-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoneyTest.cpp
54 lines (40 loc) · 1.29 KB
/
MoneyTest.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
#include <cppunit/config/SourcePrefix.h>
#include "Money.h"
#include "MoneyTest.h"
CPPUNIT_TEST_SUITE_REGISTRATION( MoneyTest );
void MoneyTest::setUp() {}
void MoneyTest::tearDown() {}
void MoneyTest::testConstructor()
{
const std::string currencyFF( "FF" );
const double longNumber = 1234.5678;
Money money( longNumber, currencyFF );
CPPUNIT_ASSERT_EQUAL( longNumber, money.getAmount() );
CPPUNIT_ASSERT_EQUAL( currencyFF, money.getCurrency() );
}
void MoneyTest::testEqual()
{
const Money money123FF( 123, "FF" );
const Money money123USD( 123, "USD" );
const Money money12FF( 12, "FF" );
const Money money12USD( 12, "USD" );
CPPUNIT_ASSERT( money123FF == money123FF );
CPPUNIT_ASSERT( money12FF != money123FF );
CPPUNIT_ASSERT( money123USD != money123FF );
CPPUNIT_ASSERT( money12USD != money123FF );
}
void MoneyTest::testAdd()
{
const Money money12FF( 12, "FF" );
const Money expectedMoney( 135, "FF" );
Money money( 123, "FF" );
money += money12FF;
CPPUNIT_ASSERT_EQUAL( expectedMoney, money );
CPPUNIT_ASSERT( &money == &(money += money12FF) );
}
void MoneyTest::testAddThrow()
{
const Money money123FF( 123, "FF" );
Money money( 123, "USD" );
CPPUNIT_ASSERT_THROW( money += money123FF, IncompatibleMoneyError );
}