switched over from assert to doAssert for guide
This commit is contained in:
parent
d4dd332c8d
commit
8618530413
1 changed files with 7 additions and 16 deletions
|
|
@ -33,28 +33,19 @@ If you change the stdlib (anything under `lib/`), put a test in the
|
||||||
file you changed. Add the tests under an `when isMainModule:`
|
file you changed. Add the tests under an `when isMainModule:`
|
||||||
condition so they only get executed when the tester is building the
|
condition so they only get executed when the tester is building the
|
||||||
file. Each test should be in a separate `block:` statement, such that
|
file. Each test should be in a separate `block:` statement, such that
|
||||||
each has its own scope. Use boolean conditions and `assert` for the
|
each has its own scope. Use boolean conditions and `doAssert` for the
|
||||||
testing by itself, don't rely on echo statements or similar.
|
testing by itself, don't rely on echo statements or similar.
|
||||||
|
|
||||||
Sample test:
|
Sample test:
|
||||||
|
|
||||||
```nim
|
```nim
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
block lenTest:
|
block: # newSeqWith tests
|
||||||
var values: HashSet[int]
|
var seq2D = newSeqWith(4, newSeq[bool](2))
|
||||||
assert(not values.isValid)
|
seq2D[0][0] = true
|
||||||
assert values.len == 0
|
seq2D[1][0] = true
|
||||||
assert values.card == 0
|
seq2D[0][1] = true
|
||||||
block setIterator:
|
doAssert seq2D == @[@[true, true], @[true, false], @[false, false], @[false, false]]
|
||||||
type pair = tuple[a, b: int]
|
|
||||||
var a, b = initSet[pair]()
|
|
||||||
a.incl((2, 3))
|
|
||||||
a.incl((3, 2))
|
|
||||||
a.incl((2, 3))
|
|
||||||
for x, y in a.items:
|
|
||||||
b.incl((x - 2, y + 1))
|
|
||||||
assert a.len == b.card
|
|
||||||
assert a.len == 2
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Compiler
|
## Compiler
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue