Skip to content

Commit

Permalink
[Tst] Adds more regression tests for foreach with break/continue
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-goel committed Nov 27, 2023
1 parent f8132d0 commit 82d768e
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 0 deletions.
33 changes: 33 additions & 0 deletions Tst/RegressionTests/Feature2Stmts/Correct/foreach3/foreach3.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/********************
* This example explains the usage of foreach iterator with continue
* ******************/


machine Main {
var ss: set[int];

start state Init {
entry {
var iter: int;
var sum: int;
ss += (100);
ss += (123);
ss += (134);
ss += (245);

foreach(iter in ss)
{
print format ("Iter = {0}, Sum = {1}", iter, sum);
assert sum <= 100, "Incorrect sum inside loop";
sum = sum + iter;
if (iter == 123) {
break;
}
}

print format ("Final Sum = {0}", sum);
assert sum == 223, "Incorrect sum outside loop";
}
}
}

36 changes: 36 additions & 0 deletions Tst/RegressionTests/Feature2Stmts/Correct/foreach4/foreach4.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/********************
* This example explains the usage of foreach iterator with continue
* ******************/


machine Main {
var ss: set[int];

start state Init {
entry {
var iter: int;
var sum: int;
ss += (100);
ss += (134);
ss += (123);
ss += (245);

foreach(iter in ss)
{
print format ("Iter = {0}, Sum = {1}", iter, sum);
assert sum <= 100, "Incorrect sum inside loop";
if (iter == 134) {
continue;
}
sum = sum + iter;
if (iter == 123) {
break;
}
}

print format ("Final Sum = {0}", sum);
assert sum == 223, "Incorrect sum outside loop";
}
}
}

32 changes: 32 additions & 0 deletions Tst/RegressionTests/Feature2Stmts/DynamicError/foreach2/foreach2.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/********************
* This example explains the usage of foreach iterator with continue
* ******************/


machine Main {
var ss: set[int];

start state Init {
entry {
var iter: int;
var sum: int;
ss += (100);
ss += (134);
ss += (245);

foreach(iter in ss)
{
print format ("Iter = {0}, Sum = {1}", iter, sum);
assert sum <= 345, "Incorrect sum inside loop";
if (iter == 134) {
continue;
}
sum = sum + iter;
}

print format ("Final Sum = {0}", sum);
assert sum != 345, "Should get triggered";
}
}
}

33 changes: 33 additions & 0 deletions Tst/RegressionTests/Feature2Stmts/DynamicError/foreach3/foreach3.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/********************
* This example explains the usage of foreach iterator with continue
* ******************/


machine Main {
var ss: set[int];

start state Init {
entry {
var iter: int;
var sum: int;
ss += (100);
ss += (123);
ss += (134);
ss += (245);

foreach(iter in ss)
{
print format ("Iter = {0}, Sum = {1}", iter, sum);
assert sum <= 100, "Incorrect sum inside loop";
sum = sum + iter;
if (iter == 123) {
break;
}
}

print format ("Final Sum = {0}", sum);
assert sum != 223, "Should get triggered";
}
}
}

36 changes: 36 additions & 0 deletions Tst/RegressionTests/Feature2Stmts/DynamicError/foreach4/foreach4.p
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/********************
* This example explains the usage of foreach iterator with continue
* ******************/


machine Main {
var ss: set[int];

start state Init {
entry {
var iter: int;
var sum: int;
ss += (100);
ss += (134);
ss += (123);
ss += (245);

foreach(iter in ss)
{
print format ("Iter = {0}, Sum = {1}", iter, sum);
assert sum <= 100, "Incorrect sum inside loop";
if (iter == 134) {
continue;
}
sum = sum + iter;
if (iter == 123) {
break;
}
}

print format ("Final Sum = {0}", sum);
assert sum != 223, "Should get triggered";
}
}
}

0 comments on commit 82d768e

Please sign in to comment.