new tester; all tests categorized

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

48
tests/matrix/tmatrix.nim Normal file
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

19
tests/matrix/tmatrix1.nim Normal file
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

22
tests/matrix/tmatrix2.nim Normal file
View file

@ -0,0 +1,22 @@
discard """
output: "5.0000000000000000e+00"
"""
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