Skip to content

Commit 972e5de

Browse files
Fixed contains function, wrote a test.
1 parent 6df8597 commit 972e5de

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/safeset.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type
1010
pendingClear: bool
1111

1212
proc newSafeSet*[T](): SafeSet[T] =
13-
SafeSet[T]()
13+
SafeSet[T](elements: initOrderedSet[T]())
1414

1515
proc areElementsLocked*[T](this: SafeSet[T]): bool =
1616
this.iterationDepth > 0

tests/safeset_test.nim

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
import
22
nimtest,
33
safeset,
4-
sequtils
4+
sequtils,
5+
hashes,
6+
sets
7+
8+
var i: int = 0
9+
10+
type Foo = object
11+
id: int
12+
children: SafeSet[Foo]
13+
14+
proc newFoo(): Foo =
15+
result = Foo(id: i, children: newSafeSet[Foo]())
16+
inc i
17+
18+
proc hash*(f: Foo): Hash =
19+
hash(f.id)
520

621
describe "SafeSet":
722

@@ -79,3 +94,15 @@ describe "SafeSet":
7994
@["foobar", "aoeu", "something", "htns"]
8095
)
8196

97+
describe "contains":
98+
99+
it "reports when a safeset contains an element properly":
100+
let
101+
parent = newFoo()
102+
child = newFoo()
103+
104+
assertEquals(parent.children.contains(child), false)
105+
106+
parent.children.add(child)
107+
assertEquals(parent.children.contains(child), true)
108+

0 commit comments

Comments
 (0)