Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22f6790
commit 261abd8
Showing
5 changed files
with
78 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,49 @@ | ||
from unittest import TestCase | ||
from unittest.mock import Mock, patch | ||
from inferi.probability import SimpleEvent, Event | ||
from inferi.probability import SimpleEvent, Event, SampleSpace | ||
|
||
class SimpleEventCreationTests(TestCase): | ||
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) | ||
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") | ||
SimpleEvent("H", "jj", self.space) | ||
|
||
|
||
def test_probability_must_be_valid(self): | ||
with self.assertRaises(ValueError): | ||
SimpleEvent("H", -0.1) | ||
SimpleEvent("H", -0.1, self.space) | ||
with self.assertRaises(ValueError): | ||
SimpleEvent("H", 1.1) | ||
SimpleEvent("H", 1.1, self.space) | ||
|
||
|
||
|
||
class SimpleEventReprTests(TestCase): | ||
class SimpleEventReprTests(SimpleEventTest): | ||
|
||
def test_simple_event_repr(self): | ||
e = SimpleEvent("H", 0.5) | ||
e = SimpleEvent("H", 0.5, self.space) | ||
self.assertEqual(str(e), "<SimpleEvent: H>") | ||
|
||
|
||
|
||
class SimpleEventOutcomeTests(TestCase): | ||
class SimpleEventOutcomeTests(SimpleEventTest): | ||
|
||
def test_simple_event_outcome(self): | ||
e = SimpleEvent("H", 0.5) | ||
e = SimpleEvent("H", 0.5, self.space) | ||
self.assertEqual(e.outcome(), e._outcome) |