|
| 1 | +import pytest |
| 2 | + |
| 3 | +from src.teams import DuplicatePointsEntryException, InvalidPointsException, InvalidTaskException, appendTeamsData, getTeamPoints |
| 4 | + |
| 5 | + |
| 6 | +def test_simple(): |
| 7 | + teamTasks = {} |
| 8 | + appendTeamsData(1234, 'AA', 5, teamTasks) |
| 9 | + appendTeamsData(1234, 'BA', 3, teamTasks) |
| 10 | + appendTeamsData(1234, 'CD', 2, teamTasks) |
| 11 | + appendTeamsData(1234, 'EG', 1, teamTasks) |
| 12 | + appendTeamsData(1235, 'HA', 5, teamTasks) |
| 13 | + assert teamTasks == { |
| 14 | + 1234: { |
| 15 | + 'AA': 5, |
| 16 | + 'BA': 3, |
| 17 | + 'CD': 2, |
| 18 | + 'EG': 1, |
| 19 | + }, |
| 20 | + 1235: { |
| 21 | + 'HA': 5, |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + |
| 26 | +def test_duplicate_valid(): |
| 27 | + teamTasks = {} |
| 28 | + appendTeamsData(1234, 'AA', 5, teamTasks) |
| 29 | + appendTeamsData(1234, 'BA', 3, teamTasks) |
| 30 | + appendTeamsData(1234, 'CD', 2, teamTasks) |
| 31 | + appendTeamsData(1234, 'AA', 5, teamTasks) |
| 32 | + appendTeamsData(1234, 'EG', 1, teamTasks) |
| 33 | + appendTeamsData(1235, 'HA', 5, teamTasks) |
| 34 | + assert teamTasks == { |
| 35 | + 1234: { |
| 36 | + 'AA': 5, |
| 37 | + 'BA': 3, |
| 38 | + 'CD': 2, |
| 39 | + 'EG': 1, |
| 40 | + }, |
| 41 | + 1235: { |
| 42 | + 'HA': 5, |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | +def test_duplicate_invalid(): |
| 48 | + teamTasks = {} |
| 49 | + appendTeamsData(1234, 'AA', 5, teamTasks) |
| 50 | + with pytest.raises(DuplicatePointsEntryException): |
| 51 | + appendTeamsData(1234, 'AA', 3, teamTasks) |
| 52 | + |
| 53 | + |
| 54 | +def test_invalid_points(): |
| 55 | + with pytest.raises(InvalidPointsException): |
| 56 | + appendTeamsData(1234, 'AA', 4, {}) |
| 57 | + with pytest.raises(InvalidPointsException): |
| 58 | + appendTeamsData(1234, 'AA', 0, {}) |
| 59 | + with pytest.raises(InvalidPointsException): |
| 60 | + appendTeamsData(1234, 'AA', -1, {}) |
| 61 | + with pytest.raises(InvalidPointsException): |
| 62 | + appendTeamsData(1234, 'AA', 6, {}) |
| 63 | + |
| 64 | + |
| 65 | +def test_invalid_task(): |
| 66 | + with pytest.raises(InvalidTaskException): |
| 67 | + appendTeamsData(1234, 'A', 5, {}) |
| 68 | + with pytest.raises(InvalidTaskException): |
| 69 | + appendTeamsData(1234, 'AAA', 5, {}) |
| 70 | + with pytest.raises(InvalidTaskException): |
| 71 | + appendTeamsData(1234, 'AI', 5, {}) |
| 72 | + with pytest.raises(InvalidTaskException): |
| 73 | + appendTeamsData(1234, 'aa', 5, {}) |
| 74 | + with pytest.raises(InvalidTaskException): |
| 75 | + appendTeamsData(1234, 'IA', 5, {}) |
| 76 | + with pytest.raises(InvalidTaskException): |
| 77 | + appendTeamsData(1234, 'HI', 5, {}) |
| 78 | + with pytest.raises(InvalidTaskException): |
| 79 | + appendTeamsData(1234, 'IH', 5, {}) |
| 80 | + |
| 81 | + |
| 82 | +def test_points_sum(): |
| 83 | + teamTasks = { |
| 84 | + 1234: { |
| 85 | + 'AA': 5, |
| 86 | + 'BA': 3, |
| 87 | + 'BB': 3, |
| 88 | + 'EG': 1, |
| 89 | + }, |
| 90 | + 1235: { |
| 91 | + 'HA': 3, |
| 92 | + } |
| 93 | + } |
| 94 | + assert getTeamPoints(teamTasks) == { |
| 95 | + 1234: { |
| 96 | + 'sum': 12, |
| 97 | + 'counts': { |
| 98 | + 5: 1, |
| 99 | + 3: 2, |
| 100 | + 1: 1, |
| 101 | + } |
| 102 | + }, |
| 103 | + 1235: { |
| 104 | + 'sum': 3, |
| 105 | + 'counts': { |
| 106 | + 3: 1 |
| 107 | + } |
| 108 | + } |
| 109 | + } |
0 commit comments