new tester; all tests categorized
This commit is contained in:
parent
51ee524109
commit
20b5f31c03
481 changed files with 794 additions and 2506 deletions
6
tests/range/compilehelpers.nim
Normal file
6
tests/range/compilehelpers.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
template accept(e: expr) =
|
||||
static: assert(compiles(e))
|
||||
|
||||
template reject(e: expr) =
|
||||
static: assert(not compiles(e))
|
||||
|
||||
14
tests/range/tbug499771.nim
Normal file
14
tests/range/tbug499771.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
discard """
|
||||
file: "tbug499771.nim"
|
||||
output: '''TSubRange: 5 from 1 to 10
|
||||
true true true'''
|
||||
"""
|
||||
type
|
||||
TSubRange = range[1 .. 10]
|
||||
TEnum = enum A, B, C
|
||||
var sr: TSubRange = 5
|
||||
echo("TSubRange: " & $sr & " from " & $low(TSubRange) & " to " &
|
||||
$high(TSubRange))
|
||||
|
||||
const cset = {A} + {B}
|
||||
echo A in cset, " ", B in cset, " ", C notin cset
|
||||
39
tests/range/tcolors.nim
Normal file
39
tests/range/tcolors.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import strutils
|
||||
|
||||
type
|
||||
TColor = distinct int32
|
||||
|
||||
proc rgb(r, g, b: range[0..255]): TColor =
|
||||
result = TColor(r or g shl 8 or b shl 16)
|
||||
|
||||
proc `$`(c: TColor): string =
|
||||
result = "#" & toHex(int32(c), 6)
|
||||
|
||||
echo rgb(34, 55, 255)
|
||||
|
||||
when false:
|
||||
type
|
||||
TColor = distinct int32
|
||||
TColorComponent = distinct int8
|
||||
|
||||
proc red(a: TColor): TColorComponent =
|
||||
result = TColorComponent(int32(a) and 0xff'i32)
|
||||
|
||||
proc green(a: TColor): TColorComponent =
|
||||
result = TColorComponent(int32(a) shr 8'i32 and 0xff'i32)
|
||||
|
||||
proc blue(a: TColor): TColorComponent =
|
||||
result = TColorComponent(int32(a) shr 16'i32 and 0xff'i32)
|
||||
|
||||
proc rgb(r, g, b: range[0..255]): TColor =
|
||||
result = TColor(r or g shl 8 or b shl 8)
|
||||
|
||||
proc `+!` (a, b: TColorComponent): TColorComponent =
|
||||
## saturated arithmetic:
|
||||
result = TColorComponent(min(ze(int8(a)) + ze(int8(b)), 255))
|
||||
|
||||
proc `+` (a, b: TColor): TColor =
|
||||
## saturated arithmetic for colors makes sense, I think:
|
||||
return rgb(red(a) +! red(b), green(a) +! green(b), blue(a) +! blue(b))
|
||||
|
||||
rgb(34, 55, 255)
|
||||
41
tests/range/tmatrix3.nim
Normal file
41
tests/range/tmatrix3.nim
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
discard """
|
||||
output: '''0.0000000000000000e+00
|
||||
0.0000000000000000e+00
|
||||
0
|
||||
0
|
||||
0
|
||||
'''
|
||||
"""
|
||||
|
||||
include compilehelpers
|
||||
|
||||
type
|
||||
Matrix*[M, N, T] = object
|
||||
aij*: array[M, array[N, T]]
|
||||
|
||||
Matrix2*[T] = Matrix[range[0..1], range[0..1], T]
|
||||
|
||||
Matrix3*[T] = Matrix[range[0..2], range[0..2], T]
|
||||
|
||||
proc mn(x: Matrix): Matrix.T = x.aij[0][0]
|
||||
|
||||
proc m2(x: Matrix2): Matrix2.T = x.aij[0][0]
|
||||
|
||||
proc m3(x: Matrix3): auto = x.aij[0][0]
|
||||
|
||||
var
|
||||
matn: Matrix[range[0..3], range[0..2], int]
|
||||
mat2: Matrix2[int]
|
||||
mat3: Matrix3[float]
|
||||
|
||||
echo m3(mat3)
|
||||
echo mn(mat3)
|
||||
echo m2(mat2)
|
||||
echo mn(mat2)
|
||||
echo mn(matn)
|
||||
|
||||
reject m3(mat2)
|
||||
reject m3(matn)
|
||||
reject m2(mat3)
|
||||
reject m2(matn)
|
||||
|
||||
21
tests/range/tsubrange.nim
Normal file
21
tests/range/tsubrange.nim
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
discard """
|
||||
line: 20
|
||||
errormsg: "cannot convert 60 to TRange"
|
||||
"""
|
||||
|
||||
type
|
||||
TRange = range[0..40]
|
||||
|
||||
proc p(r: TRange) =
|
||||
nil
|
||||
|
||||
var
|
||||
r: TRange
|
||||
y = 50
|
||||
r = y
|
||||
|
||||
p y
|
||||
|
||||
const
|
||||
myConst: TRange = 60
|
||||
|
||||
17
tests/range/tsubrange2.nim
Normal file
17
tests/range/tsubrange2.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
discard """
|
||||
file: "tsubrange2.nim"
|
||||
outputsub: "value out of range: 50 [EOutOfRange]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
type
|
||||
TRange = range[0..40]
|
||||
|
||||
proc p(r: TRange) =
|
||||
nil
|
||||
|
||||
var
|
||||
r: TRange
|
||||
y = 50
|
||||
p y
|
||||
|
||||
19
tests/range/tsubrange3.nim
Normal file
19
tests/range/tsubrange3.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
discard """
|
||||
file: "tsubrange.nim"
|
||||
outputsub: "value out of range: 50 [EOutOfRange]"
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
type
|
||||
TRange = range[0..40]
|
||||
|
||||
proc p(r: TRange) =
|
||||
nil
|
||||
|
||||
var
|
||||
r: TRange
|
||||
y = 50
|
||||
r = y
|
||||
|
||||
#p y
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue