forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvalMatrixMultiply.test
More file actions
73 lines (58 loc) · 1.45 KB
/
EvalMatrixMultiply.test
File metadata and controls
73 lines (58 loc) · 1.45 KB
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
setup "square matrices"
local tIdentity, tA1, tA2, tA3
put 1 into tIdentity[0,0]
put 0 into tIdentity[0,1]
put 0 into tIdentity[1,0]
put 1 into tIdentity[1,1]
local tVal = 1
repeat with r = 0 to 1
repeat with c = 0 to 1
put tVal into tA1[r,c]
add 1 to tVal
end repeat
end repeat
repeat with r = 0 to 1
repeat with c = 0 to 1
put tVal into tA2[r,c]
add 1 to tVal
end repeat
end repeat
test matrixMultiply(tIdentity, tA1) is tA1
test matrixMultiply(tA1, tIdentity) is tA1
put matrixMultiply(tA1, tA2) into tA3
test matrixMultiply(tA2, tA1) is not tA3
test tA3[0,0] is (tA1[0,0] * tA2[0,0]) + (tA1[0,1] * tA2[1,0])
test tA3[0,1] is (tA1[0,0] * tA2[0,1]) + (tA1[0,1] * tA2[1,1])
test tA3[1,0] is (tA1[1,0] * tA2[0,0]) + (tA1[1,1] * tA2[1,0])
test tA3[1,1] is (tA1[1,0] * tA2[0,1]) + (tA1[1,1] * tA2[1,1])
teardown
setup "non-square matrices"
local tA1, tA2, tA3
local tVal = 1
repeat with r = 0 to 2
repeat with c = 0 to 3
put tVal into tA1[r,c]
add 1 to tVal
end repeat
end repeat
repeat with r = 0 to 3
repeat with c = 0 to 4
put tVal into tA2[r,c]
add 1 to tVal
end repeat
end repeat
put matrixMultiply(tA1, tA2) into tA3
test tA3 is an array
test the extents of tA3 is ("0,2" & return & "0,4")
local tTotal
repeat with i = 0 to 2
repeat with j = 0 to 4
put 0 into tTotal
repeat with k = 0 to 3
add tA1[i,k] * tA2[k, j] to tTotal
end repeat
test tTotal is tA3[i,j]
end repeat
end repeat
test-error matrixMultiply(tA2, tA1)
teardown