new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
64
tests/sets/tsets.nim
Normal file
64
tests/sets/tsets.nim
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
discard """
|
||||
file: "tsets.nim"
|
||||
output: "Ha ein F ist in s!"
|
||||
"""
|
||||
# Test the handling of sets
|
||||
|
||||
import
|
||||
strutils
|
||||
|
||||
proc testSets(s: var set[char]) =
|
||||
s = {'A', 'B', 'C', 'E'..'G'} + {'Z'} + s
|
||||
|
||||
# test sets if the first element is different from 0:
|
||||
type
|
||||
TAZ = range['a'..'z']
|
||||
TAZset = set[TAZ]
|
||||
|
||||
TTokType* = enum
|
||||
tkInvalid, tkEof,
|
||||
tkSymbol,
|
||||
tkAddr, tkAnd, tkAs, tkAsm, tkBlock, tkBreak, tkCase, tkCast, tkConst,
|
||||
tkContinue, tkConverter, tkDiscard, tkDiv, tkElif, tkElse, tkEnd, tkEnum,
|
||||
tkExcept, tkException, tkFinally, tkFor, tkFrom, tkGeneric, tkIf, tkImplies,
|
||||
tkImport, tkIn, tkInclude, tkIs, tkIsnot, tkIterator, tkLambda, tkMacro,
|
||||
tkMethod, tkMod, tkNil, tkNot, tkNotin, tkObject, tkOf, tkOr, tkOut, tkProc,
|
||||
tkPtr, tkRaise, tkRecord, tkRef, tkReturn, tkShl, tkShr, tkTemplate, tkTry,
|
||||
tkType, tkVar, tkWhen, tkWhere, tkWhile, tkWith, tkWithout, tkXor, tkYield,
|
||||
tkIntLit, tkInt8Lit, tkInt16Lit, tkInt32Lit, tkInt64Lit, tkFloatLit,
|
||||
tkFloat32Lit, tkFloat64Lit, tkStrLit, tkRStrLit, tkTripleStrLit, tkCharLit,
|
||||
tkRCharLit, tkParLe, tkParRi, tkBracketLe, tkBracketRi, tkCurlyLe,
|
||||
tkCurlyRi, tkBracketDotLe, tkBracketDotRi,
|
||||
tkCurlyDotLe, tkCurlyDotRi,
|
||||
tkParDotLe, tkParDotRi,
|
||||
tkComma, tkSemiColon, tkColon, tkEquals, tkDot, tkDotDot, tkHat, tkOpr,
|
||||
tkComment, tkAccent, tkInd, tkSad, tkDed,
|
||||
tkSpaces, tkInfixOpr, tkPrefixOpr, tkPostfixOpr
|
||||
TTokTypeRange = range[tkSymbol..tkDed]
|
||||
TTokTypes* = set[TTokTypeRange]
|
||||
|
||||
const
|
||||
toktypes: TTokTypes = {TTokTypeRange(tkSymbol)..pred(tkIntLit),
|
||||
tkStrLit..tkTripleStrLit}
|
||||
|
||||
var
|
||||
s: set[char]
|
||||
a: TAZset
|
||||
s = {'0'..'9'}
|
||||
testSets(s)
|
||||
if 'F' in s: write(stdout, "Ha ein F ist in s!\n")
|
||||
else: write(stdout, "BUG: F ist nicht in s!\n")
|
||||
a = {} #{'a'..'z'}
|
||||
for x in low(TAZ) .. high(TAZ):
|
||||
incl(a, x)
|
||||
if x in a: nil
|
||||
else: write(stdout, "BUG: something not in a!\n")
|
||||
|
||||
for x in low(TTokTypeRange) .. high(TTokTypeRange):
|
||||
if x in tokTypes:
|
||||
nil
|
||||
#writeln(stdout, "the token '$1' is in the set" % repr(x))
|
||||
|
||||
#OUT Ha ein F ist in s!
|
||||
|
||||
|
||||
62
tests/sets/tsets2.nim
Normal file
62
tests/sets/tsets2.nim
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
discard """
|
||||
output: '''true'''
|
||||
cmd: "nimrod cc --hints:on $# $#"
|
||||
"""
|
||||
|
||||
import hashes, sets
|
||||
|
||||
const
|
||||
data = [
|
||||
"34", "12",
|
||||
"90", "0",
|
||||
"1", "2",
|
||||
"3", "4",
|
||||
"5", "6",
|
||||
"7", "8",
|
||||
"9", "---00",
|
||||
"10", "11", "19",
|
||||
"20", "30", "40",
|
||||
"50", "60", "70",
|
||||
"80"]
|
||||
|
||||
block tableTest1:
|
||||
var t = initSet[tuple[x, y: int]]()
|
||||
t.incl((0,0))
|
||||
t.incl((1,0))
|
||||
assert(not t.containsOrIncl((0,1)))
|
||||
t.incl((1,1))
|
||||
|
||||
for x in 0..1:
|
||||
for y in 0..1:
|
||||
assert((x,y) in t)
|
||||
#assert($t ==
|
||||
# "{(x: 0, y: 0), (x: 0, y: 1), (x: 1, y: 0), (x: 1, y: 1)}")
|
||||
|
||||
block setTest2:
|
||||
var t = initSet[string]()
|
||||
t.incl("test")
|
||||
t.incl("111")
|
||||
t.incl("123")
|
||||
t.excl("111")
|
||||
|
||||
t.incl("012")
|
||||
t.incl("123") # test duplicates
|
||||
|
||||
assert "123" in t
|
||||
assert "111" notin t # deleted
|
||||
|
||||
for key in items(data): t.incl(key)
|
||||
for key in items(data): assert key in t
|
||||
|
||||
|
||||
block orderedSetTest1:
|
||||
var t = data.toOrderedSet
|
||||
for key in items(data): assert key in t
|
||||
var i = 0
|
||||
# `items` needs to yield in insertion order:
|
||||
for key in items(t):
|
||||
assert key == data[i]
|
||||
inc(i)
|
||||
|
||||
echo "true"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue