-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_generative_processes.py
43 lines (35 loc) · 1.42 KB
/
test_generative_processes.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
import unittest
import random
from PDFA import EvenProcess
class TestEvenProcess(unittest.TestCase):
def setUp(self):
random.seed(1) # for reproducibility
self.process = EvenProcess()
def test_initial_state(self):
self.assertIn(self.process.current_state, ['A', 'B'])
def test_sample(self):
sample, state = self.process.sample()
self.assertIn(sample, [0, 1])
self.assertIn(state, ['A', 'B'])
def test_generate_series(self):
samples = self.process.generate_series(1000, return_states=False)
self.assertEqual(len(samples), 1000)
def test_generate_series_with_states(self):
samples_states = self.process.generate_series(1000, return_states=True)
self.assertEqual(len(samples_states), 1000)
for sample, state in samples_states:
self.assertIn(sample, [0, 1])
self.assertIn(state, ['A', 'B'])
def test_state_transition(self):
for _ in range(1000):
if self.process.current_state == 'A':
sample, state = self.process.sample()
if sample == 0:
self.assertEqual(state, 'A')
else:
self.assertEqual(state, 'B')
else:
sample, state = self.process.sample()
self.assertEqual(state, 'A') # Always transition back to 'A' from 'B'
if __name__ == '__main__':
unittest.main()