Coverage for skema/program_analysis/CAST/matlab/tests/test_operators.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-30 17:15 +0000

1from skema.program_analysis.CAST.matlab.tests.utils import (check, cast) 

2from skema.program_analysis.CAST2FN.model.cast import ( 

3 Assignment, 

4 Call, 

5 Operator 

6) 

7 

8def test_binary_operator(): 

9 """ Test CAST from binary operator.""" 

10 check(cast("y + z;")[0], Operator(op = "+", operands = ["y","z"])) 

11 

12def test_boolean_operator(): 

13 """ Test CAST from boolean operator.""" 

14 check(cast("yes && no;")[0], Operator(op = "&&", operands = ["yes","no"])) 

15 

16def test_unary_operator(): 

17 """ Test CAST from unary operator.""" 

18 check(cast("-6;")[0], Operator(op = "-", operands = [6])) 

19 

20def test_comparison_operator(): 

21 """ Test CAST from comparison operator.""" 

22 check(cast("y < 4;")[0], Operator(op = "<", operands = ["y", 4])) 

23 

24def test_not_operator(): 

25 """ Test CAST from matrix not operator.""" 

26 check(cast("~y")[0], Operator(op = "~", operands = ["y"])) 

27 

28def test_postfix_operator(): 

29 """ Test CAST from postfix operator.""" 

30 check(cast("y'")[0], Operator(op = "'", operands = ["y"])) 

31 

32def test_spread_operator(): 

33 """ Test CAST from spread operator.""" 

34 check( 

35 cast("foo(:)")[0], 

36 Call( 

37 func = "foo", 

38 arguments = [Operator(op = ":", operands = [])] 

39 ) 

40 ) 

41 

42def test_pemdas_add_multiply(): 

43 """ Test PEMDAS compliance with addition and multiplication.""" 

44 check( 

45 cast("foo + bar * baz")[0], 

46 Operator( 

47 op = "+", 

48 operands = [ 

49 "foo", 

50 Operator(op = "*", operands = ["bar", "baz"]) 

51 ] 

52 ) 

53 ) 

54 

55def test_pemdas_multiply_parenthesis_add(): 

56 """ Test PEMDAS compliance with multiplication of parenthesized addition.""" 

57 check( 

58 cast("(foo + bar) * baz")[0], 

59 Operator( 

60 op = "*", 

61 operands = [ 

62 Operator(op = "+", operands = ["foo", "bar"]), 

63 "baz" 

64 ] 

65 ) 

66 )