-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest5.t
76 lines (58 loc) · 1.39 KB
/
test5.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
--local SVector = {}
SVector = terralib.memoize(function(T,N)
local struct Vector{
_data : T[N]
}
local Class = {}
Class.Vector = Vector
terra Vector:size() : int
return N
end
Vector.metamethods.__apply = macro(function(self,idx)
return `self._data[idx]
end)
terra Class.fill(a : T) : Vector
var v : Vector
for i = 0,N do
v(i) = a
end
return v
end
return Class
end)
import "terratest" -- using the terra unit test library
testenv "Vector implementation" do
for _,T in pairs{int32,int64} do
for N=2,3 do
--parameterized testset
testset(N,T) "fill" do
local SVec = SVector(T,N)
terracode
var y = SVec.fill(3)
end
test y:size()==N
for i=0,N-1 do
test y(i)==T(3)
end
end
end
end
end --testenv
for _,T in pairs{int32,int64} do
for N=2,3 do
--parameterized testenv
testenv(N,T) "Vector implementation" do
--parameterized testset
testset "fill" do
local SVec = SVector(T,N)
terracode
var y = SVec.fill(3)
end
test y:size()==N
for i=0,N-1 do
test y(i)==T(3)
end
end
end --testenv
end --N
end --T