blob: 8d837c1c7818c5d8d1c7ac6ba500e7b4c8f80d12 [file] [log] [blame]
Holger Hans Peter Freyther38adaa92018-01-20 19:09:47 +00001#!/usr/bin/env python3
2
3import _prep
4
5from osmo_ms_driver import cdf
6from datetime import timedelta
7
8def print_fuzzy_compare(want, expe, len=3):
9 want_str = str(want)[0:len]
10 expe_str = str(expe)[0:len]
11 print(want_str, expe_str, want_str == expe_str)
12
13
14def check_steps(a, steps, fun):
15 print("Done", a.is_done())
16 for step in steps:
17 # Verify we can step
18
19 # Compare and step once
20 fun(a, step)
21 if a.is_done():
22 break
23 a.step_once()
24 print("Done", a.is_done())
25
26def compare_value(a, step):
27 print_fuzzy_compare(a.current_value(), step)
28
29def compare_scaled_value(a, val):
30 (step, scale) = val
31 print_fuzzy_compare(a.current_value(), step)
32 print_fuzzy_compare(a.current_scaled_value(), scale)
33
34def compare_x_value(a, val):
35 (x, step) = val
36 print(a._x, x, x == a._x)
37 print_fuzzy_compare(a.current_value(), step)
38
39def testImmediate():
40 print("Testing the immediate CDF")
41 a = cdf.immediate()
42 print("Done", a.is_done())
43 print_fuzzy_compare(a.current_value(), 1.0)
44
45
46def testLinearWithDuration():
47 print("Testing linear with duration")
48 a = cdf.linear_with_duration(timedelta(seconds=10), step_size=timedelta(seconds=2))
49 steps = [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
50 check_steps(a, steps, compare_value)
51
52 print("Testing linear with duration scaled")
53 a = cdf.linear_with_duration(timedelta(seconds=10), step_size=timedelta(seconds=2))
54 a.set_target(1000)
55 steps = [(0.0, 0.0), (0.2, 200), (0.4, 400), (0.6, 600), (0.8, 800), (1.0, 10000)]
56 check_steps(a, steps, compare_scaled_value)
57
58def testInOut():
59 print("Testing in_out")
60 print_fuzzy_compare(cdf._in_out(0.5), 0.5, 3)
61 print_fuzzy_compare(cdf._in_out(0.75), 0.875, 4)
62 print_fuzzy_compare(cdf._in_out(0.8), 0.92, 3)
63 print_fuzzy_compare(cdf._in_out(0.85), 0.955, 4)
64 print_fuzzy_compare(cdf._in_out(1.0), 1.0, 3)
65
66def testEaseInOutDuration():
67 print("Testing ease In and Out")
68 a = cdf.ease_in_out_duration(duration=timedelta(seconds=20), step_size=timedelta(seconds=5))
69 steps = [(0.0, 0.0), (5.0, 0.125), (10.0, 0.5), (15.0, 0.875), (20, 1.0)]
70 check_steps(a, steps, compare_x_value)
71
72testImmediate()
73testLinearWithDuration()
74testInOut()
75testEaseInOutDuration()