c1012382f2
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
'''
|
|
Created on Dec 19, 2016
|
|
|
|
@author: klaehn
|
|
'''
|
|
import unittest
|
|
import random
|
|
from data_buffer import DataBuffer
|
|
|
|
|
|
class Test(unittest.TestCase):
|
|
|
|
|
|
def test_zero_space(self):
|
|
dut = DataBuffer(0)
|
|
result = dut.push(10)
|
|
self.assertFalse(result, "test_zero_space - exp: False res: True")
|
|
|
|
def test_max_data(self):
|
|
buffer_size = 10
|
|
dut = DataBuffer(buffer_size)
|
|
for _ in range(11):
|
|
dut.push(random.random())
|
|
result = dut.length()
|
|
self.assertEqual(result, buffer_size, "test_max_data - exp: " + \
|
|
str(buffer_size) + " res: " + str(result))
|
|
|
|
def test_average_min(self):
|
|
dut = DataBuffer(10)
|
|
rnd = random.random()
|
|
dut.push(rnd)
|
|
result = dut.average()
|
|
self.assertEqual(result, None, "test_average_min - exp: None" + \
|
|
" res: " + str(result))
|
|
|
|
def test_average_mid(self):
|
|
buffer_size = 10
|
|
res_buffer = []
|
|
dut = DataBuffer(buffer_size)
|
|
for _ in range(buffer_size / 2):
|
|
rnd = random.random()
|
|
dut.push(rnd)
|
|
res_buffer.append(rnd)
|
|
result = dut.average()
|
|
self.assertEqual(result, None, "test_average_mid - exp: None" + \
|
|
" res: " + str(result))
|
|
|
|
def test_average_max(self):
|
|
buffer_size = 10
|
|
res_buffer = []
|
|
dut = DataBuffer(buffer_size)
|
|
for _ in range(buffer_size):
|
|
rnd = random.random()
|
|
dut.push(rnd)
|
|
res_buffer.append(rnd)
|
|
result = dut.average()
|
|
self.assertEqual(result, sum(res_buffer) / buffer_size, \
|
|
"test_average_mid - exp: " + \
|
|
str(sum(res_buffer) / buffer_size) + \
|
|
" res: " + str(result))
|
|
|
|
if __name__ == "__main__":
|
|
#import sys;sys.argv = ['', 'Test.testName']
|
|
unittest.main() |