sample.cpp
Go to the documentation of this file.
1 // tests.cpp
2 #include <gtest/gtest.h>
3 #include <math.h>
4 
5 double squareRoot(const double a)
6 {
7  double b = sqrt(a);
8  if (b != b) // nan check
9  {
10  return -1.0;
11  }
12  else
13  {
14  return sqrt(a);
15  }
16 }
17 
18 TEST(SquareRootTest, PositiveNos)
19 {
20  ASSERT_EQ(6, squareRoot(36.0));
21  ASSERT_EQ(18.0, squareRoot(324.0));
22  ASSERT_EQ(25.4, squareRoot(645.16));
23  ASSERT_EQ(0, squareRoot(0.0));
24 }
25 
26 TEST(SquareRootTest, NegativeNos)
27 {
28  ASSERT_EQ(-1.0, squareRoot(-15.0));
29  ASSERT_EQ(-1.0, squareRoot(-0.2));
30 }
31 
32 int main(int argc, char **argv)
33 {
34  testing::InitGoogleTest(&argc, argv);
35  return RUN_ALL_TESTS();
36 }
double squareRoot(const double a)
Definition: sample.cpp:5
TEST(SquareRootTest, PositiveNos)
Definition: sample.cpp:18
int main(int argc, char **argv)
Definition: sample.cpp:32


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25