-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
137 lines (96 loc) · 5.46 KB
/
tests.py
File metadata and controls
137 lines (96 loc) · 5.46 KB
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
import unittest
from functions import *
from settings import *
# Tests for functions.py
class TestGetClanmateNames(unittest.TestCase):
# Warning: this test only checks that some names are returned, and that those contain a few known ones, doesn't check that
# all the names are returned because of the fluid nature of clan membership
def test_get_clanmate_names(self):
res = get_clanmate_names('Acorn')
# Checking against Acorn with players who don't change their rsn's
self.assertIn('Mrawr', res)
self.assertIn('Gadnuka', res)
self.assertIn('CompCake', res)
self.assertIn('MiracleEdrea', res)
class TestGetCurrentXpAll(unittest.TestCase):
def test_get_current_xp_all(self):
res = get_current_xp_all(['Andy Hunts', 'Mrawr', 'Gadnuka', 'CompCake'])
self.assertEqual(res[0][0], 'Andy Hunts')
self.assertEqual(res[2][0], 'Gadnuka')
self.assertEqual(res[3][0], 'CompCake')
# Current xp is always changing, with the exception of players with 200m in a skill, so test against known 200ms
resMrawr = res[1]
self.assertEqual(resMrawr[0], 'Mrawr')
self.assertEqual(resMrawr[INVENTION], 200000000)
self.assertEqual(resMrawr[HUNTER], 200000000)
self.assertEqual(resMrawr[MAGIC], 200000000)
self.assertEqual(resMrawr[DEFENCE], 200000000)
class TestStoreXpInFile(unittest.TestCase):
def test_store_xp_in_file(self):
pass
class TestPullXpFromFile(unittest.TestCase):
def test_pull_xp_from_file(self):
pass
class TestCalcXPGained(unittest.TestCase):
def test_same_names(self):
old = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
new = [['test1', 90, 30, 322], ['test2', 11, 43, 424], ['test3', 48, 32, 4244], ['test4', 120, 40, 111]]
res = calc_xp_gained(old, new)
expected = [['test1', 0, 0, 298], ['test2', 0, 0, 423], ['test3', 0, 0, 4232], ['test4', 0, 0, 100]]
self.assertEqual(res, expected)
def test_changed_name(self):
old = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
new = [['test5', 90, 30, 322], ['test2', 11, 43, 424], ['test3', 48, 32, 4244], ['test4', 120, 40, 111]]
res = calc_xp_gained(old, new)
expected = [['test2', 0, 0, 423], ['test3', 0, 0, 4232], ['test4', 0, 0, 100]]
self.assertEqual(res, expected)
def test_user_went_inactive(self):
old = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
new = [['test2', 11, 43, 424], ['test3', 48, 32, 4244], ['test4', 120, 40, 111]]
res = calc_xp_gained(old, new)
expected = [['test2', 0, 0, 423], ['test3', 0, 0, 4232], ['test4', 0, 0, 100]]
self.assertEqual(res, expected)
def test_new_member(self):
old = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
new = [['test1', 90, 30, 24], ['test2', 11, 43, 424], ['test3', 48, 32, 4244], ['test4', 120, 40, 111], ['test5', 90, 30, 24]]
res = calc_xp_gained(old, new)
expected = [['test1', 0, 0, 0], ['test2', 0, 0, 423], ['test3', 0, 0, 4232], ['test4', 0, 0, 100]]
self.assertEqual(res, expected)
def test_order_changed(self):
old = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
new = [['test2', 11, 43, 424], ['test3', 48, 32, 4244], ['test4', 120, 40, 111], ['test1', 90, 30, 322]]
res = calc_xp_gained(old, new)
expected = [['test1', 0, 0, 298], ['test2', 0, 0, 423], ['test3', 0, 0, 4232], ['test4', 0, 0, 100]]
self.assertEqual(res, expected)
class TestCalcCompGains(unittest.TestCase):
def test_one_skill(self):
gains = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
skills = [ATTACK]
res = calc_comp_gains(gains, skills)
expected = [['test1', 30], ['test2', 43], ['test3', 32], ['test4', 40]]
def test_two_skills(self):
gains = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
skills = [ATTACK, DEFENCE]
res = calc_comp_gains(gains, skills)
expected = [['test1', 54], ['test2', 44], ['test3', 44], ['test4', 51]]
def test_three_skills(self):
gains = [['test1', 90, 30, 24], ['test2', 11, 43, 1], ['test3', 48, 32, 12], ['test4', 120, 40, 11]]
skills = [OVERALL, ATTACK, DEFENCE]
res = calc_comp_gains(gains, skills)
expected = [['test1', 144], ['test2', 55], ['test3', 92], ['test4', 171]]
class TestFilterNoXpGained(unittest.TestCase):
def test_one_with_none(self):
res = filter_no_xp_gained([['CompCake', 0]])
self.assertEqual(res, [])
def test_one_with_xp(self):
res = filter_no_xp_gained([['Andy Hunts', 780334]])
self.assertEqual(res, [['Andy Hunts', 780334]])
def test_mult_with_one_none(self):
res = filter_no_xp_gained([['Andy Hunts', 780334], ['Gadnuka', 93022], ['CompCake', 0]])
self.assertEqual(res, [['Andy Hunts', 780334], ['Gadnuka', 93022]])
def test_mult_with_none_none(self):
res = filter_no_xp_gained([['Andy Hunts', 780334], ['Gadnuka', 93022], ['CompCake', 900]])
self.assertEqual(res, [['Andy Hunts', 780334], ['Gadnuka', 93022], ['CompCake', 900]])
# Tests for run_cmd.py
if __name__ == '__main__':
unittest.main()