-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTestTransaction.py
98 lines (74 loc) · 3.44 KB
/
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
"""
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
""" Define test testTransaction class by extending the unittest.TestCase class"""
class TestTransaction(unittest.TestCase):
DEPOSIT = 2000 # Expected Deposit amount
WITHDRAWL = 500 # Expected Withdrawl amount
FIRST = 103 # Expected first transaction number
TYPE = "deposit" # Expected Deposit transaction type
# The setup method creates three transactions
def setUp(self):
self.transaction1 = Transaction("deposit", TestTransaction.DEPOSIT)
self.transaction2 = Transaction("withdrawl", TestTransaction.WITHDRAWL)
self.transaction3 = Transaction("interest")
# 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.FIRST)
self.assertEqual(self.transaction1.getTType(), TestTransaction.TYPE)
print("The first transaction: ", self.transaction1)
print(repr(self.transaction1))
# 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")
self.assertTrue(self.transaction1 == self.transaction1)
# 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 + self.transaction1
print("\nTesting the addition special method")
self.assertEqual(addTest, 4000)
# Test the __sub__ special method
def test_sub(self):
subTest = self.transaction1 - self.transaction2
print("\nTesting the subtraction special method")
self.assertEqual(subTest, 1500)
# Test the __sum__ special method
def test_sum(self):
listTransactions = [self.transaction1, self.transaction2,
self.transaction3]
sumTest = sum(listTransactions)
print("\nTesting the sum special method %d" % sumTest)
self.assertEqual(sumTest, (TestTransaction.DEPOSIT +
TestTransaction.WITHDRAWL))
if __name__ == '__main__':
unittest.main()