Skip to content

Commit

Permalink
Merge pull request #3 from Ishad-M-I-M/improve-code-coverage
Browse files Browse the repository at this point in the history
Add new test cases
  • Loading branch information
Ishad-M-I-M authored Dec 18, 2023
2 parents fff7a85 + 512f666 commit 279711e
Show file tree
Hide file tree
Showing 25 changed files with 190 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/main/java/io/rpal/ast/evaluator/csemachine/Machine.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ else if (element instanceof Tor) {
}
stack.push(element, environment);
}


}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Object apply(Object operand1, Object operand2) {
case "-" -> op1 - op2;
case "*" -> op1 * op2;
case "/" -> op1 / op2;
case "**" -> Math.pow(op1, op2);
case "**" -> (int)Math.pow(op1, op2);

// Boolean operations
case "eq" -> op1 == op2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public void testStandardTreeGeneration(String filename) throws Exception {

@DataProvider(name = "standardTreeGenerationTestDataProvider")
public Object[] dataProvider() {
return new Object[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "9-simplified", "10", "11", "12"};
return new Object[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "9-simplified", "10", "11", "12", "13",
"14", "neg", "bops", "string_comparisons"};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void testStandardTreeEvaluation(String filename) throws Exception {

@DataProvider(name = "standardTreeEvaluationTestDataProvider")
public Object[] dataProvider() {
return new Object[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "9-simplified", "10", "11", "12"};
return new Object[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "9-simplified", "10", "11", "12", "13",
"14", "neg", "bops", "string_comparisons"};
}
}
12 changes: 12 additions & 0 deletions src/test/resources/astFiles/13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let
.=
..<ID:x>
..tau
...<INT:1>
...<INT:2>
...<INT:3>
.gamma
..<ID:Print>
..gamma
...<ID:x>
...<INT:2>
12 changes: 12 additions & 0 deletions src/test/resources/astFiles/14.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let
.=
..<ID:x>
..tau
...<INT:1>
...<INT:2>
...<INT:3>
.gamma
..<ID:Print>
..gamma
...<ID:Order>
...<ID:x>
21 changes: 21 additions & 0 deletions src/test/resources/astFiles/bops.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let
.=
..<ID:x>
..->
...ne
..../
.....**
......<INT:2>
......<INT:4>
.....<INT:16>
....<INT:1>
...<STR:'Error'>
...->
....ge
.....<INT:4>
.....<INT:5>
....<STR:'Error'>
....<STR:'Correct'>
.gamma
..<ID:Print>
..<ID:x>
12 changes: 12 additions & 0 deletions src/test/resources/astFiles/neg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let
.=
..<ID:x>
..<INT:2>
.gamma
..<ID:Print>
..tau
...neg
....<ID:x>
...neg
....neg
.....<ID:x>
31 changes: 31 additions & 0 deletions src/test/resources/astFiles/string_comparisons.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
let
.=
..<ID:x>
..tau
...ls
....<STR:'a'>
....<STR:'b'>
...ls
....<STR:'b'>
....<STR:'a'>
...le
....<STR:'b'>
....<STR:'c'>
...le
....<STR:'c'>
....<STR:'b'>
...gr
....<STR:'d'>
....<STR:'e'>
...gr
....<STR:'e'>
....<STR:'d'>
...ge
....<STR:'f'>
....<STR:'g'>
...ge
....<STR:'g'>
....<STR:'f'>
.gamma
..<ID:Print>
..<ID:x>
1 change: 1 addition & 0 deletions src/test/resources/expectedOutputs/13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions src/test/resources/expectedOutputs/14.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions src/test/resources/expectedOutputs/bops.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Correct
1 change: 1 addition & 0 deletions src/test/resources/expectedOutputs/neg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(-2, 2)
1 change: 1 addition & 0 deletions src/test/resources/expectedOutputs/string_comparisons.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(true, false, true, false, false, true, false, true)
12 changes: 12 additions & 0 deletions src/test/resources/expectedSTs/13.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
gamma
.lambda
..x
..gamma
...Print
...gamma
....x
....2
.tau
..1
..2
..3
12 changes: 12 additions & 0 deletions src/test/resources/expectedSTs/14.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
gamma
.lambda
..x
..gamma
...Print
...gamma
....Order
....x
.tau
..1
..2
..3
21 changes: 21 additions & 0 deletions src/test/resources/expectedSTs/bops.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
gamma
.lambda
..x
..gamma
...Print
...x
.->
..ne
.../
....**
.....2
.....4
....16
...1
..Error
..->
...ge
....4
....5
...Error
...Correct
12 changes: 12 additions & 0 deletions src/test/resources/expectedSTs/neg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
gamma
.lambda
..x
..gamma
...Print
...tau
....neg
.....x
....neg
.....neg
......x
.2
31 changes: 31 additions & 0 deletions src/test/resources/expectedSTs/string_comparisons.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
gamma
.lambda
..x
..gamma
...Print
...x
.tau
..ls
...a
...b
..ls
...b
...a
..le
...b
...c
..le
...c
...b
..gr
...d
...e
..gr
...e
...d
..ge
...f
...g
..ge
...g
...f
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions src/test/resources/rpalPrograms/14.rpal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = (1, 2, 3) in Print(Order x)
1 change: 1 addition & 0 deletions src/test/resources/rpalPrograms/bops.rpal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = 2**4/16 ne 1 -> 'Error' | 4 ge 5 -> 'Error' | 'Correct' in Print(x)
1 change: 1 addition & 0 deletions src/test/resources/rpalPrograms/neg.rpal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x=2 in Print ((-x), -(-x))
1 change: 1 addition & 0 deletions src/test/resources/rpalPrograms/string_comparisons.rpal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = ('a' ls 'b', 'b' ls 'a', 'b' le 'c', 'c' le 'b', 'd' gr 'e', 'e' gr 'd', 'f' ge 'g', 'g' ge 'f') in Print(x)

0 comments on commit 279711e

Please sign in to comment.