本文整理汇总了Golang中github.com/karlseguin/nabu/key.Type函数的典型用法代码示例。如果您正苦于以下问题:Golang Type函数的具体用法?Golang Type怎么用?Golang Type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestEmptyLength
func TestEmptyLength(t *testing.T) {
spec := gspec.New(t)
empty := NewEmpty("x")
empty.Set(key.Type(4))
empty.Set(key.Type(6))
spec.Expect(empty.Len()).ToEqual(0)
}
示例2: TestLoadsTheMap
func TestLoadsTheMap(t *testing.T) {
spec := gspec.New(t)
m := newIdMap()
data := map[uint]string{1: "a1", 2: "b2", 10: "c3"}
m.load(data)
spec.Expect(m.get("c3", false)).ToEqual(key.Type(10))
spec.Expect(m.get("c4", true)).ToEqual(key.Type(11))
}
示例3: TestSortedStringsOrderOnRemove
func TestSortedStringsOrderOnRemove(t *testing.T) {
spec := gspec.New(t)
s := NewSortedStrings("test")
sortedSetLoad(s, 1, "banana", 2, "apples", 3, "oranges")
s.Remove(key.Type(3))
spec.Expect(s.list[1].id).ToEqual(key.Type(2))
spec.Expect(s.list[2].id).ToEqual(key.Type(1))
spec.Expect(s.Len()).ToEqual(2)
}
示例4: TestSortedStringsContains
func TestSortedStringsContains(t *testing.T) {
spec := gspec.New(t)
s := NewSortedStrings("test")
sortedSetLoad(s, 1, "banana", 2, "apples", 3, "oranges")
s.SetString(key.Type(1), "prune")
s.SetString(key.Type(4), "apes")
s.Remove(1)
spec.Expect(s.Contains(key.Type(1))).ToEqual(false)
spec.Expect(s.Contains(key.Type(3))).ToEqual(true)
}
示例5: TestSortedIntsForwardIterationMovesUpToNextClosest
func TestSortedIntsForwardIterationMovesUpToNextClosest(t *testing.T) {
for i := 0; i < 1000; i++ {
rand.Seed(int64(i))
s := NewSortedInts("test")
s.SetInt(key.Type(1), 1)
s.SetInt(key.Type(3), 3)
s.SetInt(key.Type(4), 4)
s.SetInt(key.Type(5), 5)
assertIterator(t, s.Forwards().Range(2, 4).Offset(0), 3, 4)
}
}
示例6: get
func (m *IdMap) get(s string, create bool) key.Type {
bucket := m.getBucket(s)
bucket.RLock()
id, exists := bucket.lookup[s]
bucket.RUnlock()
if exists {
return id
}
if create == false {
return key.NULL
}
bucket.Lock()
defer bucket.Unlock()
id, exists = bucket.lookup[s]
if exists {
return id
}
id = key.Type(atomic.AddUint64(&m.counter, 1))
bucket.lookup[s] = id
return id
}
示例7: TestEmptyBackwards
func TestEmptyBackwards(t *testing.T) {
spec := gspec.New(t)
empty := NewEmpty("x")
empty.Set(key.Type(4))
iter := empty.Backwards()
spec.Expect(iter.Current()).ToEqual(key.NULL)
}
示例8: TestIdMapReturnsAnExistingId
func TestIdMapReturnsAnExistingId(t *testing.T) {
spec := gspec.New(t)
m := newIdMap()
m.get("over", true)
m.get("9000", true)
spec.Expect(m.get("over", false)).ToEqual(key.Type(1))
}
示例9: TestUnionDoesNotContainANonExistantId
func TestUnionDoesNotContainANonExistantId(t *testing.T) {
spec := gspec.New(t)
union := NewUnion("x", []string{"apple", "orange"})
union.On(makeSetIndex(20, 23, 24, 25, 26))
union.On(makeSetIndex(20, 25, 28, 29))
spec.Expect(union.Contains(key.Type(22))).ToEqual(false)
}
示例10: makeSetIndex
func makeSetIndex(ids ...int) indexes.Index {
set := indexes.NewSetString("test")
for _, id := range ids {
set.Set(key.Type(id))
}
return set
}
示例11: TestSetContainsAnExistingIdIfMultipleIndexesContainsIt
func TestSetContainsAnExistingIdIfMultipleIndexesContainsIt(t *testing.T) {
spec := gspec.New(t)
union := NewUnion("x", []string{"apple", "orange"})
union.On(makeSetIndex(20, 23, 24, 25, 26))
union.On(makeSetIndex(20, 25, 28, 29))
spec.Expect(union.Contains(key.Type(20))).ToEqual(true)
}
示例12: TestGreaterThanOrEqualContainsAnIdWithAScoreEqualToOurTarget
func TestGreaterThanOrEqualContainsAnIdWithAScoreEqualToOurTarget(t *testing.T) {
spec := gspec.New(t)
gte := NewGreaterThanOrEqual("x", 10)
gte.On(makeIndex(1, 7, 8, 10, 11, 12, 13, 20))
score, exists := gte.Score(key.Type(3))
spec.Expect(score).ToEqual(10)
spec.Expect(exists).ToEqual(true)
}
示例13: TestEqualContainsAnIdWithAScoreEqualOurTarget
func TestEqualContainsAnIdWithAScoreEqualOurTarget(t *testing.T) {
spec := gspec.New(t)
eq := NewEqual("x", 10)
eq.On(makeIndex(1, 7, 8, 10, 11, 12, 13, 20))
score, exists := eq.Score(key.Type(3))
spec.Expect(score).ToEqual(10)
spec.Expect(exists).ToEqual(true)
}
示例14: TestLessThanOrEqualContainsAnIdWithAScoreLessThanOrEqualOurTarget
func TestLessThanOrEqualContainsAnIdWithAScoreLessThanOrEqualOurTarget(t *testing.T) {
spec := gspec.New(t)
lte := NewLessThanOrEqual("x", 10)
lte.On(makeIndex(1, 7, 8, 10, 11, 12, 13, 20))
score, exists := lte.Score(key.Type(2))
spec.Expect(score).ToEqual(8)
spec.Expect(exists).ToEqual(true)
}
示例15: TestEqualReturnsTheLength
func TestEqualReturnsTheLength(t *testing.T) {
spec := gspec.New(t)
eq := NewEqual("x", 10)
idx := makeIndex(1, 7, 8, 10, 11, 12, 13, 20)
idx.(indexes.WithIntScores).SetInt(key.Type(22), 10)
eq.On(idx)
spec.Expect(eq.Len()).ToEqual(2)
}