-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·116 lines (89 loc) · 3.69 KB
/
test.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
from ortools.sat.python import cp_model
from utils import *
import shutil
def test_conditions(rows, matches):
for the_match in matches:
match_date = the_match["Date"]
home_team = the_match["Home"]
away_team = the_match["Away"]
home_row = get_row_for_team(rows, home_team)
away_row = get_row_for_team(rows, away_team)
# print (the_match)
assert home_row[match_date] != "No Home"
assert home_row[match_date] != "No Play"
assert home_row[match_date] != "Off Request"
assert away_row[match_date] != "No Play"
assert away_row[match_date] != "Off Request"
def test_no_ground_conflicts(rows, matches):
for the_match in matches:
fixture_ground = the_match["Ground"]
fixture_date = the_match["Date"]
for a_match in matches:
if the_match == a_match:
continue
if fixture_date == a_match["Date"]:
if fixture_ground == a_match["Ground"]:
pass
# print (the_match)
# print (a_match)
# print (a_match)
assert fixture_ground != a_match["Ground"]
def test_correct_ground(rows, matches):
for the_match in matches:
fixture_ground = the_match["Ground"]
fixture_home = the_match["Home"]
home_row = get_row_for_team(rows, fixture_home)
if fixture_ground not in [home_row["Ground"]] + [x.strip() for x in home_row["Alternative Grounds"].split(",")]:
# print (the_match)
# print (home_row)
# print (fixture_ground)
assert False
def test_no_dates_conflicts(rows, matches):
for the_match in matches:
fixture_ground = the_match["Ground"]
fixture_home = the_match["Home"]
fixture_opposition = the_match["Away"]
fixture_date = the_match["Date"]
for a_match in matches:
if the_match == a_match:
continue
if fixture_date == a_match["Date"]:
assert fixture_home not in [a_match["Home"], a_match["Away"]]
assert fixture_opposition not in [a_match["Home"], a_match["Away"]]
def test_number_of_matches(rows, matches):
for division in get_all_divisions(rows):
for team_name in get_all_teams(rows, division):
nb_expected_one_leg_matches = len(get_all_teams(rows, division)) - 1
home_matches_count = 0
away_matches_count = 0
for a_match in matches:
if team_name == a_match["Home"]:
home_matches_count += 1
if team_name == a_match["Away"]:
away_matches_count += 1
assert nb_expected_one_leg_matches == home_matches_count
assert nb_expected_one_leg_matches == away_matches_count
def test_results(rows, matches):
# test_number_of_matches(rows, matches)
test_correct_ground(rows, matches)
test_no_dates_conflicts(rows, matches)
test_no_ground_conflicts(rows, matches)
test_conditions(rows, matches)
print("all tests done")
def test_results_indexes(rows, matches):
match_dicts = []
for match in matches:
match_dicts.append(
{"Ground": match[0], "Home": match[1], "Away": match[2], "Date": match[3]}
)
test_results(rows, match_dicts)
def main():
try:
partial_results_file = sys.argv[1]
except:
partial_results_file = "2024/results/v4/v1/play-cricket-normalised.xlsx"
rows = read_excel("2024/results/v4/v1/data-wip.xlsx", "Grounds")
matches = read_excel(partial_results_file)
test_results(rows, matches)
if __name__ == "__main__":
main()