Skip to content

Commit 8736dc2

Browse files
author
梶塚太智
committed
Create test.rs
1 parent 43d039d commit 8736dc2

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/test.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use super::{Executor, Mode};
2+
3+
#[test]
4+
fn calculate() {
5+
let mut executor = Executor::new(Mode::Script);
6+
7+
assert_eq!(
8+
{
9+
executor.evaluate_program("5 8 add".to_string());
10+
executor.pop_stack().get_number()
11+
},
12+
13f64
13+
);
14+
15+
assert_eq!(
16+
{
17+
executor.evaluate_program("8 3 sub".to_string());
18+
executor.pop_stack().get_number()
19+
},
20+
5f64
21+
);
22+
23+
assert_eq!(
24+
{
25+
executor.evaluate_program("5 8 mul".to_string());
26+
executor.pop_stack().get_number()
27+
},
28+
40f64
29+
);
30+
31+
assert_eq!(
32+
{
33+
executor.evaluate_program("10 5 div".to_string());
34+
executor.pop_stack().get_number()
35+
},
36+
2f64
37+
);
38+
39+
assert_eq!(
40+
{
41+
executor.evaluate_program("3 2 pow".to_string());
42+
executor.pop_stack().get_number()
43+
},
44+
9f64
45+
);
46+
}
47+
48+
#[test]
49+
fn control() {
50+
let mut executor = Executor::new(Mode::Script);
51+
52+
assert_eq!(
53+
{
54+
executor.evaluate_program("(true) (false) 10 2 div 5 equal if".to_string());
55+
executor.pop_stack().get_bool()
56+
},
57+
true
58+
);
59+
60+
assert_eq!(
61+
{
62+
executor.evaluate_program("(true) (false) 10 2 div 4 equal if".to_string());
63+
executor.pop_stack().get_bool()
64+
},
65+
false
66+
);
67+
68+
assert_eq!(
69+
{
70+
executor.evaluate_program("5 (i) var (i 1 add (i) var) (i 10 less) while i".to_string());
71+
executor.pop_stack().get_number()
72+
},
73+
10f64
74+
);
75+
}

0 commit comments

Comments
 (0)