aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sca/test_process.py
blob: 9ab8bcf2740f5b6da2dde25be57c90515b5c5160 (plain) (blame)
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
import numpy as np
import pytest

from pyecsca.sca import (
    Trace,
    absolute,
    invert,
    threshold,
    rolling_mean,
    offset,
    recenter,
    normalize,
    normalize_wl,
)


@pytest.fixture()
def trace():
    return Trace(np.array([30, -60, 145, 247], dtype=np.dtype("i2")), None)


def test_absolute(trace):
    result = absolute(trace)
    assert result is not None
    assert result.samples[1] == 60


def test_invert(trace):
    result = invert(trace)
    assert result is not None
    np.testing.assert_equal(result.samples, [-30, 60, -145, -247])


def test_threshold(trace):
    result = threshold(trace, 128)
    assert result is not None
    assert result.samples[0] == 0
    assert result.samples[2] == 1


def test_rolling_mean(trace):
    result = rolling_mean(trace, 2)
    assert result is not None
    assert len(result.samples) == 3
    assert result.samples[0] == -15
    assert result.samples[1] == 42.5
    assert result.samples[2] == 196


def test_offset(trace):
    result = offset(trace, 5)
    assert result is not None
    np.testing.assert_equal(
        result.samples, np.array([35, -55, 150, 252], dtype=np.dtype("i2"))
    )


def test_recenter(trace):
    assert recenter(trace) is not None


def test_normalize(trace):
    result = normalize(trace)
    assert result is not None


def test_normalize_wl(trace):
    result = normalize_wl(trace)
    assert result is not None