|
| 1 | +#include "gtest/gtest.h" |
| 2 | +#include "quadratic-equation.hpp" |
| 3 | + |
| 4 | +using math::quadratic_equation_solution; |
| 5 | + |
| 6 | +TEST(QuadraticEquationSolutionTest, NoSolutions) { |
| 7 | + auto result = quadratic_equation_solution(1.0, 0.0, 1.0); |
| 8 | + ASSERT_TRUE(std::holds_alternative<std::monostate>(result)); |
| 9 | +} |
| 10 | + |
| 11 | +TEST(QuadraticEquationSolutionTest, OneSolution) { |
| 12 | + auto result = quadratic_equation_solution(1.0, -2.0, 1.0); // NOLINT |
| 13 | + ASSERT_TRUE(std::holds_alternative<double>(result)); |
| 14 | + const double solution = std::get<double>(result); |
| 15 | + EXPECT_DOUBLE_EQ(solution, 1.0); |
| 16 | +} |
| 17 | + |
| 18 | +TEST(QuadraticEquationSolutionTest, OneSolution2) { |
| 19 | + auto result = quadratic_equation_solution(1.0, -4.0, 4.0); // NOLINT |
| 20 | + ASSERT_TRUE(std::holds_alternative<double>(result)); |
| 21 | + const double solution = std::get<double>(result); |
| 22 | + EXPECT_DOUBLE_EQ(solution, 2.0); |
| 23 | +} |
| 24 | + |
| 25 | +TEST(QuadraticEquationSolutionTest, TwoSolutionsDistinct) { |
| 26 | + auto result = quadratic_equation_solution(1.0, -3.0, 2.0); // NOLINT |
| 27 | + ASSERT_TRUE((std::holds_alternative<std::pair<double, double>>(result))); |
| 28 | + auto solutions = std::get<std::pair<double, double>>(result); |
| 29 | + |
| 30 | + EXPECT_DOUBLE_EQ(solutions.first, 1.0); |
| 31 | + EXPECT_DOUBLE_EQ(solutions.second, 2.0); |
| 32 | +} |
| 33 | + |
| 34 | +TEST(QuadraticEquationSolutionTest, LinearEquation) { |
| 35 | + EXPECT_THROW(quadratic_equation_solution(0.0, 2.0, -4.0);, std::invalid_argument); // NOLINT |
| 36 | +} |
| 37 | + |
| 38 | +TEST(QuadraticEquationSolutionTest, ZeroCoefficientCase) { |
| 39 | + EXPECT_THROW(quadratic_equation_solution(0.0, 0.0, 1.0);, std::invalid_argument); |
| 40 | +} |
| 41 | + |
| 42 | +TEST(QuadraticEquationSolutionTest, AllZeroCoefficients) { |
| 43 | + EXPECT_THROW(quadratic_equation_solution(0.0, 0.0, 0.0);, std::invalid_argument); |
| 44 | +} |
0 commit comments