GCC Code Coverage Report


Directory: src/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 41 / 0 / 41
Functions: 100.0% 18 / 0 / 18
Branches: 18.2% 14 / 0 / 77

tests/calculator/calculator_test.cpp
Line Branch Exec Source
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
6 using namespace Coruh::Calculator;
7
8 class CalculatorTest : public ::testing::Test {
9 protected:
10 5 void SetUp() override {
11 // Setup test data
12 5 }
13
14 5 void TearDown() override {
15 // Clean up test data
16 5 }
17 };
18
19 4 TEST_F(CalculatorTest, TestAdd) {
20 1 double result = Calculator::add(5.0, 3.0);
21
2/10
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 23 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 13 taken 1 time.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 20 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 17 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 15 not taken.
1 EXPECT_DOUBLE_EQ(result, 8.0);
22 1 }
23
24 4 TEST_F(CalculatorTest, TestSubtract) {
25 1 double result = Calculator::subtract(5.0, 3.0);
26
2/10
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 23 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 13 taken 1 time.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 20 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 17 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 15 not taken.
1 EXPECT_DOUBLE_EQ(result, 2.0);
27 1 }
28
29 4 TEST_F(CalculatorTest, TestMultiply) {
30 1 double result = Calculator::multiply(5.0, 3.0);
31
2/10
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 23 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 13 taken 1 time.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 20 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 17 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 15 not taken.
1 EXPECT_DOUBLE_EQ(result, 15.0);
32 1 }
33
34 4 TEST_F(CalculatorTest, TestDivide) {
35 1 double result = Calculator::divide(6.0, 3.0);
36
2/10
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 23 not taken.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 13 taken 1 time.
✗ Branch 6 → 7 not taken.
✗ Branch 6 → 20 not taken.
✗ Branch 8 → 9 not taken.
✗ Branch 8 → 17 not taken.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 15 not taken.
1 EXPECT_DOUBLE_EQ(result, 2.0);
37 1 }
38
39 4 TEST_F(CalculatorTest, TestDivideByZero) {
40
6/37
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 11 not taken.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 20 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 8 not taken.
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 20 taken 1 time.
✗ Branch 8 → 9 not taken.
✓ Branch 8 → 18 taken 1 time.
✗ Branch 9 → 10 not taken.
✗ Branch 9 → 51 not taken.
✗ Branch 11 → 12 not taken.
✗ Branch 11 → 50 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 47 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 45 not taken.
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 23 not taken.
✗ Branch 20 → 34 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 41 not taken.
✗ Branch 25 → 26 not taken.
✗ Branch 25 → 40 not taken.
✗ Branch 26 → 27 not taken.
✗ Branch 26 → 38 not taken.
✗ Branch 28 → 29 not taken.
✗ Branch 28 → 41 not taken.
✗ Branch 30 → 31 not taken.
✗ Branch 30 → 41 not taken.
✗ Branch 31 → 32 not taken.
✗ Branch 31 → 41 not taken.
✗ Branch 35 → 36 not taken.
✗ Branch 35 → 43 not taken.
✗ Branch 37 → 11 not taken.
✗ Branch 37 → 51 not taken.
1 EXPECT_THROW(Calculator::divide(5.0, 0.0), std::invalid_argument);
41 1 }
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 */
50 39 int main(int argc, char** argv) {
51 #ifdef ENABLE_CALCULATOR_TEST
52 39 ::testing::InitGoogleTest(&argc, argv);
53 39 return RUN_ALL_TESTS();
54 #else
55 return 0;
56 #endif
57 }
58