Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(examples): add p/moul/collection #3321

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions examples/gno.land/p/demo/avl/list/list_test.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package list

import (
"fmt"
"testing"
)

Expand Down Expand Up @@ -395,6 +396,68 @@ func TestList_IndexConsistency(t *testing.T) {
}
}

func TestList_RecursiveSafety(t *testing.T) {
// Create a new list
l := &List{}

// Add some initial values
l.Append("id1")
l.Append("id2")
l.Append("id3")

// Test deep list traversal
found := false
l.ForEach(func(i int, v interface{}) bool {
if str, ok := v.(string); ok {
if str == "id2" {
found = true
return true // stop iteration
}
}
return false // continue iteration
})

if !found {
t.Error("Failed to find expected value in list")
}

short := testing.Short()

// Test recursive safety by performing multiple operations
for i := 0; i < 1000; i++ {
// Add new value
l.Append(fmt.Sprintf("id%d", i+4))

if !short {
// Search for a value
var lastFound bool
l.ForEach(func(j int, v interface{}) bool {
if str, ok := v.(string); ok {
if str == fmt.Sprintf("id%d", i+3) {
lastFound = true
return true
}
}
return false
})

if !lastFound {
t.Errorf("Failed to find value id%d after insertion", i+3)
}
}
}

// Verify final length
expectedLen := 1003 // 3 initial + 1000 added
if l.Len() != expectedLen {
t.Errorf("Expected length %d, got %d", expectedLen, l.Len())
}

if short {
t.Skip("skipping extended recursive safety test in short mode")
}
}

// Helper function to compare slices
func sliceEqual(a, b []interface{}) bool {
if len(a) != len(b) {
Expand Down
Loading
Loading