Skip to content

Instantly share code, notes, and snippets.

@lithiumhead
Created January 31, 2018 17:13
Show Gist options
  • Save lithiumhead/3354fa059f1f51bbbae71f9366915335 to your computer and use it in GitHub Desktop.
Save lithiumhead/3354fa059f1f51bbbae71f9366915335 to your computer and use it in GitHub Desktop.
TEST() and code in same file - Test Pass
#include <iostream>
#include <math.h>
#include <gtest/gtest.h>
double squareroot (double a) {
if(a<0)
return -1;
else
return sqrt(a);
};
TEST (SquareRootTest, PositiveNos) {
EXPECT_EQ (18.0, squareroot (324.0));
EXPECT_EQ (25.4, squareroot (645.16));
EXPECT_EQ (50.332, squareroot (2533.310224));
}
TEST (SquareRootTest, ZeroAndNegativeNos) {
ASSERT_EQ (0.0, squareroot (0.0));
ASSERT_EQ (-1, squareroot (-22.0));
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment