Created
July 24, 2017 01:01
-
-
Save OPhamster/00864a63993c7ce6d69290c12a9f72fc to your computer and use it in GitHub Desktop.
googletest_sample_code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "solution_code.h" | |
| #include "gtest/gtest.h" | |
| #include <climits> | |
| // ---- Tests on Input ------ | |
| // ---- Tests on 'solution_code' Function ----- | |
| // checking validity of function on negative input | |
| TEST(FunctionTest, SuccessNegative){ | |
| float a[] = {-1.0,-5.0,-2.0,-3.0}; | |
| float b[] = {-4.6,-2.1,-6.77,-4.01,-7.89,-254.24,-60.0}; | |
| EXPECT_TRUE(solution_code(a)); | |
| EXPECT_FLOAT_EQ(ce.first,-5.0); | |
| EXPECT_FLOAT_EQ(ce.second,-3.0); | |
| EXPECT_FLOAT_EQ(ce.third,-2.0); | |
| EXPECT_TRUE(solution_code(b)); | |
| EXPECT_FLOAT_EQ(ce.first,-254.24); | |
| EXPECT_FLOAT_EQ(ce.second,-60.0); | |
| EXPECT_FLOAT_EQ(ce.third,-7.89); | |
| } | |
| // checking validity of function on positive input | |
| TEST(FunctionTest, SuccessPositive){ | |
| float a[] = {1.0,5.0,2.0,3.0}; | |
| float b[] = {4.6,2.1,6.77,4.01,7.89,254.24,60.0}; | |
| EXPECT_TRUE(solution_code(a)); | |
| EXPECT_FLOAT_EQ(ce.first,1.0); | |
| EXPECT_FLOAT_EQ(ce.second,2.0); | |
| EXPECT_FLOAT_EQ(ce.third,3.0); | |
| EXPECT_TRUE(solution_code(b)); | |
| EXPECT_FLOAT_EQ(ce.first,1.6); | |
| EXPECT_FLOAT_EQ(ce.second,2.1); | |
| EXPECT_FLOAT_EQ(ce.third,4.01); | |
| } | |
| // checking validty of function on input including zero's | |
| TEST(FunctionTest, SuccessZero){ | |
| float a[] = {0.0,0.0,0.0,0.0,0.0,0.0}; | |
| float b[] = {1.0,-5.2,-3.2,0.0}; | |
| EXPECT_TRUE(solution_code(a)); | |
| EXPECT_FLOAT_EQ(ce.first,0.0); | |
| EXPECT_FLOAT_EQ(ce.second,0.0); | |
| EXPECT_FLOAT_EQ(ce.third,0.0); | |
| EXPECT_TRUE(solution_code(b)); | |
| EXPECT_FLOAT_EQ(ce.first,-3.2); | |
| EXPECT_FLOAT_EQ(ce.second,0.0); | |
| EXPECT_FLOAT_EQ(ce.third,1.0); | |
| } | |
| // validating function on non attainablity of required number of elements - Negative numbers | |
| TEST(FunctionTest, FailureNegative){ | |
| float a[] = {-1.0,-5.0}; | |
| float b[] = {-4.6}; | |
| EXPECT_FALSE(solution_code(a)); | |
| EXPECT_FALSE(solution_code(b)); | |
| } | |
| // validating function on non attainablity of required number of elements - Positive numbers | |
| TEST(FunctionTest, FailurePostitive){ | |
| float a[] = {6.0,3.0}; | |
| float b[] = {4.24,80.0}; | |
| EXPECT_FALSE(solution_code(a)); | |
| EXPECT_FALSE(solution_code(b)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment