tests are green again

This commit is contained in:
Araq 2011-06-28 01:31:53 +02:00
commit 5c94a9e1ae
11 changed files with 23 additions and 558 deletions

View file

@ -11,7 +11,7 @@ proc bp(x: var TB) = x.b[high(x.b)] = -1
# in Nimrod proc (x: TB) is compatible to proc (x: TA),
# but this is not type safe:
var f: proc (x: var TA) = bp
var f = cast[proc (x: var TA)](bp)
var a: TA
f(a) # bp expects a TB, but gets a TA

View file

@ -21,7 +21,7 @@ proc drawCircle(my: var TCircle) = stdout.writeln("o " & $my.radius)
proc init(my: var TCircle) =
init(TFigure(my)) # call base constructor
my.radius = 5
my.draw = drawCircle
my.draw = cast[proc (my: var TFigure)](drawCircle)
type
TRectangle = object of TFigure
@ -33,7 +33,7 @@ proc init(my: var TRectangle) =
init(TFigure(my)) # call base constructor
my.width = 5
my.height = 10
my.draw = drawRectangle
my.draw = cast[proc (my: var TFigure)](drawRectangle)
macro `!` (n: expr): stmt =
result = newNimNode(nnkCall, n)

View file

@ -251,8 +251,6 @@ proc sort*[A](t: var TCountTable[A]) =
## first. This is destructive! You must not modify `t` afterwards!
## You can use the iterators `pairs`, `keys`, and `values` to iterate over
## `t` in the sorted order.
var w: type(t.data[0])
checkTypeInfo(addr(w), 10, GetTypeInfo(w))
# we use shellsort here; fast enough and simple
var h = 1
@ -263,18 +261,11 @@ proc sort*[A](t: var TCountTable[A]) =
h = h div 3
for i in countup(h, high(t.data)):
var j = i
checkTypeInfo(addr(w), 11, GetTypeInfo(w))
while t.data[j-h].val <= t.data[j].val:
checkTypeInfo(addr(w), 12, GetTypeInfo(w))
var xyz = t.data[j]
checkTypeInfo(addr(w), 13, GetTypeInfo(w))
t.data[j] = xyz
checkTypeInfo(addr(w), 14, GetTypeInfo(w))
t.data[j-h] = t.data[j]
#swap(t.data[j], t.data[j-h])
checkTypeInfo(addr(w), 15, GetTypeInfo(w))
t.data[j] = t.data[j-h]
t.data[j-h] = xyz
j = j-h
checkTypeInfo(addr(w), 16, GetTypeInfo(w))
if j < h: break
if h == 1: break
@ -293,43 +284,19 @@ const
"50": 344490, "60": 344491, "70": 344492,
"80": 344497}
proc fake() =
#var s: TTable[string, int]
#var otherCountTable: TCountTable[string]
#var w: type(otherCountTable.data[0])
#checkTypeInfo(addr(w), nil, GetTypeInfo(w))
proc countTableTest1 =
#fake()
var s = initTable[string, int](64)
for key, val in items(data): s[key] = val
var w: tuple[key: string, val: int] #type(otherCountTable.data[0])
checkTypeInfo(addr(w), 0, GetTypeInfo(w))
#var s = data.toTable
#var otherCountTable: TCountTable[string]
#var w: tuple[key: string, val: int] #type(otherCountTable.data[0])
checkTypeInfo(addr(w), 1, GetTypeInfo(w))
var t = initCountTable[string]()
checkTypeInfo(addr(w), 2, GetTypeInfo(w))
for k, v in items(data): t.inc(k)
checkTypeInfo(addr(w), 3, GetTypeInfo(w))
for k in t.keys: assert t[k] == 1
checkTypeInfo(addr(w), 4, GetTypeInfo(w))
t.inc("90", 3)
checkTypeInfo(addr(w), 5, GetTypeInfo(w))
t.inc("12", 2)
checkTypeInfo(addr(w), 6, GetTypeInfo(w))
t.inc("34", 1)
checkTypeInfo(addr(w), 7, GetTypeInfo(w))
assert t.largest()[0] == "90"
checkTypeInfo(addr(w), 8, GetTypeInfo(w))
t.sort()
checkTypeInfo(addr(w), 9, GetTypeInfo(w))
when false:
for k, v in t.pairs:
echo k, ": ", v
var i = 0
for k, v in t.pairs:

View file

@ -1,6 +1,6 @@
discard """
file: "twrongexc.nim"
outputsub: "Error: unhandled exception [EInvalidValue]"
outputsub: "Error: unhandled exception: [EInvalidValue]"
"""
try:
raise newException(EInvalidValue, "")

View file

@ -1,7 +1,7 @@
discard """
file: "tatomic.nim"
line: 7
errormsg: "identifier expected, but found \'atomic\'"
errormsg: "identifier expected, but found 'keyword atomic'"
"""
var
atomic: int