aboutsummaryrefslogtreecommitdiff
path: root/immutable_test.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2023-01-02 10:49:14 -0700
committerGitHub <noreply@github.com>2023-01-02 10:49:14 -0700
commit4dd1fd8b0a5501553e35fc21ecde1a6b1863c2ca (patch)
tree11208329fc4edf7c9b7167a1e7148b9e4ca69864 /immutable_test.go
parentMerge pull request #34 from laher/sets (diff)
parentset/sorted-set: Items() to return slice of items (diff)
downloadpds-4dd1fd8b0a5501553e35fc21ecde1a6b1863c2ca.tar.gz
pds-4dd1fd8b0a5501553e35fc21ecde1a6b1863c2ca.tar.xz
Merge pull request #35 from laher/sets-maps-append-multi
Sets & maps append-multi. Also docs and a fix for SortedSets
Diffstat (limited to 'immutable_test.go')
-rw-r--r--immutable_test.go32
1 files changed, 30 insertions, 2 deletions
diff --git a/immutable_test.go b/immutable_test.go
index 6a0ee22..a878a78 100644
--- a/immutable_test.go
+++ b/immutable_test.go
@@ -200,8 +200,10 @@ func TestList(t *testing.T) {
t.Fatal("Failed to find leaf node due to nil child")
}
return findLeaf(n.children[0])
- case *listLeafNode[*int]: return n
- default: panic("Unexpected case")
+ case *listLeafNode[*int]:
+ return n
+ default:
+ panic("Unexpected case")
}
}
@@ -959,6 +961,22 @@ func TestMap_Set(t *testing.T) {
}
})
+ t.Run("Multi", func(t *testing.T) {
+ m := NewMapOf(nil, map[int]string{1: "foo"})
+ itr := m.Iterator()
+ if itr.Done() {
+ t.Fatal("MapIterator.Done()=false, expected true")
+ }
+ if k, v, ok := itr.Next(); !ok {
+ t.Fatalf("MapIterator.Next()!=ok, expected ok")
+ } else if k != 1 || v != "foo" {
+ t.Fatalf("MapIterator.Next()=<%v,%v>, expected <1, \"foo\">", k, v)
+ }
+ if k, v, ok := itr.Next(); ok {
+ t.Fatalf("MapIterator.Next()=<%v,%v>, expected nil", k, v)
+ }
+ })
+
t.Run("VerySmall", func(t *testing.T) {
const n = 6
m := NewMap[int, int](nil)
@@ -1070,6 +1088,16 @@ func TestMap_Overwrite(t *testing.T) {
t.Fatalf("Get(%d)=<%v,%v>", i, v, ok)
}
}
+
+ t.Run("Simple", func(t *testing.T) {
+ m := NewMap[int, string](nil)
+ itr := m.Iterator()
+ if !itr.Done() {
+ t.Fatal("MapIterator.Done()=true, expected false")
+ } else if k, v, ok := itr.Next(); ok {
+ t.Fatalf("MapIterator.Next()=<%v,%v>, expected nil", k, v)
+ }
+ })
}
func TestMap_Delete(t *testing.T) {