-
Notifications
You must be signed in to change notification settings - Fork 0
/
testRunner.cpp
97 lines (79 loc) · 1.89 KB
/
testRunner.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
95
96
97
#include<iostream>
#include<gtest/gtest.h>
#include "libraryCode.h"
TEST(AccountTest, TestEmptyAccount)
{
Account account;
double balance = account.getBalance();
ASSERT_EQ(0, balance);
}
class AccountTestFixture : public ::testing::Test
{
public:
AccountTestFixture();
virtual ~AccountTestFixture();
void SetUp() override;
void TearDown() override;
static void SetUpTestCase();
static void TearDownTestCase();
protected:
Account* account;
};
AccountTestFixture::AccountTestFixture()
{
std::cout << "AccountTestFixture Constructor" << std::endl;
}
AccountTestFixture::~AccountTestFixture()
{
std::cout << "AccountTestFixture Destructor" << std::endl;
}
void AccountTestFixture::SetUp()
{
std::cout << "SetUp called" << std::endl;
account = new Account();
account->deposit(10.5);
}
void AccountTestFixture::TearDown()
{
std::cout << "TearDown called" << std::endl;
delete account;
account = nullptr;
}
void AccountTestFixture::SetUpTestCase()
{
std::cout << "SetUpTestCase called" << std::endl;
}
void AccountTestFixture::TearDownTestCase()
{
std::cout << "TearDownTestCase called" << std::endl;
}
TEST_F(AccountTestFixture, TestDeposit)
{
ASSERT_EQ(10.5, account->getBalance());
}
TEST_F(AccountTestFixture, TestWithdraw)
{
account->withdraw(3);
ASSERT_EQ(7.5, account->getBalance());
}
TEST_F(AccountTestFixture, TestWithdrawInsufficientFunds)
{
ASSERT_THROW(account->withdraw(300), std::runtime_error);
}
TEST_F(AccountTestFixture, TestTransferOK)
{
Account to;
account->transfer(to, 2);
ASSERT_EQ(8.5, account->getBalance());
ASSERT_EQ(2, to.getBalance());
}
TEST_F(AccountTestFixture, TestTransferInsufficientFunds)
{
Account to;
ASSERT_THROW(account->transfer(to, 200), std::runtime_error);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}