-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
63 lines (52 loc) · 1.24 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <gtest/gtest.h>
// Note this file doesn't have a main function as it is provided by the gtest_main library
// If you want you can add a main and call RUN_ALL_TESTS() yourself
// USE the TEST macro to define a test where the first argument is the test group
// and the second is the test name
TEST(IntEqual, equalTest)
{
EXPECT_EQ(1, 1);
}
TEST(IntEqual, notEqualTest)
{
EXPECT_NE(1, 2);
}
TEST(BoolTests, trueTest)
{
EXPECT_TRUE(true);
}
TEST(BoolTests, falseTest)
{
EXPECT_FALSE(false);
}
TEST(StringCompare, stringTest)
{
EXPECT_STREQ("Hello", "Hello");
}
TEST(StringCompare, stringTest2)
{
EXPECT_STRNE("Hello", "World");
}
// Floats must be tested differently, we can use EXPECT_FLOAT_EQ or EXPECT_DOUBLE_EQ
// This is because floating point numbers are not exact and can have rounding errors
// We can also use near for other more complex comparisons
TEST(FloatTests, floatTest)
{
EXPECT_FLOAT_EQ(1.0f, 1.0f);
}
TEST(FloatTests, doubleTest)
{
EXPECT_DOUBLE_EQ(1.0, 1.0);
}
TEST(FloatTests, nearTest)
{
EXPECT_NEAR(1.0, 1.1, 0.2);
}
TEST(FloatTests, nearTestFloat)
{
EXPECT_NEAR(1.0f, 1.1f, 0.2f);
}
TEST(Excptions, exceptionTest)
{
EXPECT_THROW(throw std::runtime_error("message"), std::runtime_error);
}