mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
62 lines
1.0 KiB
Go
62 lines
1.0 KiB
Go
package test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzoai/commerce/util/bit"
|
|
|
|
. "github.com/hanzoai/commerce/util/test/ginkgo"
|
|
)
|
|
|
|
func Test(t *testing.T) {
|
|
Setup("util/bit", t)
|
|
}
|
|
|
|
const (
|
|
A bit.Mask = 1 << iota
|
|
B
|
|
C
|
|
)
|
|
|
|
var _ = Describe("Field", func() {
|
|
It("Should be able to set Mask", func() {
|
|
field := new(bit.Field)
|
|
|
|
field.Set(A)
|
|
field.Set(B)
|
|
|
|
Expect(field.Has(A)).To(Equal(true))
|
|
Expect(field.Has(B)).To(Equal(true))
|
|
Expect(field.Has(C)).To(Equal(false))
|
|
})
|
|
|
|
It("Should be able to remove Mask", func() {
|
|
field := new(bit.Field)
|
|
|
|
field.Set(A)
|
|
field.Set(B)
|
|
field.Set(C)
|
|
|
|
field.Del(B)
|
|
|
|
Expect(field.Has(A)).To(Equal(true))
|
|
Expect(field.Has(B)).To(Equal(false))
|
|
Expect(field.Has(C)).To(Equal(true))
|
|
})
|
|
|
|
It("should perform operations efficiently", func() {
|
|
start := time.Now()
|
|
field := new(bit.Field)
|
|
|
|
for n := 0; n < 100000; n++ {
|
|
field.Set(A)
|
|
field.Set(B)
|
|
field.Set(C)
|
|
}
|
|
|
|
elapsed := time.Since(start)
|
|
Expect(elapsed.Seconds()).To(BeNumerically("<", 0.1))
|
|
})
|
|
})
|