|
|
|
|
@ -71,3 +71,36 @@ def test_compute_flip_direction_insufficient_data(): |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assert compute_flip_direction(1, party_scores) is False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_auto_flip_computation_for_all_components(): |
|
|
|
|
"""Test that flip directions are computed correctly for all components.""" |
|
|
|
|
from analysis.svd_labels import compute_flip_direction |
|
|
|
|
|
|
|
|
|
# Simulate party scores for 10 components |
|
|
|
|
# Right parties should have positive scores on component 1 (EU-integratie) |
|
|
|
|
# Left parties should have negative scores on component 1 |
|
|
|
|
party_scores = { |
|
|
|
|
"VVD": [0.5] * 10, # Right party, positive on all components |
|
|
|
|
"PVV": [0.8] * 10, # Right party |
|
|
|
|
"SP": [-0.6] * 10, # Left party, negative on all components |
|
|
|
|
"DENK": [-0.4] * 10, # Left party |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# For all components, right_mean > left_mean, so flip should be False |
|
|
|
|
for comp in range(1, 11): |
|
|
|
|
flip = compute_flip_direction(comp, party_scores) |
|
|
|
|
assert flip is False, f"Component {comp} should not flip" |
|
|
|
|
|
|
|
|
|
# Now test with right parties on left (negative scores) |
|
|
|
|
party_scores_left = { |
|
|
|
|
"VVD": [-0.5] * 10, |
|
|
|
|
"PVV": [-0.8] * 10, |
|
|
|
|
"SP": [0.6] * 10, |
|
|
|
|
"DENK": [0.4] * 10, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# For all components, right_mean < left_mean, so flip should be True |
|
|
|
|
for comp in range(1, 11): |
|
|
|
|
flip = compute_flip_direction(comp, party_scores_left) |
|
|
|
|
assert flip is True, f"Component {comp} should flip" |
|
|
|
|
|