-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_weak_sync_logic.py
More file actions
95 lines (88 loc) · 2.56 KB
/
test_weak_sync_logic.py
File metadata and controls
95 lines (88 loc) · 2.56 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# test_weak_sync_logic.py
from weak_sync_logic import decide_weak_sync
def test_decide_skip_within_threshold():
d = decide_weak_sync(
diffs=[0.02, -0.01, 0.03],
threshold=0.05,
strong_threshold=1.0,
confirm_needed=3,
last_sign=0,
confirm_count=0,
)
assert d.action == "skip"
assert d.confirm_count == 0
assert d.last_sign == 0
def test_decide_strong_set_over_strong_threshold():
d = decide_weak_sync(
diffs=[1.2, 1.1, 1.3],
threshold=0.05,
strong_threshold=1.0,
confirm_needed=3,
last_sign=0,
confirm_count=0,
)
assert d.action == "strong_set"
assert d.confirm_count == 0
assert d.last_sign == 0
def test_decide_pending_then_set_after_confirm_needed():
# 1回目:新しい方向なので pending、count=1
d1 = decide_weak_sync(
diffs=[0.20, 0.18, 0.22],
threshold=0.05,
strong_threshold=1.0,
confirm_needed=3,
last_sign=0,
confirm_count=0,
)
assert d1.action == "pending"
assert d1.last_sign == 1
assert d1.confirm_count == 1
# 2回目:同方向なので pending、count=2
d2 = decide_weak_sync(
diffs=[0.21, 0.19, 0.20],
threshold=0.05,
strong_threshold=1.0,
confirm_needed=3,
last_sign=d1.last_sign,
confirm_count=d1.confirm_count,
)
assert d2.action == "pending"
assert d2.last_sign == 1
assert d2.confirm_count == 2
# 3回目:同方向で必要回数到達 → set
d3 = decide_weak_sync(
diffs=[0.22, 0.21, 0.20],
threshold=0.05,
strong_threshold=1.0,
confirm_needed=3,
last_sign=d2.last_sign,
confirm_count=d2.confirm_count,
)
assert d3.action == "set"
assert d3.confirm_count == 0
assert d3.last_sign == 0
def test_decide_resets_on_sign_flip():
# まず +方向で1回目
d1 = decide_weak_sync(
diffs=[0.2, 0.2, 0.2],
threshold=0.05,
strong_threshold=1.0,
confirm_needed=3,
last_sign=0,
confirm_count=0,
)
assert d1.action == "pending"
assert d1.last_sign == 1
assert d1.confirm_count == 1
# 次に -方向へ反転 → countは1にリセット、last_sign=-1
d2 = decide_weak_sync(
diffs=[-0.2, -0.2, -0.2],
threshold=0.05,
strong_threshold=1.0,
confirm_needed=3,
last_sign=d1.last_sign,
confirm_count=d1.confirm_count,
)
assert d2.action == "pending"
assert d2.last_sign == -1
assert d2.confirm_count == 1