diff --git a/examples/gno.land/p/demo/btree/btree_test.gno b/examples/gno.land/p/demo/btree/btree_test.gno index 5790161c435..a0f7c1c55ca 100644 --- a/examples/gno.land/p/demo/btree/btree_test.gno +++ b/examples/gno.land/p/demo/btree/btree_test.gno @@ -4,8 +4,6 @@ import ( "fmt" "sort" "testing" - - "gno.land/p/demo/btree" ) // Content represents a key-value pair where the Key can be either an int or string @@ -74,7 +72,7 @@ var _ Record = Content{} // Test helpers // **************************************************************************** -func genericSeeding(tree *btree.BTree, size int) *btree.BTree { +func genericSeeding(tree *BTree, size int) *BTree { for i := 0; i < size; i++ { tree.Insert(Content{Key: i, Value: fmt.Sprintf("Value_%d", i)}) } @@ -108,17 +106,17 @@ func intSlicesCompare(left, right []int) int { // **************************************************************************** func TestLen(t *testing.T) { - length := genericSeeding(btree.New(WithDegree(10)), 7).Len() + length := genericSeeding(New(WithDegree(10)), 7).Len() if length != 7 { t.Errorf("Length is incorrect. Expected 7, but got %d.", length) } - length = genericSeeding(btree.New(WithDegree(5)), 111).Len() + length = genericSeeding(New(WithDegree(5)), 111).Len() if length != 111 { t.Errorf("Length is incorrect. Expected 111, but got %d.", length) } - length = genericSeeding(btree.New(WithDegree(30)), 123).Len() + length = genericSeeding(New(WithDegree(30)), 123).Len() if length != 123 { t.Errorf("Length is incorrect. Expected 123, but got %d.", length) } @@ -126,7 +124,7 @@ func TestLen(t *testing.T) { } func TestHas(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 40) + tree := genericSeeding(New(WithDegree(10)), 40) if tree.Has(Content{Key: 7}) != true { t.Errorf("Has(7) reported false, but it should be true.") @@ -140,7 +138,7 @@ func TestHas(t *testing.T) { } func TestMin(t *testing.T) { - min := Content(genericSeeding(btree.New(WithDegree(10)), 53).Min()) + min := Content(genericSeeding(New(WithDegree(10)), 53).Min()) if min.Key != 0 { t.Errorf("Minimum should have been 0, but it was reported as %d.", min) @@ -148,7 +146,7 @@ func TestMin(t *testing.T) { } func TestMax(t *testing.T) { - max := Content(genericSeeding(btree.New(WithDegree(10)), 53).Min()) + max := Content(genericSeeding(New(WithDegree(10)), 53).Min()) if max.Key != 0 { t.Errorf("Minimum should have been 0, but it was reported as %d.", max) @@ -156,7 +154,7 @@ func TestMax(t *testing.T) { } func TestGet(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 40) + tree := genericSeeding(New(WithDegree(10)), 40) if Content(tree.Get(Content{Key: 7})).Value != "Value_7" { t.Errorf("Get(7) should have returned 'Value_7', but it returned %v.", tree.Get(Content{Key: 7})) @@ -170,12 +168,12 @@ func TestGet(t *testing.T) { } func TestDescend(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 5) + tree := genericSeeding(New(WithDegree(10)), 5) expected := []int{4, 3, 2, 1, 0} found := []int{} - tree.Descend(func(_record btree.Record) bool { + tree.Descend(func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -187,12 +185,12 @@ func TestDescend(t *testing.T) { } func TestDescendGreaterThan(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 10) + tree := genericSeeding(New(WithDegree(10)), 10) expected := []int{9, 8, 7, 6, 5} found := []int{} - tree.DescendGreaterThan(Content{Key: 4}, func(_record btree.Record) bool { + tree.DescendGreaterThan(Content{Key: 4}, func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -204,12 +202,12 @@ func TestDescendGreaterThan(t *testing.T) { } func TestDescendLessOrEqual(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 10) + tree := genericSeeding(New(WithDegree(10)), 10) expected := []int{4, 3, 2, 1, 0} found := []int{} - tree.DescendLessOrEqual(Content{Key: 4}, func(_record btree.Record) bool { + tree.DescendLessOrEqual(Content{Key: 4}, func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -221,12 +219,12 @@ func TestDescendLessOrEqual(t *testing.T) { } func TestDescendRange(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 10) + tree := genericSeeding(New(WithDegree(10)), 10) expected := []int{6, 5, 4, 3, 2} found := []int{} - tree.DescendRange(Content{Key: 6}, Content{Key: 1}, func(_record btree.Record) bool { + tree.DescendRange(Content{Key: 6}, Content{Key: 1}, func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -238,12 +236,12 @@ func TestDescendRange(t *testing.T) { } func TestAscend(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 5) + tree := genericSeeding(New(WithDegree(10)), 5) expected := []int{0, 1, 2, 3, 4} found := []int{} - tree.Ascend(func(_record btree.Record) bool { + tree.Ascend(func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -255,12 +253,12 @@ func TestAscend(t *testing.T) { } func TestAscendGreaterOrEqual(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 10) + tree := genericSeeding(New(WithDegree(10)), 10) expected := []int{5, 6, 7, 8, 9} found := []int{} - tree.AscendGreaterOrEqual(Content{Key: 5}, func(_record btree.Record) bool { + tree.AscendGreaterOrEqual(Content{Key: 5}, func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -272,12 +270,12 @@ func TestAscendGreaterOrEqual(t *testing.T) { } func TestAscendLessThan(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 10) + tree := genericSeeding(New(WithDegree(10)), 10) expected := []int{0, 1, 2, 3, 4} found := []int{} - tree.AscendLessThan(Content{Key: 5}, func(_record btree.Record) bool { + tree.AscendLessThan(Content{Key: 5}, func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -289,12 +287,12 @@ func TestAscendLessThan(t *testing.T) { } func TestAscendRange(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(10)), 10) + tree := genericSeeding(New(WithDegree(10)), 10) expected := []int{2, 3, 4, 5, 6} found := []int{} - tree.AscendRange(Content{Key: 2}, Content{Key: 7}, func(_record btree.Record) bool { + tree.AscendRange(Content{Key: 2}, Content{Key: 7}, func(_record Record) bool { record := Content(_record) found = append(found, int(record.Key)) return true @@ -306,7 +304,7 @@ func TestAscendRange(t *testing.T) { } func TestDeleteMin(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(3)), 100) + tree := genericSeeding(New(WithDegree(3)), 100) expected := []int{0, 1, 2, 3, 4} found := []int{} @@ -323,7 +321,7 @@ func TestDeleteMin(t *testing.T) { } func TestShift(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(3)), 100) + tree := genericSeeding(New(WithDegree(3)), 100) expected := []int{0, 1, 2, 3, 4} found := []int{} @@ -340,7 +338,7 @@ func TestShift(t *testing.T) { } func TestDeleteMax(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(3)), 100) + tree := genericSeeding(New(WithDegree(3)), 100) expected := []int{99, 98, 97, 96, 95} found := []int{} @@ -357,7 +355,7 @@ func TestDeleteMax(t *testing.T) { } func TestPop(t *testing.T) { - tree := genericSeeding(btree.New(WithDegree(3)), 100) + tree := genericSeeding(New(WithDegree(3)), 100) expected := []int{99, 98, 97, 96, 95} found := []int{} @@ -374,7 +372,7 @@ func TestPop(t *testing.T) { } func TestInsertGet(t *testing.T) { - tree := btree.New(WithDegree(4)) + tree := New(WithDegree(4)) expected := []Content{} @@ -398,7 +396,7 @@ func TestClone(t *testing.T) { func TestBTree(t *testing.T) { // Create a B-Tree of degree 3 - tree := btree.New(WithDegree(3)) + tree := New(WithDegree(3)) //insertData := []Content{} var insertData ContentSlice @@ -475,7 +473,7 @@ func TestBTree(t *testing.T) { t.Logf("Sorted Data Length: %d", len(sortedInsertData)) t.Logf("Tree Length: %d", tree.Len()) - tree.Ascend(func(_record btree.Record) bool { + tree.Ascend(func(_record Record) bool { record := Content(_record) t.Logf("Key:Value == %v:%v", record.Key, record.Value) if record.Key != sortedInsertData[pos].Key { @@ -488,7 +486,7 @@ func TestBTree(t *testing.T) { t.Logf("\nReverse-order Iteration:\n") pos = len(sortedInsertData) - 1 - tree.Descend(func(_record btree.Record) bool { + tree.Descend(func(_record Record) bool { record := Content(_record) t.Logf("Key:Value == %v:%v", record.Key, record.Value) if record.Key != sortedInsertData[pos].Key { @@ -530,7 +528,7 @@ func TestStress(t *testing.T) { for degree := 3; degree <= 12; degree += 3 { t.Logf("Testing B-Tree of degree %d\n", degree) - tree := btree.New(WithDegree(degree)) + tree := New(WithDegree(degree)) // Insert 1000 records t.Logf("Inserting 1000 records\n") @@ -576,7 +574,7 @@ func TestStress(t *testing.T) { // Print a few lines using Logf to let the user know what's happening. t.Logf("Testing B-Tree of degree 10 with 100000 records\n") - tree := btree.New(WithDegree(10)) + tree := New(WithDegree(10)) // Insert 100000 records t.Logf("Inserting 100000 records\n") @@ -607,7 +605,7 @@ func TestStress(t *testing.T) { func TestBTreeCloneIsolation(t *testing.T) { t.Logf("Creating B-Tree of degree 10 with 10000 records\n") - tree := genericSeeding(btree.New(WithDegree(10)), 10000) + tree := genericSeeding(New(WithDegree(10)), 10000) // Clone the tree t.Logf("Cloning the tree\n")