-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestCustomer.cpp
94 lines (77 loc) · 2.65 KB
/
testCustomer.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// HW10: Test Suite for the Customer Class
// Peter Hurford and Bryan Fowler
#include <gtest/gtest.h>
#include "./Customer.h"
#include <iostream>
#include <string>
using namespace std;
// ----------------------- Test Constructor ----------------------- //
TEST(CustomerTest,EmptyConstructor){ //test empty constructor
Customer r;
EXPECT_EQ(0.0,r.time());
EXPECT_EQ("",r.label());
}
TEST(CustomerTest,Constructor){ //test constructor
Customer r(5.2, "First"); //create customer event
EXPECT_EQ(5.2,r.time());
EXPECT_EQ("First",r.label());
Customer r1(1.8, "Second"); //create customer event
EXPECT_EQ(1.8,r1.time());
EXPECT_EQ("Second",r1.label());
}
TEST(CustomerTest,PartConstructor){ //test constructor with only time argument
Customer r(1.3);
EXPECT_EQ(1.3,r.time());
EXPECT_EQ("",r.label());
}
// ---------------------------------------------------------------- //
// -------------------------- Test str ---------------------------- //
TEST(CustomerTest,Str){ //test str() function
Customer a(3.0, "First");
string s("<Customer First: 3>");
EXPECT_EQ(s,a.str());
}
TEST(CustomerTest,EmptyStr){ //test str() function for empty constructor
Customer a;
string s("<Customer : 0>");
EXPECT_EQ(s,a.str());
}
// ---------------------------------------------------------------- //
// -------------------------- Test time ---------------------------- //
TEST(CustomerTest,EmptyTime){ //test time() function for empty constructor
Customer a;
EXPECT_EQ(a.time(),0);
}
TEST(CustomerTest,Time){ //test time() function
Customer a(4.3);
EXPECT_EQ(a.time(),4.3);
}
// ---------------------------------------------------------------- //
// -------------------------- Test label ---------------------------- //
TEST(CustomerTest,EmptyLabel){ //test label() function for empty constructor
Customer a;
EXPECT_EQ(a.label(),"");
}
TEST(CustomerTest,Label){ //test label() function
Customer a(4.3, "First");
EXPECT_EQ(a.label(),"First");
}
// ---------------------------------------------------------------- //
// -------------------------- Test settime ---------------------------- //
TEST(CustomerTest,EmptySetTime){ //test setTime() for empty constructor
Customer r;
r.setTime(-2.0); //set time
EXPECT_EQ(-2,r.time());
EXPECT_EQ("",r.label());
}
TEST(CustomerTest,SetTime1){ //test setTime()
Customer r(4.5);
r.setTime(2); //set time
EXPECT_EQ(2,r.time());
EXPECT_EQ("",r.label());
}
// ---------------------------------------------------------------- //
int main(int argc, char **argv){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}