Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include "quadraticEquation.hpp"
  2. #include "gtest/gtest.h"
  3.  
  4. // #define f(a,b,c) std::pair<unsgined, std::pair<float,float>>(a, std::pair<float,float>(b, c))
  5. // https://github.com/google/googletest/blob/master/googletest/docs/advanced.md <- here you can find how to properly handle floating point numbers in EXPECTs and ASSERTs
  6.  
  7. class QuadraticEquationTest : public ::testing::Test
  8. {
  9.     protected:
  10.     QuadraticEquationTest() {};
  11.     ~QuadraticEquationTest() override {};
  12.  
  13.     void SetUp() override {};
  14.     void TearDown() override {};
  15. };
  16.  
  17. TEST_F(QuadraticEquationTest, FirstOfTwoZeroes)
  18. {
  19.     auto x = utils::quadraticEquation(1, 3, 2);
  20.     ASSERT_FLOAT_EQ(-2, x.second.first);
  21. }
  22.  
  23. TEST_F(QuadraticEquationTest, SecondOfTwoZeroes)
  24. {
  25.     auto x = utils::quadraticEquation(1, 3, 2);
  26.     ASSERT_FLOAT_EQ(-1, x.second.second);
  27. }
  28.  
  29. TEST_F(QuadraticEquationTest, DeltaLTZero)
  30. {
  31.     auto x = utils::quadraticEquation(15, 10, 2);
  32.     ASSERT_EQ(0u, x.first);
  33. }
  34.  
  35. TEST_F(QuadraticEquationTest, DeltaEQZero)
  36. {
  37.     auto x = utils::quadraticEquation(1, 2, 1);
  38.     ASSERT_EQ(1u, x.first);
  39. }
  40.  
  41. TEST_F(QuadraticEquationTest, WhenZeroesNeedBigPrecisionAndNeedDeltaFirstArgument)
  42. {
  43.     auto x = utils::quadraticEquation(12, 7, -15);
  44.     EXPECT_NEAR(-1.4471, x.second.first, 0.0001);
  45. }
  46.  
  47. TEST_F(QuadraticEquationTest, WhenZeroesNeedBigPrecisionAndNeedDeltaSecondArgument)
  48. {
  49.     auto x = utils::quadraticEquation(12, 7, -15);
  50.     ASSERT_NEAR(0.86379, x.second.second, 0.0001);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement