| | 0 | 1 | | //#define ENABLE_CALCULATOR_TEST // Uncomment this line to enable the Calculator tests |
| | | 2 | | |
| | | 3 | | #include "gtest/gtest.h" |
| | | 4 | | #include "../../calculator/header/calculator.h" // Adjust this include path based on your project structure |
| | | 5 | | |
| | 0 | 6 | | using namespace Coruh::Calculator; |
| | | 7 | | |
| | 0 | 8 | | class CalculatorTest : public ::testing::Test { |
| | | 9 | | protected: |
| | 0 | 10 | | void SetUp() override { |
| | | 11 | | // Setup test data |
| | | 12 | | } |
| | | 13 | | |
| | 0 | 14 | | void TearDown() override { |
| | | 15 | | // Clean up test data |
| | | 16 | | } |
| | | 17 | | }; |
| | | 18 | | |
| | 0 | 19 | | TEST_F(CalculatorTest, TestAdd) { |
| | | 20 | | double result = Calculator::add(5.0, 3.0); |
| | | 21 | | EXPECT_DOUBLE_EQ(result, 8.0); |
| | | 22 | | } |
| | | 23 | | |
| | 0 | 24 | | TEST_F(CalculatorTest, TestSubtract) { |
| | | 25 | | double result = Calculator::subtract(5.0, 3.0); |
| | | 26 | | EXPECT_DOUBLE_EQ(result, 2.0); |
| | | 27 | | } |
| | | 28 | | |
| | 0 | 29 | | TEST_F(CalculatorTest, TestMultiply) { |
| | | 30 | | double result = Calculator::multiply(5.0, 3.0); |
| | | 31 | | EXPECT_DOUBLE_EQ(result, 15.0); |
| | | 32 | | } |
| | | 33 | | |
| | 0 | 34 | | TEST_F(CalculatorTest, TestDivide) { |
| | | 35 | | double result = Calculator::divide(6.0, 3.0); |
| | | 36 | | EXPECT_DOUBLE_EQ(result, 2.0); |
| | | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | TEST_F(CalculatorTest, TestDivideByZero) { |
| | | 40 | | EXPECT_THROW(Calculator::divide(5.0, 0.0), std::invalid_argument); |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | /** |
| | | 44 | | * @brief The main function of the test program. |
| | | 45 | | * |
| | | 46 | | * @param argc The number of command-line arguments. |
| | | 47 | | * @param argv An array of command-line argument strings. |
| | | 48 | | * @return int The exit status of the program. |
| | | 49 | | */ |
| | 1 | 50 | | int main(int argc, char** argv) { |
| | | 51 | | #ifdef ENABLE_CALCULATOR_TEST |
| | | 52 | | ::testing::InitGoogleTest(&argc, argv); |
| | | 53 | | return RUN_ALL_TESTS(); |
| | | 54 | | #else |
| | | 55 | | return 0; |
| | | 56 | | #endif |
| | | 57 | | } |