From 938502a74ee38db332e851e416586e25fb39b521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Cancio?= Date: Fri, 3 Oct 2025 18:54:19 +0200 Subject: [PATCH] Add doctests to chaos machine Added doctests for push and reset functions. Contributes to #9943 --- hashes/chaos_machine.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/hashes/chaos_machine.py b/hashes/chaos_machine.py index d2fde2f5e371..f7c43277116f 100644 --- a/hashes/chaos_machine.py +++ b/hashes/chaos_machine.py @@ -14,6 +14,25 @@ def push(seed): + """ + Push data into the chaos machine buffer. + + Updates the buffer space and parameters space using chaotic dynamics + based on the input seed value. + + Args: + seed: Input value to push into the chaos machine + + >>> reset() + >>> initial_time = machine_time + >>> push(12345) + >>> machine_time == initial_time + 1 + True + >>> len(buffer_space) == m + True + >>> all(0 <= x < 1 for x in buffer_space) + True + """ global buffer_space, params_space, machine_time, K, m, t # Choosing Dynamical Systems (All) @@ -73,6 +92,20 @@ def xorshift(x, y): def reset(): + """ + Reset the chaos machine to initial state. + + Resets buffer space to initial values K, clears parameters space, + and resets machine time to 0. + + >>> reset() + >>> buffer_space == K + True + >>> machine_time + 0 + >>> len(params_space) + 5 + """ global buffer_space, params_space, machine_time, K, m, t buffer_space = K