Skip to content

Commit 938502a

Browse files
committed
Add doctests to chaos machine
Added doctests for push and reset functions. Contributes to #9943
1 parent a71618f commit 938502a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

hashes/chaos_machine.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,25 @@
1414

1515

1616
def push(seed):
17+
"""
18+
Push data into the chaos machine buffer.
19+
20+
Updates the buffer space and parameters space using chaotic dynamics
21+
based on the input seed value.
22+
23+
Args:
24+
seed: Input value to push into the chaos machine
25+
26+
>>> reset()
27+
>>> initial_time = machine_time
28+
>>> push(12345)
29+
>>> machine_time == initial_time + 1
30+
True
31+
>>> len(buffer_space) == m
32+
True
33+
>>> all(0 <= x < 1 for x in buffer_space)
34+
True
35+
"""
1736
global buffer_space, params_space, machine_time, K, m, t
1837

1938
# Choosing Dynamical Systems (All)
@@ -73,6 +92,20 @@ def xorshift(x, y):
7392

7493

7594
def reset():
95+
"""
96+
Reset the chaos machine to initial state.
97+
98+
Resets buffer space to initial values K, clears parameters space,
99+
and resets machine time to 0.
100+
101+
>>> reset()
102+
>>> buffer_space == K
103+
True
104+
>>> machine_time
105+
0
106+
>>> len(params_space)
107+
5
108+
"""
76109
global buffer_space, params_space, machine_time, K, m, t
77110

78111
buffer_space = K

0 commit comments

Comments
 (0)