-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_test.pony
149 lines (138 loc) · 6.93 KB
/
_test.pony
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
use "ponytest"
actor TestMain is TestList
new create(env: Env) =>
PonyTest(env, this)
new make() =>
None
fun tag derp(out: StdStream tag)=>
out.print("")
fun tag tests(test: PonyTest) =>
test(_TestMerge)
// test(_TestSub)
// TODO: revisit
//cant seem to get this working with tuples
class RowCmp is (Equatable[RowCmp] & Stringable)
let _r: ROW
new ref create(r: ROW) => _r = r
fun eq(that: box->RowCmp): Bool =>
this._r is that._r
// (this._r._1 == that._r._1) and
// (this._r._2 == that._r._2) and
// (this._r._3 == that._r._3) and
// (this._r._4 == that._r._4)
fun ne(that: box->RowCmp): Bool => not eq(that)
fun box string() : String iso^ =>
let s : String ref = recover String(30) end
s.append("(")
s.append(_r._1.string())
s.append(",")
s.append(_r._2.string())
s.append(",")
s.append(_r._3.string())
s.append(",")
s.append(_r._4.string())
s.append(")")
s.string()
class iso _TestMerge is UnitTest
fun name():String => "2048 Merger test"
fun apply(h: TestHelper) =>
let rows : Array[(ROW, ROW)] = [
// auto gen IN with python # [x for x in itertools.product(*[[0,1,2]]*4)]
// hand jammed OUT
// some repeats since matcher for 1100 is the same as 2200,
// but at least this covers every case
// MERGE DIRECTION <<| |<<<<<<<
/* TEST 1 */ (/*IN*/ (0, 0, 0, 0) ,
/*OUT*/(0,0,0,0) ); /* TEST 2 */ (/*IN*/ (0, 0, 0, 1) ,
/*OUT*/(1,0,0,0) ); /* TEST 3 */ (/*IN*/ (0, 0, 0, 2) ,
/*OUT*/(2,0,0,0) ); /* TEST 4 */ (/*IN*/ (0, 0, 1, 0) ,
/*OUT*/(1,0,0,0) ); /* TEST 5 */ (/*IN*/ (0, 0, 1, 1) ,
/*OUT*/(2,0,0,0) ); /* TEST 6 */ (/*IN*/ (0, 0, 1, 2) ,
/*OUT*/(1,2,0,0) ); /* TEST 7 */ (/*IN*/ (0, 0, 2, 0) ,
/*OUT*/(2,0,0,0) ); /* TEST 8 */ (/*IN*/ (0, 0, 2, 1) ,
/*OUT*/(2,1,0,0) ); /* TEST 9 */ (/*IN*/ (0, 0, 2, 2) ,
/*OUT*/(4,0,0,0) ); /* TEST 10 */ (/*IN*/ (0, 1, 0, 0) ,
/*OUT*/(1,0,0,0) ); /* TEST 11 */ (/*IN*/ (0, 1, 0, 1) ,
/*OUT*/(2,0,0,0) ); /* TEST 12 */ (/*IN*/ (0, 1, 0, 2) ,
/*OUT*/(1,2,0,0) ); /* TEST 13 */ (/*IN*/ (0, 1, 1, 0) ,
/*OUT*/(2,0,0,0) ); /* TEST 14 */ (/*IN*/ (0, 1, 1, 1) ,
/*OUT*/(2,1,0,0) ); /* TEST 15 */ (/*IN*/ (0, 1, 1, 2) ,
/*OUT*/(2,2,0,0) ); /* TEST 16 */ (/*IN*/ (0, 1, 2, 0) ,
/*OUT*/(1,2,0,0) ); /* TEST 17 */ (/*IN*/ (0, 1, 2, 1) ,
/*OUT*/(1,2,1,0) ); /* TEST 18 */ (/*IN*/ (0, 1, 2, 2) ,
/*OUT*/(1,4,0,0) ); /* TEST 19 */ (/*IN*/ (0, 2, 0, 0) ,
/*OUT*/(2,0,0,0) ); /* TEST 20 */ (/*IN*/ (0, 2, 0, 1) ,
/*OUT*/(2,1,0,0) ); /* TEST 21 */ (/*IN*/ (0, 2, 0, 2) ,
/*OUT*/(4,0,0,0) ); /* TEST 22 */ (/*IN*/ (0, 2, 1, 0) ,
/*OUT*/(2,1,0,0) ); /* TEST 23 */ (/*IN*/ (0, 2, 1, 1) ,
/*OUT*/(2,2,0,0) ); /* TEST 24 */ (/*IN*/ (0, 2, 1, 2) ,
/*OUT*/(2,1,2,0) ); /* TEST 25 */ (/*IN*/ (0, 2, 2, 0) ,
/*OUT*/(4,0,0,0) ); /* TEST 26 */ (/*IN*/ (0, 2, 2, 1) ,
/*OUT*/(4,1,0,0) ); /* TEST 27 */ (/*IN*/ (0, 2, 2, 2) ,
/*OUT*/(4,2,0,0) ); /* TEST 28 */ (/*IN*/ (1, 0, 0, 0) ,
/*OUT*/(1,0,0,0) ); /* TEST 29 */ (/*IN*/ (1, 0, 0, 1) ,
/*OUT*/(2,0,0,0) ); /* TEST 30 */ (/*IN*/ (1, 0, 0, 2) ,
/*OUT*/(1,2,0,0) ); /* TEST 31 */ (/*IN*/ (1, 0, 1, 0) ,
/*OUT*/(2,0,0,0) ); /* TEST 32 */ (/*IN*/ (1, 0, 1, 1) ,
/*OUT*/(2,1,0,0) ); /* TEST 33 */ (/*IN*/ (1, 0, 1, 2) ,
/*OUT*/(2,2,0,0) ); /* TEST 34 */ (/*IN*/ (1, 0, 2, 0) ,
/*OUT*/(1,2,0,0) ); /* TEST 35 */ (/*IN*/ (1, 0, 2, 1) ,
/*OUT*/(1,2,1,0) ); /* TEST 36 */ (/*IN*/ (1, 0, 2, 2) ,
/*OUT*/(1,4,0,0) ); /* TEST 37 */ (/*IN*/ (1, 1, 0, 0) ,
/*OUT*/(2,0,0,0) ); /* TEST 38 */ (/*IN*/ (1, 1, 0, 1) ,
/*OUT*/(2,1,0,0) ); /* TEST 39 */ (/*IN*/ (1, 1, 0, 2) ,
/*OUT*/(2,2,0,0) ); /* TEST 40 */ (/*IN*/ (1, 1, 1, 0) ,
/*OUT*/(2,1,0,0) ); /* TEST 41 */ (/*IN*/ (1, 1, 1, 1) ,
/*OUT*/(2,2,0,0) ); /* TEST 42 */ (/*IN*/ (1, 1, 1, 2) ,
/*OUT*/(2,1,2,0) ); /* TEST 43 */ (/*IN*/ (1, 1, 2, 0) ,
/*OUT*/(2,2,0,0) ); /* TEST 44 */ (/*IN*/ (1, 1, 2, 1) ,
/*OUT*/(2,2,1,0) ); /* TEST 45 */ (/*IN*/ (1, 1, 2, 2) ,
/*OUT*/(2,4,0,0) ); /* TEST 46 */ (/*IN*/ (1, 2, 0, 0) ,
/*OUT*/(1,2,0,0) ); /* TEST 47 */ (/*IN*/ (1, 2, 0, 1) ,
/*OUT*/(1,2,1,0) ); /* TEST 48 */ (/*IN*/ (1, 2, 0, 2) ,
/*OUT*/(1,4,0,0) ); /* TEST 49 */ (/*IN*/ (1, 2, 1, 0) ,
/*OUT*/(1,2,1,0) ); /* TEST 50 */ (/*IN*/ (1, 2, 1, 1) ,
/*OUT*/(1,2,2,0) ); /* TEST 51 */ (/*IN*/ (1, 2, 1, 2) ,
/*OUT*/(1,2,1,2) ); /* TEST 52 */ (/*IN*/ (1, 2, 2, 0) ,
/*OUT*/(1,4,0,0) ); /* TEST 53 */ (/*IN*/ (1, 2, 2, 1) ,
/*OUT*/(1,4,1,0) ); /* TEST 54 */ (/*IN*/ (1, 2, 2, 2) ,
/*OUT*/(1,4,2,0) ); /* TEST 55 */ (/*IN*/ (2, 0, 0, 0) ,
/*OUT*/(2,0,0,0) ); /* TEST 56 */ (/*IN*/ (2, 0, 0, 1) ,
/*OUT*/(2,1,0,0) ); /* TEST 57 */ (/*IN*/ (2, 0, 0, 2) ,
/*OUT*/(4,0,0,0) ); /* TEST 58 */ (/*IN*/ (2, 0, 1, 0) ,
/*OUT*/(2,1,0,0) ); /* TEST 59 */ (/*IN*/ (2, 0, 1, 1) ,
/*OUT*/(2,2,0,0) ); /* TEST 60 */ (/*IN*/ (2, 0, 1, 2) ,
/*OUT*/(2,1,2,0) ); /* TEST 61 */ (/*IN*/ (2, 0, 2, 0) ,
/*OUT*/(4,0,0,0) ); /* TEST 62 */ (/*IN*/ (2, 0, 2, 1) ,
/*OUT*/(4,1,0,0) ); /* TEST 63 */ (/*IN*/ (2, 0, 2, 2) ,
/*OUT*/(4,2,0,0) ); /* TEST 64 */ (/*IN*/ (2, 1, 0, 0) ,
/*OUT*/(2,1,0,0) ); /* TEST 65 */ (/*IN*/ (2, 1, 0, 1) ,
/*OUT*/(2,2,0,0) ); /* TEST 66 */ (/*IN*/ (2, 1, 0, 2) ,
/*OUT*/(2,1,2,0) ); /* TEST 67 */ (/*IN*/ (2, 1, 1, 0) ,
/*OUT*/(2,2,0,0) ); /* TEST 68 */ (/*IN*/ (2, 1, 1, 1) ,
/*OUT*/(2,2,1,0) ); /* TEST 69 */ (/*IN*/ (2, 1, 1, 2) ,
/*OUT*/(2,2,2,0) ); /* TEST 70 */ (/*IN*/ (2, 1, 2, 0) ,
/*OUT*/(2,1,2,0) ); /* TEST 71 */ (/*IN*/ (2, 1, 2, 1) ,
/*OUT*/(2,1,2,1) ); /* TEST 72 */ (/*IN*/ (2, 1, 2, 2) ,
/*OUT*/(2,1,4,0) ); /* TEST 73 */ (/*IN*/ (2, 2, 0, 0) ,
/*OUT*/(4,0,0,0) ); /* TEST 74 */ (/*IN*/ (2, 2, 0, 1) ,
/*OUT*/(4,1,0,0) ); /* TEST 75 */ (/*IN*/ (2, 2, 0, 2) ,
/*OUT*/(4,2,0,0) ); /* TEST 76 */ (/*IN*/ (2, 2, 1, 0) ,
/*OUT*/(4,1,0,0) ); /* TEST 77 */ (/*IN*/ (2, 2, 1, 1) ,
/*OUT*/(4,2,0,0) ); /* TEST 78 */ (/*IN*/ (2, 2, 1, 2) ,
/*OUT*/(4,1,2,0) ); /* TEST 79 */ (/*IN*/ (2, 2, 2, 0) ,
/*OUT*/(4,2,0,0) ); /* TEST 80 */ (/*IN*/ (2, 2, 2, 1) ,
/*OUT*/(4,2,1,0) ); /* TEST 81 */ (/*IN*/ (2, 2, 2, 2) ,
/*OUT*/(4,4,0,0) ) ]
var i : U32 = 0
for (rin, rout) in rows.values() do
i = i + 1
var out = RowCmp(Merger(rin))
var expect : RowCmp = RowCmp(rout)
h.assert_eq[RowCmp](expect, out, "@TEST#" + i.string())
end
// fun apply(h: TestHelper) =>
// var out : ROW box
// out = Merger((0,0,0,0))
// var dat : ROW box= (0,0,0,0)
// h.assert_eq[ROW box](out, dat)