-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.rs
More file actions
42 lines (37 loc) · 1.29 KB
/
Copy pathtest.rs
File metadata and controls
42 lines (37 loc) · 1.29 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
#[macro_use]
extern crate lalrpop_util;
lalrpop_mod!(pub arithmetic);
#[test]
fn multiplication() {
let parser = arithmetic::TermParser::new();
assert_eq!(parser.parse("(3*3)").unwrap(), 9.0);
assert_eq!(parser.parse("(-3*-3)").unwrap(), 9.0);
assert_eq!(parser.parse("(3*-3)").unwrap(), -9.0);
assert_eq!(parser.parse("(-3*3)").unwrap(), -9.0);
}
#[test]
fn addition() {
let parser = arithmetic::TermParser::new();
assert_eq!(parser.parse("(3+3)").unwrap(), 6.0);
assert_eq!(parser.parse("(-3+-3)").unwrap(), -6.0);
assert_eq!(parser.parse("(3+-3)").unwrap(), 0.0);
assert_eq!(parser.parse("(-3+3)").unwrap(), 0.0);
}
#[test]
fn division() {
let parser = arithmetic::TermParser::new();
assert_eq!(parser.parse("(6/2)").unwrap(), 3.0);
assert_eq!(parser.parse("(6/-2)").unwrap(), -3.0);
assert_eq!(parser.parse("(-6/-2)").unwrap(), 3.0);
assert_eq!(parser.parse("(-6/2)").unwrap(), -3.0);
#[should_panic]
assert_eq!(parser.parse("(6/0)").unwrap(), 0.0);
}
#[test]
fn subtraction() {
let parser = arithmetic::TermParser::new();
assert_eq!(parser.parse("(-3--3)").unwrap(), 0.0);
assert_eq!(parser.parse("(3--3)").unwrap(), 6.0);
assert_eq!(parser.parse("(-3-3)").unwrap(), 6.0);
assert_eq!(parser.parse("(3-3)").unwrap(), 0.0);
}