-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_rms.py
43 lines (34 loc) · 1.42 KB
/
test_rms.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
# -*- coding: utf-8 -*-
# test_rms.py
# This module provides the tests for the rms function.
# Copyright 2014 Giuseppe Venturini
# This file is part of python-deltasigma.
#
# python-deltasigma is a 1:1 Python replacement of Richard Schreier's
# MATLAB delta sigma toolbox (aka "delsigma"), upon which it is heavily based.
# The delta sigma toolbox is (c) 2009, Richard Schreier.
#
# python-deltasigma is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# LICENSE file for the licensing terms.
"""This module provides the test class for the rms() function.
"""
import unittest
import numpy as np
from deltasigma import rms
class TestRms(unittest.TestCase):
"""Test class for rms()"""
def setUp(self):
self.tv = np.arange(100)
self.res1 = np.sqrt(np.sum(self.tv**2.)/float(self.tv.shape[0]))
self.res2 = np.sqrt((np.sum((self.tv - self.tv.mean())**2.)) \
/self.tv.shape[0])
def test_rms_1(self):
"""Test function for rms() 1/2"""
self.assertTrue(np.allclose(rms(self.tv), self.res1, rtol=1e-05,
atol=1e-08))
def test_rms_2(self):
"""Test function for rms() 2/2"""
self.assertTrue(np.allclose(rms(self.tv, no_dc=True), self.res2,
rtol=1e-05, atol=1e-08))