-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rs
290 lines (277 loc) · 11.4 KB
/
test.rs
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#![license="BSD simplified"]
#![feature(macro_rules)]
extern crate hangeul;
extern crate aheui;
macro_rules! check_final_draw_counts(
($final:expr, $count:expr) => (
assert_eq!(aheui::final_draw_counts[$final as uint], $count);
)
)
#[cfg(test)]
mod tests {
use hangeul;
use aheui;
use aheui::{Instruction, Source, Interpreter};
#[test]
pub fn test_source() {
let s = Source::from_str("아희\n밯망희");
assert_eq!(s.get((0, 0)).hangeul().char().unwrap(), '아');
assert_eq!(s.get((0, 1)).hangeul().char().unwrap(), '희');
assert_eq!(s.get((1, 0)).hangeul().char().unwrap(), '밯');
assert_eq!(s.get((1, 2)).hangeul().char().unwrap(), '희');
}
#[test]
pub fn test_final_draw_counts() {
check_final_draw_counts!(hangeul::FinalBlank, 0);
check_final_draw_counts!(hangeul::FinalGiyeok, 2);
check_final_draw_counts!(hangeul::FinalGiyeokSiot, 4);
check_final_draw_counts!(hangeul::FinalRieul, 5);
check_final_draw_counts!(hangeul::FinalRieulBieup, 9);
check_final_draw_counts!(hangeul::FinalRieulTieut, 9);
check_final_draw_counts!(hangeul::FinalChieut, 4);
}
#[test]
pub fn test_it() {
{
let mut it = Interpreter::new(Source::from_str(""));
assert_eq!(it.counter(), (0, 0));
it.instruct(&Instruction::from_char('아'));
assert_eq!(it.counter(), (0, 1));
it.instruct(&Instruction::from_char('희'));
assert_eq!(it.counter(), (0, 1));
}
{
let source = Source::from_str("아희");
let mut it = Interpreter::new(source);
it.execute();
assert_eq!(it.counter(), (0, 1));
}
}
#[test]
pub fn test_peak() {
let mut it = Interpreter::new(Source::from_str(""));
assert_eq!(it.counter(), (0, 0));
it.instruct(&Instruction::from_char('아'));
assert_eq!(it.counter(), (0, 1));
it.instruct(&Instruction::from_char('우'));
assert_eq!(it.counter(), (1, 1));
it.instruct(&Instruction::from_char('어'));
assert_eq!(it.counter(), (1, 0));
it.instruct(&Instruction::from_char('오'));
assert_eq!(it.counter(), (0, 0));
it.instruct(&Instruction::from_char('우'));
assert_eq!(it.counter(), (1, 0));
it.instruct(&Instruction::from_char('이'));
assert_eq!(it.counter(), (2, 0));
it.instruct(&Instruction::from_char('으'));
assert_eq!(it.counter(), (1, 0));
it.instruct(&Instruction::from_char('아'));
assert_eq!(it.counter(), (1, 1));
it.instruct(&Instruction::from_char('으'));
assert_eq!(it.counter(), (1, 2));
it.instruct(&Instruction::from_char('이'));
assert_eq!(it.counter(), (1, 1));
it.instruct(&Instruction::from_char('의'));
assert_eq!(it.counter(), (1, 2));
}
#[test]
pub fn test_wall() {
let mut it = Interpreter::new(Source::from_str("어아"));
assert_eq!(it.counter(), (0, 0));
assert!(!it.step());
assert_eq!(it.counter(), (0, -1));
assert!(!it.step());
assert_eq!(it.counter(), (0, 1));
assert!(!it.step());
assert_eq!(it.counter(), (0, 2));
assert!(!it.step());
assert_eq!(it.counter(), (0, 0));
assert!(!it.step());
}
#[test]
pub fn test_initial() {
let mut it = Interpreter::new(Source::from_str(""));
it.instruct(&Instruction::from_char('바'));
assert_eq!(it.storage().peek().unwrap(), 0);
it.instruct(&Instruction::from_char('반'));
assert_eq!(it.storage().peek().unwrap(), 2);
it.instruct(&Instruction::from_char('밧'));
assert_eq!(it.storage().peek().unwrap(), 2);
it.instruct(&Instruction::from_char('나'));
assert_eq!(it.storage().peek().unwrap(), 1);
it.instruct(&Instruction::from_char('밟'));
assert_eq!(it.storage().peek().unwrap(), 9);
it.instruct(&Instruction::from_char('밭'));
assert_eq!(it.storage().peek().unwrap(), 4);
it.instruct(&Instruction::from_char('다'));
assert_eq!(it.storage().peek().unwrap(), 13);
it.instruct(&Instruction::from_char('밪'));
assert_eq!(it.storage().peek().unwrap(), 3);
it.instruct(&Instruction::from_char('따'));
assert_eq!(it.storage().peek().unwrap(), 39);
it.instruct(&Instruction::from_char('반'));
assert_eq!(it.storage().peek().unwrap(), 2);
it.instruct(&Instruction::from_char('눔'));
assert_eq!(it.storage().peek().unwrap(), 19);
it.instruct(&Instruction::from_char('발'));
assert_eq!(it.storage().peek().unwrap(), 5);
it.instruct(&Instruction::from_char('룸'));
assert_eq!(it.storage().peek().unwrap(), 4);
it.instruct(&Instruction::from_char('밥'));
assert_eq!(it.storage().peek().unwrap(), 4);
it.instruct(&Instruction::from_char('주'));
assert_eq!(it.storage().peek().unwrap(), 1);
it.instruct(&Instruction::from_char('반'));
assert_eq!(it.storage().peek().unwrap(), 2);
it.instruct(&Instruction::from_char('주'));
assert_eq!(it.storage().peek().unwrap(), 0);
}
#[test]
pub fn test_chieut() {
let mut it = Interpreter::new(Source::from_str(""));
assert_eq!(it.counter(), (0, 0));
it.instruct(&Instruction::from_char('반'));
assert_eq!(it.counter(), (0, 1));
assert_eq!(it.storage().peek().unwrap(), 2);
it.instruct(&Instruction::from_char('찬'));
assert_eq!(it.counter(), (0, 2));
assert_eq!(it.storage().len(), 0);
it.instruct(&Instruction::from_char('바'));
assert_eq!(it.counter(), (0, 3));
assert_eq!(it.storage().peek().unwrap(), 0);
it.instruct(&Instruction::from_char('쳐'));
assert_eq!(it.counter(), (0, 5));
assert_eq!(it.storage().len(), 0);
}
#[test]
pub fn test_queue() {
let mut it = Interpreter::new(Source::from_str(""));
it.instruct(&Instruction::from_char('상'));
it.instruct(&Instruction::from_char('반'));
it.instruct(&Instruction::from_char('발'));
it.instruct(&Instruction::from_char('밞'));
assert_eq!(it.storage().peek().unwrap(), 2);
it.instruct(&Instruction::from_char('팡'));
assert_eq!(it.storage().peek().unwrap(), 5);
it.instruct(&Instruction::from_char('덧'));
assert_eq!(it.storage().peek().unwrap(), 9);
it.instruct(&Instruction::from_char('멍'));
assert_eq!(it.storage().peek().unwrap(), 7);
}
#[test]
pub fn test_helloworld() {
let source = Source::from_str("밤밣따빠밣밟따뿌\n빠맣파빨받밤뚜뭏\n돋밬탕빠맣붏두붇\n볻뫃박발뚷투뭏붖\n뫃도뫃희멓뭏뭏붘\n뫃봌토범더벌뿌뚜\n뽑뽀멓멓더벓뻐뚠\n뽀덩벐멓뻐덕더벅");
let mut it = Interpreter::new(source);
assert_eq!(it.counter(), (0, 0));
assert_eq!(it.storage().len(), 0);
assert!(!it.step());
assert_eq!(it.counter(), (0, 1));
assert_eq!(it.storage().len(), 1);
assert_eq!(it.storage().peek().unwrap(), 4);
assert!(!it.step());
assert_eq!(it.counter(), (0, 2));
assert_eq!(it.storage().len(), 2);
assert_eq!(it.storage().peek().unwrap(), 8);
assert!(!it.step());
assert_eq!(it.counter(), (0, 3));
assert!(!it.step());
assert_eq!(it.counter(), (0, 4));
assert!(!it.step());
assert_eq!(it.counter(), (0, 5));
assert!(!it.step());
assert_eq!(it.counter(), (0, 6));
assert!(!it.step());
assert_eq!(it.counter(), (0, 7));
assert!(!it.step());
assert_eq!(it.counter(), (1, 7));
}
#[test]
pub fn test_99dan() {
let source = Source::from_str("삼반반타반빠빠빠빠빠빠뿌\n우어번벋벋범벌벖벍벓벒석\n");
let mut it = Interpreter::new(source);
assert_eq!(it.counter(), (0, 0));
assert_eq!(it.storage().len(), 0);
assert!(!it.step());
assert_eq!(it.counter(), (0, 1));
assert_eq!(it.storage().len(), 0);
assert!(!it.step());
assert_eq!(it.counter(), (0, 2));
assert_eq!(it.storage().len(), 1);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 3));
assert_eq!(it.storage().len(), 2);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 4));
assert_eq!(it.storage().len(), 1);
assert_eq!(it.storage().peek().unwrap(), 0);
assert!(!it.step());
assert_eq!(it.counter(), (0, 5));
assert_eq!(it.storage().len(), 2);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 6));
assert_eq!(it.storage().len(), 3);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 7));
assert_eq!(it.storage().len(), 4);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 8));
assert_eq!(it.storage().len(), 5);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 9));
assert_eq!(it.storage().len(), 6);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 10));
assert_eq!(it.storage().len(), 7);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (0, 11));
assert_eq!(it.storage().len(), 8);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (1, 11));
assert_eq!(it.storage().len(), 9);
assert_eq!(it.storage().peek().unwrap(), 2);
assert!(!it.step());
assert_eq!(it.counter(), (1, 10));
assert_eq!(it.storage().len(), 0);
assert!(!it.step());
assert_eq!(it.counter(), (1, 9));
assert_eq!(it.storage().len(), 1);
assert_eq!(it.storage().peek().unwrap(), 9);
assert!(!it.step());
assert_eq!(it.counter(), (1, 8));
assert_eq!(it.storage().len(), 2);
assert_eq!(it.storage().peek().unwrap(), 8);
assert!(!it.step());
assert_eq!(it.counter(), (1, 7));
assert_eq!(it.storage().len(), 3);
assert_eq!(it.storage().peek().unwrap(), 7);
assert!(!it.step());
assert_eq!(it.counter(), (1, 6));
assert_eq!(it.storage().len(), 4);
assert_eq!(it.storage().peek().unwrap(), 6);
assert!(!it.step());
assert_eq!(it.counter(), (1, 5));
assert_eq!(it.storage().len(), 5);
assert_eq!(it.storage().peek().unwrap(), 5);
assert!(!it.step());
assert_eq!(it.counter(), (1, 4));
assert_eq!(it.storage().len(), 6);
assert_eq!(it.storage().peek().unwrap(), 4);
assert!(!it.step());
assert_eq!(it.counter(), (1, 3));
assert_eq!(it.storage().len(), 7);
assert_eq!(it.storage().peek().unwrap(), 3);
assert!(!it.step());
assert_eq!(it.counter(), (1, 2));
assert_eq!(it.storage().len(), 8);
assert_eq!(it.storage().peek().unwrap(), 3);
}
}