File tree 12 files changed +192
-78
lines changed
12 files changed +192
-78
lines changed Original file line number Diff line number Diff line change @@ -28,3 +28,27 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
28
28
_ => None
29
29
}
30
30
}
31
+
32
+ #[ cfg( test) ]
33
+ mod tests {
34
+ use crate :: types:: Type ;
35
+
36
+ use super :: super :: Operation ;
37
+
38
+ #[ test]
39
+ fn add_numbers ( ) {
40
+ let res_type = Operation :: Add . typ ( & Type :: Number , & Type :: Number ) ;
41
+ assert_eq ! ( res_type, Ok ( Type :: Number ) ) ;
42
+ }
43
+
44
+ #[ test]
45
+ fn add_strings ( ) {
46
+ let res_type = Operation :: Add . typ ( & Type :: String , & Type :: String ) ;
47
+ assert_eq ! ( res_type, Ok ( Type :: String ) ) ;
48
+ }
49
+
50
+ #[ test]
51
+ fn cannot_add_different ( ) {
52
+ assert ! ( Operation :: Add . typ( & Type :: String , & Type :: Number ) . is_err( ) )
53
+ }
54
+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn div_numbers ( ) {
32
+ let res_type = Operation :: Div . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Number ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_div_different ( ) {
38
+ assert ! ( Operation :: Div . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -28,3 +28,27 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
28
28
_ => None
29
29
}
30
30
}
31
+
32
+ #[ cfg( test) ]
33
+ mod tests {
34
+ use crate :: types:: Type ;
35
+
36
+ use super :: super :: Operation ;
37
+
38
+ #[ test]
39
+ fn eq_numbers ( ) {
40
+ let res_type = Operation :: Eq . typ ( & Type :: Number , & Type :: Number ) ;
41
+ assert_eq ! ( res_type, Ok ( Type :: Bool ) ) ;
42
+ }
43
+
44
+ #[ test]
45
+ fn eq_strings ( ) {
46
+ let res_type = Operation :: Eq . typ ( & Type :: String , & Type :: String ) ;
47
+ assert_eq ! ( res_type, Ok ( Type :: Bool ) ) ;
48
+ }
49
+
50
+ #[ test]
51
+ fn cannot_eq_different ( ) {
52
+ assert ! ( Operation :: Eq . typ( & Type :: String , & Type :: Number ) . is_err( ) )
53
+ }
54
+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn gt_numbers ( ) {
32
+ let res_type = Operation :: Gt . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Bool ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_gt_different ( ) {
38
+ assert ! ( Operation :: Gt . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn gte_numbers ( ) {
32
+ let res_type = Operation :: Gte . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Bool ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_gte_different ( ) {
38
+ assert ! ( Operation :: Gte . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn lt_numbers ( ) {
32
+ let res_type = Operation :: Lt . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Bool ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_lt_different ( ) {
38
+ assert ! ( Operation :: Lt . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn lte_numbers ( ) {
32
+ let res_type = Operation :: Lte . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Bool ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_lte_different ( ) {
38
+ assert ! ( Operation :: Lte . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -62,6 +62,3 @@ impl Operation {
62
62
res. expect ( "invalid operation slipped through to the interpreter after a valid operation check" )
63
63
}
64
64
}
65
-
66
- #[ cfg( test) ]
67
- mod tests;
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn mul_numbers ( ) {
32
+ let res_type = Operation :: Mul . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Number ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_mul_different ( ) {
38
+ assert ! ( Operation :: Mul . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn rem_numbers ( ) {
32
+ let res_type = Operation :: Rem . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Number ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_rem_different ( ) {
38
+ assert ! ( Operation :: Rem . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,21 @@ pub fn op(lhs: &Data, rhs: &Data) -> Option<Data> {
20
20
_ => None
21
21
}
22
22
}
23
+
24
+ #[ cfg( test) ]
25
+ mod tests {
26
+ use crate :: types:: Type ;
27
+
28
+ use super :: super :: Operation ;
29
+
30
+ #[ test]
31
+ fn sub_numbers ( ) {
32
+ let res_type = Operation :: Sub . typ ( & Type :: Number , & Type :: Number ) ;
33
+ assert_eq ! ( res_type, Ok ( Type :: Number ) ) ;
34
+ }
35
+
36
+ #[ test]
37
+ fn cannot_sub_different ( ) {
38
+ assert ! ( Operation :: Sub . typ( & Type :: String , & Type :: Number ) . is_err( ) )
39
+ }
40
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments