Skip to content

Commit

Permalink
Merge branch 'master' into feat/sign-transactions-genesis
Browse files Browse the repository at this point in the history
  • Loading branch information
Villaquiranm authored Dec 6, 2024
2 parents 169e2a3 + 9a0da98 commit 069c01b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 37 deletions.
72 changes: 35 additions & 37 deletions examples/gno.land/p/demo/btree/btree_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)})
}
Expand Down Expand Up @@ -108,25 +106,25 @@ 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)
}

}

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.")
Expand All @@ -140,23 +138,23 @@ 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)
}
}

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)
}
}

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}))
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}

Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions gnovm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ _test.stdlibs:
go run ./cmd/gno test -v ./stdlibs/...


_test.filetest:;
go test pkg/gnolang/files_test.go -test.short -run 'TestFiles$$/' $(GOTEST_FLAGS)

########################################
# Code gen
# TODO: move _dev.stringer to go:generate instructions, simplify generate
Expand Down

0 comments on commit 069c01b

Please sign in to comment.