Skip to content

Commit

Permalink
Merge pull request #69 from czgdp1807/switch_case_01
Browse files Browse the repository at this point in the history
TEST: Replace if-else-if workaround with switch-case
  • Loading branch information
czgdp1807 authored Jan 23, 2024
2 parents ded59c9 + 861a255 commit df05c1d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
56 changes: 33 additions & 23 deletions integration_tests/array_15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,46 @@ std::cout << c << std::endl;
for( i = 0; i < a.shape(0); i++ ) {
for( j = 0; j < a.shape(1); j++ ) {
for( k = 0; k < a.shape(2); k++ ) {
// TODO: Achieve the following by switch case.
// Check integration_tests/arrays_op_3.f90
if( op_code == 0 ) {
if(c(i, j, k) != (a(i, j, k) == b(i, j, k))) {
exit(2);
switch( op_code ) {
case 0: {
if(c(i, j, k) != (a(i, j, k) == b(i, j, k))) {
exit(2);
}
break;
}
} else if( op_code == 1 ) {
if(c(i, j, k) != (a(i, j, k) != b(i, j, k))) {
exit(2);
case 1: {
if(c(i, j, k) != (a(i, j, k) != b(i, j, k))) {
exit(2);
}
break;
}
} else if( op_code == 2 ) {
if(c(i, j, k) != (a(i, j, k) < b(i, j, k))) {
exit(2);
case 2: {
if(c(i, j, k) != (a(i, j, k) < b(i, j, k))) {
exit(2);
}
break;
}
} else if( op_code == 3 ) {
if(c(i, j, k) != (b(i, j, k) <= a(i, j, k))) {
exit(2);
case 3: {
if(c(i, j, k) != (b(i, j, k) <= a(i, j, k))) {
exit(2);
}
break;
}
} else if( op_code == 4 ) {
if(c(i, j, k) != (b(i, j, k) > a(i, j, k))) {
exit(2);
case 4: {
if(c(i, j, k) != (b(i, j, k) > a(i, j, k))) {
exit(2);
}
break;
}
case 5: {
if(c(i, j, k) != (b(i, j, k) >= a(i, j, k))) {
exit(2);
}
break;
}
break;
} else if( op_code == 5 ) {
if(c(i, j, k) != (b(i, j, k) >= a(i, j, k))) {
default: {
exit(2);
}
break;
} else {
exit(2);
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions integration_tests/array_16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ for( i = 0; i < c.shape(0); i++ ) {
for( k = 0; k < c.shape(2); k++ ) {
left = i + j + k + 3;
right = (i + 1)*(j + 1)*(k + 1);
if( op_code == 0 ) {
if(c(i, j, k) != left + right*1.0i) {
exit(2);
switch( op_code ) {
case 0: {
if(c(i, j, k) != left + right*1.0i) {
exit(2);
}
break;
}
} else if( op_code == 1 ) {
if(c(i, j, k) != -left - right*1.0i) {
exit(2);
case 1: {
if(c(i, j, k) != -left - right*1.0i) {
exit(2);
}
break;
}
}
}
Expand Down

0 comments on commit df05c1d

Please sign in to comment.