|
1 | 1 |
|
| 2 | +import math |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | + |
2 | 7 | def test_emotional_imports(): |
3 | 8 | from emotion.emotion_core import EmotionCore |
4 | 9 | from emotion.eeg_mapper import EEGEmotionMapper |
| 10 | + |
5 | 11 | assert EmotionCore is not None and EEGEmotionMapper is not None |
| 12 | + |
| 13 | + |
| 14 | +def test_emotion_core_tracks_variance(): |
| 15 | + from emotion.emotion_core import EmotionCore |
| 16 | + |
| 17 | + core = EmotionCore(baseline=0.5) |
| 18 | + result = core.process([0.0, 1.0, 2.0]) |
| 19 | + |
| 20 | + assert result["mood"] == pytest.approx(0.5 + (0.0 + 1.0 + 2.0) / 3.0) |
| 21 | + assert result["variance"] == pytest.approx( |
| 22 | + sum((value - result["mood"]) ** 2 for value in [0.0, 1.0, 2.0]) / 3.0 |
| 23 | + ) |
| 24 | + |
| 25 | + |
| 26 | +def test_fractional_distribution_normalises_output(): |
| 27 | + from emotion.utils import fractional_distribution |
| 28 | + |
| 29 | + distribution = fractional_distribution([1.0, 2.0], ["a", "b", "c"]) |
| 30 | + |
| 31 | + assert set(distribution) == {"a", "b", "c"} |
| 32 | + assert math.isclose(sum(distribution.values()), 1.0) |
| 33 | + assert distribution["b"] > distribution["a"] |
| 34 | + |
| 35 | + |
| 36 | +def test_fractional_distribution_handles_negative_values(): |
| 37 | + from emotion.utils import fractional_distribution |
| 38 | + |
| 39 | + distribution = fractional_distribution([-1.0, -3.0], ["alpha", "beta"]) |
| 40 | + |
| 41 | + assert distribution["beta"] == pytest.approx(0.75) |
0 commit comments