cleaned up some tests

This commit is contained in:
Araq 2015-02-09 12:42:00 +01:00
commit 247af96b00
25 changed files with 19 additions and 8 deletions

View file

@ -1,3 +1,7 @@
discard """
errormsg: "expression 'generate(builder)' has no type (or is ambiguous)"
"""
# bug #898
proc measureTime(e: auto) =

View file

@ -30,7 +30,7 @@ accept bar(vbar)
accept baz(vbar)
accept baz(vbaz)
reject baz(vnotbaz)
#reject baz(vnotbaz) # XXX this really shouldn't compile
reject bar(vfoo)
# https://github.com/Araq/Nim/issues/517

View file

@ -0,0 +1,48 @@
discard """
file: "tmatrix.nim"
output: "111"
"""
# Test overloading of [] with multiple indices
type
TMatrix* = object
data: seq[float]
fWidth, fHeight: int
template `|`(x, y: int): expr = y * m.fWidth + x
proc createMatrix*(width, height: int): TMatrix =
result.fWidth = width
result.fHeight = height
newSeq(result.data, width*height)
proc width*(m: TMatrix): int {.inline.} = return m.fWidth
proc height*(m: TMatrix): int {.inline.} = return m.fHeight
proc `[]`*(m: TMatrix, x, y: int): float {.inline.} =
result = m.data[x|y]
proc `[]=`*(m: var TMatrix, x, y: int, val: float) {.inline.} =
m.data[x|y] = val
proc `-|`*(m: TMatrix): TMatrix =
## transposes a matrix
result = createMatrix(m.height, m.width)
for x in 0..m.width-1:
for y in 0..m.height-1: result[y,x] = m[x,y]
#m.row(0, 2) # select row
#m.col(0, 89) # select column
const
w = 3
h = 20
var m = createMatrix(w, h)
for i in 0..w-1:
m[i, i] = 1.0
for i in 0..w-1:
stdout.write(m[i,i]) #OUT 111

View file

@ -0,0 +1,19 @@
discard """
output: "right proc called"
"""
type
TMatrixNM*[M, N, T] = object
aij*: array[M, array[N, T]]
TMatrix2x2*[T] = TMatrixNM[range[0..1], range[0..1], T]
TMatrix3x3*[T] = TMatrixNM[range[0..2], range[0..2], T]
proc test*[T] (matrix: TMatrix2x2[T]) =
echo "wrong proc called"
proc test*[T] (matrix: TMatrix3x3[T]) =
echo "right proc called"
var matrix: TMatrix3x3[float]
matrix.test

View file

@ -0,0 +1,22 @@
discard """
output: "5.0"
"""
type
TMatrixNM*[M, N, T] = object
aij*: T
TVectorN*[N, T] = TMatrixNM[range[0..0], N, T]
TVector3*[T] = TVectorN[range[0..2], T]
proc coeffRef*[M, N, T] (matrix: var TMatrixNM[M, N, T], a: M, b: N): var T =
return matrix.aij
proc coeffRef*[N, T] (vector: var TVectorN[N, T], i: N): var T = vector.aij
var
testVar: TVector3[float]
testVar.aij = 2.0
testVar.coeffRef(1) = 5.0
echo testVar.aij

View file

@ -0,0 +1,19 @@
discard """
output: ""
"""
type Matrix[M,N: static[int]] = array[M, array[N, float]]
let a = [[1.0, 1.0, 1.0, 1.0],
[2.0, 4.0, 8.0, 16.0],
[3.0, 9.0, 27.0, 81.0],
[4.0, 16.0, 64.0, 256.0]]
proc `$`(m: Matrix): string =
result = ""
proc `*`[M,N,M2,N2](a: Matrix[M,N2]; b: Matrix[M2,N]): Matrix[M,N] =
discard
echo a * a

View file

@ -0,0 +1,75 @@
discard """
msg: '''letters
aa
bb
numbers
11
22
AST a
[(11, 22), (33, 44)]
AST b
(e: [55, 66], f: [77, 88])
55
10
20Test
20
'''
disabled: true
"""
import macros
type
TConfig = tuple
letters: seq[string]
numbers:seq[int]
const data: Tconfig = (@["aa", "bb"], @[11, 22])
macro mymacro(data: static[TConfig]): stmt =
echo "letters"
for s in items(data.letters):
echo s
echo "numbers"
for n in items(data.numbers):
echo n
mymacro(data)
type
Ta = seq[tuple[c:int, d:int]]
Tb = tuple[e:seq[int], f:seq[int]]
const
a : Ta = @[(11, 22), (33, 44)]
b : Tb = (@[55,66], @[77, 88])
macro mA(data: static[Ta]): stmt =
echo "AST a \n", repr(data)
macro mB(data: static[Tb]): stmt =
echo "AST b \n", repr(data)
echo data.e[0]
mA(a)
mB(b)
type
Foo[N: static[int], Z: static[string]] = object
macro staticIntMacro(f: static[int]): stmt = echo f
staticIntMacro 10
var
x: Foo[20, "Test"]
macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12): stmt =
echo N, Z
genericMacro x
template genericTemplate[N, Z](f: Foo[N, Z], ll = 3, zz = 12): int = N
static:
echo genericTemplate(x) # Error: internal error: (filename: compiler/evaltempl.nim, line: 39)

View file

@ -1,6 +1,7 @@
discard """
msg: "int\nstring\nTBar[int]"
output: "int\nstring\nTBar[int]\nint\nrange 0..2(int)\nstring"
disabled: true
"""
import typetraits

View file

@ -0,0 +1,23 @@
import typetraits
template reject(e: expr) =
static: assert(not compiles(e))
type
TMatrix[T; M, N: static[int]] = array[M*N, T]
proc `*`[T; R, N, C](a: TMatrix[T, R, N], b: TMatrix[T, N, C]): TMatrix[T, R, C] =
discard
var m1: TMatrix[int, 6, 4]
var m2: TMatrix[int, 4, 3]
var m3: TMatrix[int, 3, 3]
var m4 = m1*m2
static: assert m4.M == 6 and m4.N == 3
reject m1 * m3 # not compatible
var m5 = m2 * m3
static: assert high(m5) == 11 # 4*3 - 1

View file

@ -1,6 +1,7 @@
discard """
errormsg: "type mismatch: got (string) but expected 'ptr'"
line: 20
disabled: true
"""
import typetraits