-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_simple_events.py
49 lines (31 loc) · 1.35 KB
/
test_simple_events.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
from unittest import TestCase
from unittest.mock import Mock, patch
from inferi.probability import SimpleEvent, Event, SampleSpace
class SimpleEventTest(TestCase):
def setUp(self):
self.space = Mock(SampleSpace)
class SimpleEventCreationTests(SimpleEventTest):
def test_can_create_simple_event(self):
e = SimpleEvent("H", 0.5, self.space)
self.assertIsInstance(e, Event)
self.assertEqual(e._outcome, "H")
self.assertEqual(e._name, "H")
self.assertEqual(e._probability, 0.5)
self.assertEqual(e._sample_space, self.space)
self.assertEqual(e._simple_events, set([e]))
def test_probability_must_be_numeric(self):
with self.assertRaises(TypeError):
SimpleEvent("H", "jj", self.space)
def test_probability_must_be_valid(self):
with self.assertRaises(ValueError):
SimpleEvent("H", -0.1, self.space)
with self.assertRaises(ValueError):
SimpleEvent("H", 1.1, self.space)
class SimpleEventReprTests(SimpleEventTest):
def test_simple_event_repr(self):
e = SimpleEvent("H", 0.5, self.space)
self.assertEqual(str(e), "<SimpleEvent: H>")
class SimpleEventOutcomeTests(SimpleEventTest):
def test_simple_event_outcome(self):
e = SimpleEvent("H", 0.5, self.space)
self.assertEqual(e.outcome(), e._outcome)