-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
133 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <fstream> | ||
#include <gtest/gtest.h> | ||
|
||
extern "C" { | ||
#include "main/calculator.h" | ||
} | ||
|
||
void test_add(int x, int y) { | ||
assert(add(x, y) == x + y); | ||
} | ||
|
||
void test_subtract(int x, int y) { | ||
assert(subtract(x, y) == x - y); | ||
} | ||
|
||
void test_multiply(int x, int y) { | ||
assert(multiply(x, y) == x * y); | ||
} | ||
|
||
void test_divide(int x, int y) { | ||
assert(divide(x, y) == x / y); | ||
} | ||
|
||
void test_factor_game(int x, int y) { | ||
factor_game(x, y); // bug is hidden in factor_game() itself, no need for extra assert() here | ||
} | ||
|
||
TEST(CalculatorTest, TestAdd) { | ||
test_add(1, 2); | ||
} | ||
|
||
TEST(CalculatorTest, TestSubtract) { | ||
test_subtract(2, 1); | ||
} | ||
|
||
TEST(CalculatorTest, TestMultiply) { | ||
test_multiply(3, 2); | ||
} | ||
|
||
TEST(CalculatorTest, TestDivide) { | ||
test_divide(6, 2); | ||
} | ||
|
||
TEST(CalculatorTest, TestFactorGame) { | ||
test_factor_game(6, 2); | ||
} | ||
|
||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
|
||
// Check for file input | ||
if (argc > 1) { | ||
std::ifstream inputFile(argv[1]); | ||
if (!inputFile.is_open()) { | ||
std::cerr << "Failed to open input file: " << argv[1] << "\n"; | ||
return 1; | ||
} | ||
|
||
int a, b; | ||
|
||
// Assume the input file contains our two variables | ||
inputFile >> a >> b; | ||
|
||
test_add(a, b); | ||
test_subtract(a, b); | ||
test_multiply(a, b); | ||
test_divide(a, b); | ||
test_factor_game(a, b); | ||
|
||
// Skip running the default tests since we're using file input | ||
return 0; | ||
} | ||
|
||
// If no file input is provided, run standard test fixtures | ||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0 +0 5 � |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1 2 |