new tester; all tests categorized

This commit is contained in:
Araq
2014-01-13 02:10:03 +01:00
parent 51ee524109
commit 20b5f31c03
481 changed files with 794 additions and 2506 deletions

33
tests/array/tarray.nim Normal file
View File

@@ -0,0 +1,33 @@
discard """
file: "tarray.nim"
output: "10012"
"""
# simple check for one dimensional arrays
type
TMyArray = array[0..2, int]
TMyRecord = tuple[x, y: int]
proc sum(a: TMyarray): int =
result = 0
var i = 0
while i < len(a):
inc(result, a[i])
inc(i)
proc sum(a: openarray[int]): int =
result = 0
var i = 0
while i < len(a):
inc(result, a[i])
inc(i)
proc getPos(r: TMyRecord): int =
result = r.x + r.y
write(stdout, sum([1, 2, 3, 4]))
write(stdout, sum([]))
write(stdout, getPos( (x: 5, y: 7) ))
#OUT 10012

36
tests/array/tarray2.nim Normal file
View File

@@ -0,0 +1,36 @@
discard """
file: "tarray2.nim"
output: "[4, 5, 6]\n\n[16, 25, 36]\n\n[16, 25, 36]"
"""
# simple check for one dimensional arrays
type
TMyArray = array[0..2, int]
TObj = object
arr: TMyarray
proc mul(a, b: TMyarray): TMyArray =
result = a
for i in 0..len(a)-1:
result[i] = a[i] * b[i]
var
x, y: TMyArray
o: TObj
proc varArr1(x: var TMyArray): var TMyArray = x
proc varArr2(x: var TObj): var TMyArray = x.arr
x = [ 4, 5, 6 ]
echo repr(varArr1(x))
y = x
echo repr(mul(x, y))
o.arr = mul(x, y)
echo repr(varArr2(o))
#OUT [16, 25, 36]

13
tests/array/tarray3.nim Normal file
View File

@@ -0,0 +1,13 @@
discard """
file: "tarray3.nim"
output: "3"
"""
# simple check for two dimensional arrays
const
myData = [[1,2,3], [4, 5, 6]]
echo myData[0][2] #OUT 3

View File

@@ -0,0 +1,24 @@
discard """
file: "tarraycons.nim"
line: 14
errormsg: "invalid order in array constructor"
"""
type
TEnum = enum
eA, eB, eC, eD, eE, eF
const
myMapping: array[TEnum, array[0..1, int]] = [
eA: [1, 2],
eC: [3, 4],
eB: [5, 6],
eD: [0: 8, 1: 9],
eE: [0: 8, 9],
eF: [2, 1: 9]
]
echo myMapping[eC][1]

View File

@@ -0,0 +1,23 @@
discard """
file: "tarraycons.nim"
output: "6"
"""
type
TEnum = enum
eA, eB, eC, eD, eE, eF
const
myMapping: array[TEnum, array[0..1, int]] = [
eA: [1, 2],
eB: [3, 4],
[5, 6],
eD: [0: 8, 1: 9],
eE: [0: 8, 9],
eF: [2, 1: 9]
]
echo myMapping[eC][1]

View File

@@ -0,0 +1,13 @@
discard """
msg: "type mismatch: got (array[0..2, float], array[0..1, float])"
"""
proc `+`*[R, T] (v1, v2: array[R, T]): array[R, T] =
for i in low(v1)..high(v1):
result[i] = v1[i] + v2[i]
var
v1: array[0..2, float] = [3.0, 1.2, 3.0]
v2: array[0..1, float] = [2.0, 1.0]
v3 = v1 + v2

13
tests/array/tarrindx.nim Normal file
View File

@@ -0,0 +1,13 @@
# test another strange bug ... (I hate this compiler; it is much too buggy!)
proc putEnv(key, val: string) =
# XXX: we have to leak memory here, as we cannot
# free it before the program ends (says Borland's
# documentation)
var
env: ptr array[0..500000, char]
env = cast[ptr array[0..500000, char]](alloc(len(key) + len(val) + 2))
for i in 0..len(key)-1: env[i] = key[i]
env[len(key)] = '='
for i in 0..len(val)-1:
env[len(key)+1+i] = val[i]