Skip to content

Instantly share code, notes, and snippets.

@OPhamster
Last active July 30, 2017 14:05
Show Gist options
  • Select an option

  • Save OPhamster/b7b68092eec8b1d37bfff8f3296d7633 to your computer and use it in GitHub Desktop.

Select an option

Save OPhamster/b7b68092eec8b1d37bfff8f3296d7633 to your computer and use it in GitHub Desktop.
Code to test check_positive.cpp
#include "check_positive.h"
#include "gtest/gtest.h"
// Test to see if this function succeeds with positive integers
// TEST is a macro to define and name a test function - and they do not return values
// You can include and C++ code here along with GoogleTest assertions that you want to make
// --- Signature ---- //
// TEST(test_case_name,test_name){
// test body
// }
// --- Signature End ---- //
// The first test we make is for positive integers where this function should return a bool true
TEST(FunctionTest,PositiveInt){
// here we pass values to the function and test for what we EXPECT (non-fatal test)
// or ASSERT (fatal) values
ASSERT_TRUE(check_if_positive(1));
ASSERT_TRUE(check_if_positive(450));
ASSERT_TRUE(check_if_positive(521));
}
// The second test we make is for zero where this function should return a bool false
TEST(FunctionTest,Zero){
// here we pass values to the function and test for what we EXPECT (non-fatal test)
// or ASSERT (fatal) values
ASSERT_FALSE(check_if_positive(0));
}
// The third test we make is for zero where this function should return a bool false
TEST(FunctionTest,NegativeInt){
// here we pass values to the function and test for what we EXPECT (non-fatal test)
// or ASSERT (fatal) values
ASSERT_FALSE(check_if_positive(-1));
ASSERT_FALSE(check_if_positive(-951));
ASSERT_FALSE(check_if_positive(-51));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment