Skip to content

Commit

Permalink
Add tests for expressions and cmp reg1, reg2
Browse files Browse the repository at this point in the history
  • Loading branch information
belijzajac committed May 3, 2024
1 parent ffbd6bb commit 065c289
Showing 1 changed file with 211 additions and 1 deletion.
212 changes: 211 additions & 1 deletion tests/programs/ProgramTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ TEST_F(ProgramTest, CalculateProduct) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "3715891200");
}

TEST_F(ProgramTest, CalculateExpression) {
TEST_F(ProgramTest, CalculateExpression1) {
constexpr auto program = R"(
fn main() {
int expr = ((1 + 2) * 3 + 4 * 5) - 6 * 7 + 13;
Expand All @@ -386,6 +386,36 @@ TEST_F(ProgramTest, CalculateExpression) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "0");
}

TEST_F(ProgramTest, CalculateExpression2) {
constexpr auto program = R"(
fn main() {
int expr = 0;
print(expr + 1 + 1 + expr + expr + 1 + expr + 1 + expr + 1 + 1);
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "6");
}

TEST_F(ProgramTest, CalculateExpression3) {
constexpr auto program = R"(
fn main() {
int expr = 0;
print(expr + 1 * 1 + expr + expr + 1 + expr * 1 + expr + 1 + 1);
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "4");
}

TEST_F(ProgramTest, CalculateExpression4) {
constexpr auto program = R"(
fn main() {
int expr = 5;
print(expr + 1 * 1 + expr + expr + 1 + expr * 1 + expr + 1 + 1);
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "29");
}

TEST_F(ProgramTest, PrintSum) {
constexpr auto program = R"(
fn main() {
Expand Down Expand Up @@ -861,6 +891,21 @@ TEST_F(ProgramTest, ConditionalIntGreaterThanTrue) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntVariablesGreaterThanTrue) {
constexpr auto program = R"(
fn main() {
int value1 = 7;
int value2 = 6;
if (value1 > value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntGreaterThanFalse) {
constexpr auto program = R"(
fn main() {
Expand All @@ -875,6 +920,21 @@ TEST_F(ProgramTest, ConditionalIntGreaterThanFalse) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntVariablesGreaterThanFalse) {
constexpr auto program = R"(
fn main() {
int value1 = 6;
int value2 = 6;
if (value1 > value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntGreaterThanOrEqualTrue) {
constexpr auto program = R"(
fn main() {
Expand All @@ -889,6 +949,21 @@ TEST_F(ProgramTest, ConditionalIntGreaterThanOrEqualTrue) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntVariableGreaterThanOrEqualTrue) {
constexpr auto program = R"(
fn main() {
int value1 = 6;
int value2 = 6;
if (value1 >= value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntGreaterThanOrEqualFalse) {
constexpr auto program = R"(
fn main() {
Expand All @@ -903,6 +978,21 @@ TEST_F(ProgramTest, ConditionalIntGreaterThanOrEqualFalse) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntVariablesGreaterThanOrEqualFalse) {
constexpr auto program = R"(
fn main() {
int value1 = 5;
int value2 = 6;
if (value1 >= value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntLessTrue) {
constexpr auto program = R"(
fn main() {
Expand All @@ -917,6 +1007,21 @@ TEST_F(ProgramTest, ConditionalIntLessTrue) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntVariablesLessTrue) {
constexpr auto program = R"(
fn main() {
int value1 = 5;
int value2 = 6;
if (value1 < value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntLessFalse) {
constexpr auto program = R"(
fn main() {
Expand All @@ -931,6 +1036,21 @@ TEST_F(ProgramTest, ConditionalIntLessFalse) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntVariablesLessFalse) {
constexpr auto program = R"(
fn main() {
int value1 = 7;
int value2 = 6;
if (value1 < value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntLessOrEqualTrue) {
constexpr auto program = R"(
fn main() {
Expand All @@ -945,6 +1065,21 @@ TEST_F(ProgramTest, ConditionalIntLessOrEqualTrue) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntVariablesLessOrEqualTrue) {
constexpr auto program = R"(
fn main() {
int value1 = 6;
int value2 = 6;
if (value1 <= value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntLessOrEqualFalse) {
constexpr auto program = R"(
fn main() {
Expand All @@ -959,6 +1094,21 @@ TEST_F(ProgramTest, ConditionalIntLessOrEqualFalse) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntVariablesLessOrEqualFalse) {
constexpr auto program = R"(
fn main() {
int value1 = 10;
int value2 = 6;
if (value1 <= value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntEqualTrue) {
constexpr auto program = R"(
fn main() {
Expand All @@ -973,6 +1123,21 @@ TEST_F(ProgramTest, ConditionalIntEqualTrue) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntVariablesEqualTrue) {
constexpr auto program = R"(
fn main() {
int value1 = 6;
int value2 = 6;
if (value1 == value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntEqualFalse) {
constexpr auto program = R"(
fn main() {
Expand All @@ -987,6 +1152,21 @@ TEST_F(ProgramTest, ConditionalIntEqualFalse) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntVariablesEqualFalse) {
constexpr auto program = R"(
fn main() {
int value1 = 7;
int value2 = 6;
if (value1 == value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntNotEqualTrue) {
constexpr auto program = R"(
fn main() {
Expand All @@ -1001,6 +1181,21 @@ TEST_F(ProgramTest, ConditionalIntNotEqualTrue) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntVariablesNotEqualTrue) {
constexpr auto program = R"(
fn main() {
int value1 = 5;
int value2 = 6;
if (value1 != value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "true");
}

TEST_F(ProgramTest, ConditionalIntNotEqualFalse) {
constexpr auto program = R"(
fn main() {
Expand All @@ -1015,6 +1210,21 @@ TEST_F(ProgramTest, ConditionalIntNotEqualFalse) {
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalIntVariablesNotEqualFalse) {
constexpr auto program = R"(
fn main() {
int value1 = 6;
int value2 = 6;
if (value1 != value2) {
print("true");
} else {
print("false");
}
})"sv;
SetUp(program);
EXPECT_PROGRAM_OUTPUT(exec("./a.out"), "false");
}

TEST_F(ProgramTest, ConditionalBooleanFollowup) {
constexpr auto program = R"(
fn main() {
Expand Down

0 comments on commit 065c289

Please sign in to comment.