-
Notifications
You must be signed in to change notification settings - Fork 1
/
FINAL** TestTransaction.py
146 lines (107 loc) · 4.89 KB
/
FINAL** TestTransaction.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""
Simple Unit Test Example using Python's unittest module and assertions
@author: John McManus
@date: March 19, 2021
Import the unittest module and the Transaction module
Test each method with at least one unit test
"""
import unittest
from Transaction import Transaction
import copy
import datetime
""" Define test testTransaction class by extending the unittest.TestCase class"""
class TestTransaction(unittest.TestCase):
DEPOSIT = 2000 # Expected Deposit amount
WITHDRAWL = 500 # Expected Withdrawl amount
TRANSNUM = 102 # expected transaction number
TYPE = "deposit"
# The setup method creates three transactions
def setUp(self):
self.transaction1 = Transaction("deposit", TestTransaction.DEPOSIT,"")
self.transaction2 = Transaction("deposit", TestTransaction.DEPOSIT,"")
# The test_constructor method tests the constructor
def test_constructor(self):
print("\nTesting the constructor")
self.assertEqual(self.transaction1.getAmount(), TestTransaction.DEPOSIT)
self.assertEqual(self.transaction1.getTNumber(), TestTransaction.TRANSNUM)
self.assertEqual(self.transaction1.getTType(), TestTransaction.TYPE)
print("\nThe first transaction: ", self.transaction1.__str__())
print("\nThe second transaction: ", self.transaction2.__str__())
# The test_constructor method tests the constructor when called without parameters
def test_constructorNoParameters(self):
print("\nTesting the constructor with no parameters")
print("Enter 1 - deposit for the type")
print("Enter 2000 for the amount")
# create a new transaction
test = Transaction()
# test to check the new transaction's ampint and transaction type
self.assertEqual(test.getAmount(), TestTransaction.DEPOSIT)
self.assertEqual(test.getTType(), TestTransaction.TYPE)
# Test the __eq__ special method
def test_eq(self):
print("\nTesting the equal special method")
copyTrans = copy.deepcopy(self.transaction1)
self.assertTrue(self.transaction1, copy)
# Second test of the __eq__ special method
def test_eq_2(self):
print("\nSecond test of the equal special method")
self.assertFalse(self.transaction1 == self.transaction2)
# Test the __ne__ special method
def test_ne(self):
print("\nTesting the not equal special method ")
self.assertTrue(self.transaction1 != self.transaction2)
# Second test of the __ne__ special method
def test_ne_2(self):
print("\nSecond test of the not equal special method")
self.assertFalse(self.transaction1 != self.transaction1)
# Test the __add__ special method
def test_add(self):
addTest = self.transaction1.__add__(self.transaction2)
print("\nTesting the addition special method")
self.assertEqual(addTest, 4000)
# Test the __sub__ special method
def test_sub(self):
subTest = self.transaction1 - self.transaction2
subActual = self.transaction1.__sub__(self.transaction2)
print("\nTesting the subtraction special method")
self.assertEqual(subTest, subActual)
# test the __radd__ special method
def test_rAdd(self):
trans3 = Transaction(2,300,"")
transactions = [self.transaction2, trans3]
totalSum = self.transaction1.getAmount() + self.transaction2.getAmount() + trans3.getAmount()
actualSum = self.transaction1.__radd__(transactions)
print("\nTesting summing mulitple special method")
self.assertEqual(totalSum,actualSum)
# Test the __sum__ special method
def test_sum(self):
listTransactions = [self.transaction1.getAmount(), self.transaction2.getAmount()]
sumTest = sum(listTransactions)
print("\nTesting the sum special method")
self.assertEqual(sumTest, (TestTransaction.DEPOSIT +TestTransaction.DEPOSIT))
# Test the getAmount method
def test_getAmount(self):
expected = 2000
actual = self.transaction1.getAmount()
print("\nTesting the get amount method")
self.assertEqual(expected, actual)
# Test the getttype method
def test_getTtype(self):
expected = "deposit"
actual = self.transaction1.getTType()
print("\nTesting the get transaction type method")
self.assertEqual(expected,actual)
# Test the getDate method
def test_getDate(self):
expected = str(datetime.date.today())
actual = self.transaction2.getDate()
print("\nTesting get date method")
self.assertEqual(expected,actual)
# Test the transaction number get method
def test_getTnum(self):
expected = 115
actual = self.transaction1.getTNumber()
print("\nTesting get transaction number method")
self.assertEqual(expected, actual)
if __name__ == '__main__':
unittest.main()