64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
|
'''
|
||
|
Created on Dec 19, 2016
|
||
|
|
||
|
@author: klaehn
|
||
|
'''
|
||
|
import unittest
|
||
|
import random
|
||
|
from light_data.light_data import light_data
|
||
|
|
||
|
|
||
|
class Test(unittest.TestCase):
|
||
|
|
||
|
|
||
|
def test_zero_space(self):
|
||
|
dut = light_data(0)
|
||
|
result = dut.push(10)
|
||
|
self.assertFalse(result, "test_zero_space - exp: False res: True")
|
||
|
|
||
|
def test_max_data(self):
|
||
|
buffer_size = 10
|
||
|
dut = light_data(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 = light_data(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 = light_data(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 = light_data(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()
|