parent
ba24ad4fe6
commit
95183fec5b
@ -0,0 +1,73 @@ |
|||||||
|
"""Tests for analysis/svd_labels module.""" |
||||||
|
|
||||||
|
|
||||||
|
def test_get_svd_label_returns_correct_label(): |
||||||
|
"""Test that get_svd_label returns the correct label for each component.""" |
||||||
|
from analysis.svd_labels import get_svd_label |
||||||
|
|
||||||
|
# Component 1 should return EU-integratie label |
||||||
|
label1 = get_svd_label(1) |
||||||
|
assert "EU-integratie" in label1 or "Nationalisme" in label1 |
||||||
|
|
||||||
|
# Component 2 should return Populistisch label |
||||||
|
label2 = get_svd_label(2) |
||||||
|
assert "Populistisch" in label2 or "Institutioneel" in label2 |
||||||
|
|
||||||
|
# Component 3 should return Verzorgingsstaat label |
||||||
|
label3 = get_svd_label(3) |
||||||
|
assert "Verzorgingsstaat" in label3 or "Marktwerking" in label3 |
||||||
|
|
||||||
|
|
||||||
|
def test_compute_flip_direction_right_on_left(): |
||||||
|
"""Test that flip is True when right parties are on the left.""" |
||||||
|
from analysis.svd_labels import compute_flip_direction |
||||||
|
|
||||||
|
# Right parties have negative scores (on left), left parties have positive |
||||||
|
party_scores = { |
||||||
|
"VVD": [-0.5, 0.0], # Right party, component 1 score = -0.5 |
||||||
|
"PVV": [-0.8, 0.0], # Right party |
||||||
|
"SP": [0.6, 0.0], # Left party, component 1 score = 0.6 |
||||||
|
"DENK": [0.4, 0.0], # Left party |
||||||
|
} |
||||||
|
|
||||||
|
# Component 1: right_mean = -0.65, left_mean = 0.5 |
||||||
|
# right_mean < left_mean, so flip = True |
||||||
|
assert compute_flip_direction(1, party_scores) is True |
||||||
|
|
||||||
|
|
||||||
|
def test_compute_flip_direction_right_on_right(): |
||||||
|
"""Test that flip is False when right parties are already on the right.""" |
||||||
|
from analysis.svd_labels import compute_flip_direction |
||||||
|
|
||||||
|
# Right parties have positive scores (on right), left parties have negative |
||||||
|
party_scores = { |
||||||
|
"VVD": [0.5, 0.0], # Right party, component 1 score = 0.5 |
||||||
|
"PVV": [0.8, 0.0], # Right party |
||||||
|
"SP": [-0.6, 0.0], # Left party |
||||||
|
"DENK": [-0.4, 0.0], # Left party |
||||||
|
} |
||||||
|
|
||||||
|
# Component 1: right_mean = 0.65, left_mean = -0.5 |
||||||
|
# right_mean > left_mean, so flip = False |
||||||
|
assert compute_flip_direction(1, party_scores) is False |
||||||
|
|
||||||
|
|
||||||
|
def test_compute_flip_direction_insufficient_data(): |
||||||
|
"""Test that flip is False when there's insufficient data.""" |
||||||
|
from analysis.svd_labels import compute_flip_direction |
||||||
|
|
||||||
|
# No right parties in data |
||||||
|
party_scores = { |
||||||
|
"SP": [0.6, 0.0], |
||||||
|
"DENK": [0.4, 0.0], |
||||||
|
} |
||||||
|
|
||||||
|
assert compute_flip_direction(1, party_scores) is False |
||||||
|
|
||||||
|
# No left parties in data |
||||||
|
party_scores = { |
||||||
|
"VVD": [0.5, 0.0], |
||||||
|
"PVV": [0.8, 0.0], |
||||||
|
} |
||||||
|
|
||||||
|
assert compute_flip_direction(1, party_scores) is False |
||||||
Loading…
Reference in new issue