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

24 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 Operator 

5) 

6 

7def test_boolean(): 

8 """ Test assignment of literal boolean types. """ 

9 # we translate these MATLAB keywords into capitalized strings for Python 

10 check(cast("x = true")[0], Assignment(left = "x", right = "True")) 

11 check(cast("y = false")[0], Assignment(left = "y", right = "False")) 

12 

13def test_number_zero_integer(): 

14 """ Test assignment of integer and real numbers.""" 

15 check(cast("x = 0")[0], Assignment(left = "x", right = 0)) 

16 

17def test_number_zero_real(): 

18 """ Test assignment of integer and real numbers.""" 

19 check(cast("y = 0.0")[0], Assignment(left = "y", right = 0.0)) 

20 

21def test_number_nonzero(): 

22 """ Test assignment of integer and real numbers.""" 

23 check(cast("z = 1.8")[0], Assignment(left = "z", right = 1.8)) 

24 

25def test_string(): 

26 """ Test assignment of single and double quoted strings.""" 

27 source = """ 

28 x = 'single' 

29 y = "double" 

30 """ 

31 nodes = cast(source) 

32 check(nodes[0], Assignment(left = "x", right = "'single'")) 

33 check(nodes[1], Assignment(left = "y", right = "\"double\"")) 

34 

35def test_identifier(): 

36 """ Test assignment of identifiers.""" 

37 nodes = cast("x = y; r = x") 

38 check(nodes[0], Assignment(left = 'x', right = 'y')) 

39 check(nodes[1], Assignment(left = 'r', right = 'x')) 

40 

41def test_operator(): 

42 """ Test assignment of operator""" 

43 check( 

44 cast("x = x + 1")[0], 

45 Assignment( 

46 left = "x", 

47 right = Operator(op = "+",operands = ["x", 1]) 

48 ) 

49 ) 

50 

51def test_matrix(): 

52 """ Test assignment of matrix""" 

53 check( 

54 cast("x = [1 cat 'dog' ]")[0], 

55 Assignment( 

56 left = "x", 

57 right = [1, 'cat', "'dog'"] 

58 ) 

59 ) 

60