forked from rssalessio/PythonVRFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
71 lines (61 loc) · 2.44 KB
/
test_utils.py
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
70
71
# test_utils.py - Unittest for utilities
#
# Code author: [Alessio Russo - alessior@kth.se]
# Last update: 10th January 2021, by alessior@kth.se
#
# Copyright (c) [2017-2021] Alessio Russo [alessior@kth.se]. All rights reserved.
# This file is part of PythonVRFT.
# PythonVRFT is free software: you can redistribute it and/or modify
# it under the terms of the MIT License. You should have received a copy of
# the MIT License along with PythonVRFT.
# If not, see <https://opensource.org/licenses/MIT>.
#
from unittest import TestCase
import numpy as np
import scipy.signal as scipysig
from vrft.utils import *
from vrft.extended_tf import ExtendedTF
from vrft.vrft_algo import virtual_reference
from vrft.iddata import iddata
class TestUtils(TestCase):
def test_deconvolve(self):
t_start = 0
t_end = 10
t_step = 1e-2
t = np.arange(t_start, t_end, t_step)
sys = ExtendedTF([0.5], [1, -0.9], dt=t_step)
u = np.random.normal(size=t.size)
_, y = scipysig.dlsim(sys, u, t)
y = y[:, 0]
data = iddata(y, u, t_step, [0])
r1, _ = virtual_reference(data, sys.num, sys.den)
r2 = deconvolve_signal(sys, data.y)
self.assertTrue(np.linalg.norm(r2-r1[:r2.size], np.infty) < 1e-3)
def test_check_system(self):
a = [1, 0, 1]
b = [1, 0, 2]
self.assertTrue(check_system(a,b))
b = [1, 0, 2, 4]
self.assertTrue(check_system(a,b))
a = [1]
self.assertTrue(check_system(a,b))
a = [1, 0, 1]
b = [1,0]
with self.assertRaises(ValueError):
check_system(a,b)
b = [1]
with self.assertRaises(ValueError):
check_system(a,b)
def test_system_order(self):
self.assertEqual(system_order(0, 0), (0, 0))
self.assertEqual(system_order(1, 0), (0, 0))
self.assertEqual(system_order([1],[1]), (0, 0))
self.assertEqual(system_order([1, 1],[1, 1]), (1,1))
self.assertEqual(system_order([1, 1, 3],[1, 1]), (2,1))
self.assertEqual(system_order([1, 1, 3],[1]), (2,0))
self.assertEqual(system_order([1, 1],[1, 1, 1]), (1,2))
self.assertEqual(system_order([1],[1, 1, 1]), (0,2))
self.assertEqual(system_order([0, 1],[1, 1, 1]), (0,2))
self.assertEqual(system_order([0,0,1],[1, 1, 1]), (0,2))
self.assertEqual(system_order([0,0,1],[0, 1, 1, 1]), (0,2))
self.assertEqual(system_order([0,0,1],[0, 0, 1, 1, 1]), (0,2))