|
| 1 | +"""Tests Win Probability module.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from awpy import Demo |
| 6 | +from awpy.stats import win_probability |
| 7 | + |
| 8 | +class TestWinProbability: |
| 9 | + """Tests the win probability calculations. |
| 10 | + |
| 11 | + https://www.hltv.org/matches/2369248/natus-vincere-vs-virtuspro-pgl-cs2-major-copenhagen-2024-europe-rmr-closed-qualifier-a |
| 12 | + """ |
| 13 | + |
| 14 | + @classmethod |
| 15 | + def setup_class(cls): |
| 16 | + """ |
| 17 | + Setup method called before any tests are run. |
| 18 | + Initializes the Demo object and random weights for testing. |
| 19 | + """ |
| 20 | + cls.demo = Demo(file='tests/natus-vincere-vs-virtus-pro-m1-overpass.dem') |
| 21 | + |
| 22 | + |
| 23 | + @classmethod |
| 24 | + def teardown_class(cls): |
| 25 | + """ |
| 26 | + Teardown method called after all tests have run. |
| 27 | + """ |
| 28 | + cls.demo = None |
| 29 | + |
| 30 | + |
| 31 | + def test_win_probability_symmetry(self): |
| 32 | + """Test to ensure P(CT Win) = 1 - P(T Win) at a given tick.""" |
| 33 | + probabilities = win_probability(self.demo, 168200) |
| 34 | + for prob in probabilities: |
| 35 | + assert prob["CT_win_probability"] == pytest.approx(1 - prob["T_win_probability"], 0.01) |
| 36 | + |
| 37 | + |
| 38 | + def test_known_ct_sided_situation(self): |
| 39 | + """Test for a known heavily CT-sided situation.""" |
| 40 | + probabilities = win_probability(self.demo, 168200) |
| 41 | + assert probabilities[0]["tick"] == 168200 |
| 42 | + assert probabilities[0]["CT_win_probability"] > 0.7 |
| 43 | + |
| 44 | + |
| 45 | + def test_prediction_count_matches_ticks(self): |
| 46 | + """Test that the number of predictions matches the number of ticks passed in.""" |
| 47 | + ticks = [166100, 167023, 168200] |
| 48 | + probabilities = win_probability(self.demo, ticks) |
| 49 | + assert len(probabilities) == len(ticks) |
0 commit comments