79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
from unittest import TestCase
|
|
from app import DataCapture, Stats
|
|
|
|
|
|
class TestDataCaptureStats(TestCase):
|
|
def test_init(self):
|
|
"""Test no error at initialization."""
|
|
a = DataCapture()
|
|
assert isinstance(a, DataCapture)
|
|
|
|
def test_add_single_value(self):
|
|
"""Test no error at add single value."""
|
|
a = DataCapture()
|
|
a.add(1)
|
|
|
|
def test_add_many_values(self):
|
|
"""Test no error at add many values."""
|
|
a = DataCapture()
|
|
a.add(1, 2)
|
|
|
|
def test_generate_stats_zero(self):
|
|
"""Test no error at add many values."""
|
|
a = DataCapture()
|
|
stats = a.build_stats()
|
|
assert isinstance(stats, Stats)
|
|
|
|
def test_generate_single_element_stats(self):
|
|
"""Test no error at add many values."""
|
|
a = DataCapture()
|
|
a.add(1)
|
|
stats = a.build_stats()
|
|
assert isinstance(stats, Stats)
|
|
|
|
def test_generate_multi_element_stats(self):
|
|
"""Test no error at add many values."""
|
|
a = DataCapture()
|
|
a.add(1, 2, 3, 4, 5, 6, 7)
|
|
stats = a.build_stats()
|
|
assert isinstance(stats, Stats)
|
|
assert 5 == stats.greater(2)
|
|
assert 4 == stats.less(5)
|
|
assert 4 == stats.between(2, 5)
|
|
|
|
def test_generate_multi_element_stats_v2(self):
|
|
"""Test no error at add many values."""
|
|
a = DataCapture()
|
|
a.add(1, 2, 3, 4, 5, 6, 7)
|
|
a.add(1, 2, 3, 4, 5, 6, 7)
|
|
stats = a.build_stats()
|
|
assert isinstance(stats, Stats)
|
|
assert 10 == stats.greater(2)
|
|
assert 8 == stats.less(5)
|
|
assert 8 == stats.between(2, 5)
|
|
|
|
def test_generate_multi_element_stats_v3(self):
|
|
"""Test no error at add many values."""
|
|
a = DataCapture()
|
|
a.add(1, 2, 3, 4, 5, 6, 7)
|
|
a.add(2, 4, 6, 8)
|
|
stats = a.build_stats()
|
|
assert isinstance(stats, Stats)
|
|
assert 6 == stats.less(5)
|
|
assert 6 == stats.between(2, 5)
|
|
assert 1 == stats.less(2)
|
|
assert 2 == stats.between(2, 2)
|
|
assert 8 == stats.greater(2)
|
|
|
|
def test_base_case(self):
|
|
capture = DataCapture()
|
|
capture.add(3)
|
|
capture.add(9)
|
|
capture.add(3)
|
|
capture.add(4)
|
|
capture.add(6)
|
|
stats = capture.build_stats()
|
|
assert 2 == stats.less(4)
|
|
assert 2 == stats.greater(4)
|
|
assert 4 == stats.between(3, 6)
|