コード例 #1
0
func TestIntKeyOMapDelete(t *testing.T) {
	intMap := omap.NewIntKeyed()
	for _, number := range []int{9, 1, 8, 2, 7, 3, 6, 4, 5, 0} {
		intMap.Insert(number, number*10)
	}
	if intMap.Len() != 10 {
		t.Errorf("map len %d should be 10", intMap.Len())
	}
	length := 9
	for i, number := range []int{0, 1, 5, 8, 9} {
		if deleted := intMap.Delete(number); !deleted {
			t.Errorf("failed to delete %d", number)
		}
		if intMap.Len() != length-i {
			t.Errorf("map len %d should be %d", intMap.Len(), length-i)
		}
	}
	for _, number := range []int{-1, -21, 10, 11, 148} {
		if deleted := intMap.Delete(number); deleted {
			t.Errorf("should not have deleted nonexistent %d", number)
		}
	}
	if intMap.Len() != 5 {
		t.Errorf("map len %d should be 5", intMap.Len())
	}
}
コード例 #2
0
func BenchmarkOMapFindFailure(b *testing.B) {
	b.StopTimer() // Don't time creation and population
	intMap := omap.NewIntKeyed()
	for i := 0; i < 1e6; i++ {
		intMap.Insert(2*i, i)
	}
	b.StartTimer() // Time the Find() method failing
	for i := 0; i < b.N; i++ {
		intMap.Find(2*(i%1e6) + 1)
	}
}
コード例 #3
0
// Thanks to Russ Cox for improving these benchmarks
func BenchmarkOMapFindSuccess(b *testing.B) {
	b.StopTimer() // Don't time creation and population
	intMap := omap.NewIntKeyed()
	for i := 0; i < 1e6; i++ {
		intMap.Insert(i, i)
	}
	b.StartTimer() // Time the Find() method succeeding
	for i := 0; i < b.N; i++ {
		intMap.Find(i % 1e6)
	}
}
コード例 #4
0
func TestIntKeyOMapFind(t *testing.T) {
	intMap := omap.NewIntKeyed()
	for _, number := range []int{9, 1, 8, 2, 7, 3, 6, 4, 5, 0} {
		intMap.Insert(number, number*10)
	}
	for _, number := range []int{0, 1, 5, 8, 9} {
		value, found := intMap.Find(number)
		if !found {
			t.Errorf("failed to find %d", number)
		}
		actual, expected := value.(int), number*10
		if actual != expected {
			t.Errorf("value is %d should be %d", actual, expected)
		}
	}
	for _, number := range []int{-1, -21, 10, 11, 148} {
		_, found := intMap.Find(number)
		if found {
			t.Errorf("should not have found %d", number)
		}
	}
}
コード例 #5
0
func TestPassing(t *testing.T) {
	intMap := omap.NewIntKeyed()
	intMap.Insert(7, 7)
	passMap(intMap, t)
}