summaryrefslogtreecommitdiffhomepage
path: root/test/sca/test_edit.py
blob: 282e62eda88b49c8164197a90f16873ac4603e2f (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
from unittest import TestCase

import numpy as np

from pyecsca.sca import Trace, trim, reverse, pad


class EditTests(TestCase):
    def setUp(self):
        self._trace = Trace(np.array([10, 20, 30, 40, 50], dtype=np.dtype("i1")))

    def test_trim(self):
        result = trim(self._trace, 2)
        self.assertIsNotNone(result)
        np.testing.assert_equal(
            result.samples, np.array([30, 40, 50], dtype=np.dtype("i1"))
        )

        result = trim(self._trace, end=3)
        self.assertIsNotNone(result)
        np.testing.assert_equal(
            result.samples, np.array([10, 20, 30], dtype=np.dtype("i1"))
        )

        with self.assertRaises(ValueError):
            trim(self._trace, 5, 1)

    def test_reverse(self):
        result = reverse(self._trace)
        self.assertIsNotNone(result)
        np.testing.assert_equal(
            result.samples, np.array([50, 40, 30, 20, 10], dtype=np.dtype("i1"))
        )

    def test_pad(self):
        result = pad(self._trace, 2)
        self.assertIsNotNone(result)
        np.testing.assert_equal(
            result.samples,
            np.array([0, 0, 10, 20, 30, 40, 50, 0, 0], dtype=np.dtype("i1")),
        )

        result = pad(self._trace, (1, 3))
        self.assertIsNotNone(result)
        np.testing.assert_equal(
            result.samples,
            np.array([0, 10, 20, 30, 40, 50, 0, 0, 0], dtype=np.dtype("i1")),
        )