diff options
Diffstat (limited to 'selftest/cdf_test')
l--------- | selftest/cdf_test/_prep.py | 1 | ||||
-rw-r--r-- | selftest/cdf_test/cdf_test.ok | 57 | ||||
-rwxr-xr-x | selftest/cdf_test/cdf_test.py | 75 |
3 files changed, 133 insertions, 0 deletions
diff --git a/selftest/cdf_test/_prep.py b/selftest/cdf_test/_prep.py new file mode 120000 index 0000000..9cea3fe --- /dev/null +++ b/selftest/cdf_test/_prep.py @@ -0,0 +1 @@ +../_prep.py
\ No newline at end of file diff --git a/selftest/cdf_test/cdf_test.ok b/selftest/cdf_test/cdf_test.ok new file mode 100644 index 0000000..aa753e4 --- /dev/null +++ b/selftest/cdf_test/cdf_test.ok @@ -0,0 +1,57 @@ +Testing the immediate CDF +Done True +1 1.0 False +Testing linear with duration +Done False +0.0 0.0 True +Done False +0.2 0.2 True +Done False +0.4 0.4 True +Done False +0.6 0.6 True +Done False +0.8 0.8 True +Done True +1.0 1.0 True +Testing linear with duration scaled +Done False +0.0 0.0 True +0.0 0.0 True +Done False +0.2 0.2 True +200 200 True +Done False +0.4 0.4 True +400 400 True +Done False +0.6 0.6 True +600 600 True +Done False +0.8 0.8 True +800 800 True +Done True +1.0 1.0 True +100 100 True +Testing in_out +0.5 0.5 True +0.87 0.87 True +0.9 0.9 True +0.95 0.95 True +1.0 1.0 True +Testing ease In and Out +Done False +0.0 0.0 True +0.0 0.0 True +Done False +5.0 5.0 True +0.1 0.1 True +Done False +10.0 10.0 True +0.5 0.5 True +Done False +15.0 15.0 True +0.8 0.8 True +Done True +20.0 20 True +1.0 1.0 True diff --git a/selftest/cdf_test/cdf_test.py b/selftest/cdf_test/cdf_test.py new file mode 100755 index 0000000..8d837c1 --- /dev/null +++ b/selftest/cdf_test/cdf_test.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +import _prep + +from osmo_ms_driver import cdf +from datetime import timedelta + +def print_fuzzy_compare(want, expe, len=3): + want_str = str(want)[0:len] + expe_str = str(expe)[0:len] + print(want_str, expe_str, want_str == expe_str) + + +def check_steps(a, steps, fun): + print("Done", a.is_done()) + for step in steps: + # Verify we can step + + # Compare and step once + fun(a, step) + if a.is_done(): + break + a.step_once() + print("Done", a.is_done()) + +def compare_value(a, step): + print_fuzzy_compare(a.current_value(), step) + +def compare_scaled_value(a, val): + (step, scale) = val + print_fuzzy_compare(a.current_value(), step) + print_fuzzy_compare(a.current_scaled_value(), scale) + +def compare_x_value(a, val): + (x, step) = val + print(a._x, x, x == a._x) + print_fuzzy_compare(a.current_value(), step) + +def testImmediate(): + print("Testing the immediate CDF") + a = cdf.immediate() + print("Done", a.is_done()) + print_fuzzy_compare(a.current_value(), 1.0) + + +def testLinearWithDuration(): + print("Testing linear with duration") + a = cdf.linear_with_duration(timedelta(seconds=10), step_size=timedelta(seconds=2)) + steps = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0] + check_steps(a, steps, compare_value) + + print("Testing linear with duration scaled") + a = cdf.linear_with_duration(timedelta(seconds=10), step_size=timedelta(seconds=2)) + a.set_target(1000) + steps = [(0.0, 0.0), (0.2, 200), (0.4, 400), (0.6, 600), (0.8, 800), (1.0, 10000)] + check_steps(a, steps, compare_scaled_value) + +def testInOut(): + print("Testing in_out") + print_fuzzy_compare(cdf._in_out(0.5), 0.5, 3) + print_fuzzy_compare(cdf._in_out(0.75), 0.875, 4) + print_fuzzy_compare(cdf._in_out(0.8), 0.92, 3) + print_fuzzy_compare(cdf._in_out(0.85), 0.955, 4) + print_fuzzy_compare(cdf._in_out(1.0), 1.0, 3) + +def testEaseInOutDuration(): + print("Testing ease In and Out") + a = cdf.ease_in_out_duration(duration=timedelta(seconds=20), step_size=timedelta(seconds=5)) + steps = [(0.0, 0.0), (5.0, 0.125), (10.0, 0.5), (15.0, 0.875), (20, 1.0)] + check_steps(a, steps, compare_x_value) + +testImmediate() +testLinearWithDuration() +testInOut() +testEaseInOutDuration() |