-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_web_predictor.py
54 lines (42 loc) · 1.89 KB
/
test_web_predictor.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
import unittest
from web_predictor import WebPredictor
from IPython import embed
class TestGetWebPredictions(unittest.TestCase):
"""Basic tests for getting web predictions"""
def setUp(self):
self.predictor = WebPredictor()
self.player1 = "MC"
self.player2 = "Vortix"
self.player_non_unique = "HerO"
self.best_of = 5
def test_basic_getting(self):
"""Tests the chance of MC winning over Vortix"""
site = self.predictor._get_page(self.player1,
self.player2,
self.best_of)
self.assertIsNotNone(site)
self.assertNotEqual(site.html(), "")
def test_result_parsing(self):
"""Tests result page parsing"""
site = self.predictor._get_page(self.player1,
self.player2,
self.best_of)
result = self.predictor._parse_result(site)
num_wins = self.best_of / 2 + 1
self.assertEqual(len(result[0]), num_wins)
self.assertEqual(len(result[1]), num_wins)
self.assertAlmostEqual(sum(result[0]) + sum(result[1]), 100, 1)
def test_result_getter(self):
"""Tests the public getter method."""
prediction = self.predictor.get_predictions(self.player1,
self.player2, self.best_of)
self.assertEqual(len(prediction), 2)
self.assertTrue(self.player1 in prediction)
self.assertTrue(self.player2 in prediction)
self.assertAlmostEqual(sum(prediction.values()), 1, 2)
def test_non_unique_nick(self):
"""Tests getting prediction for non-unique nicknames"""
prediction = self.predictor.get_predictions(self.player1,
self.player_non_unique, self.best_of)
if __name__ == "__main__":
unittest.main()