add basic tests for stats filters
This commit is contained in:
parent
2e6723c15e
commit
b47cc70d92
@ -3,11 +3,13 @@ from saucebrush.tests.filters import FilterTestCase
|
||||
from saucebrush.tests.sources import SourceTestCase
|
||||
from saucebrush.tests.emitters import EmitterTestCase
|
||||
from saucebrush.tests.recipes import RecipeTestCase
|
||||
from saucebrush.tests.stats import StatsTestCase
|
||||
|
||||
filter_suite = unittest.TestLoader().loadTestsFromTestCase(FilterTestCase)
|
||||
source_suite = unittest.TestLoader().loadTestsFromTestCase(SourceTestCase)
|
||||
emitter_suite = unittest.TestLoader().loadTestsFromTestCase(EmitterTestCase)
|
||||
recipe_suite = unittest.TestLoader().loadTestsFromTestCase(RecipeTestCase)
|
||||
stats_suite = unittest.TestLoader().loadTestsFromTestCase(StatsTestCase)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
40
saucebrush/tests/stats.py
Normal file
40
saucebrush/tests/stats.py
Normal file
@ -0,0 +1,40 @@
|
||||
import unittest
|
||||
from saucebrush.stats import Sum, Average, Median, MinMax, StandardDeviation
|
||||
|
||||
class StatsTestCase(unittest.TestCase):
|
||||
|
||||
def _simple_data(self):
|
||||
return [{'a':1, 'b':2, 'c':3},
|
||||
{'a':5, 'b':5, 'c':5},
|
||||
{'a':1, 'b':10, 'c':100}]
|
||||
|
||||
def test_sum(self):
|
||||
fltr = Sum('b')
|
||||
list(fltr.attach(self._simple_data()))
|
||||
self.assertEqual(fltr.value(), 17)
|
||||
|
||||
def test_average(self):
|
||||
fltr = Average('c')
|
||||
list(fltr.attach(self._simple_data()))
|
||||
self.assertEqual(fltr.value(), 36.0)
|
||||
|
||||
def test_median(self):
|
||||
fltr = Median('a')
|
||||
list(fltr.attach(self._simple_data()))
|
||||
self.assertEqual(fltr.value(), 1)
|
||||
|
||||
def test_minmax(self):
|
||||
fltr = MinMax('b')
|
||||
list(fltr.attach(self._simple_data()))
|
||||
self.assertEqual(fltr.value(), (2, 10))
|
||||
|
||||
def test_standard_deviation(self):
|
||||
fltr = StandardDeviation('c')
|
||||
list(fltr.attach(self._simple_data()))
|
||||
self.assertEqual(fltr.average(), 36.0)
|
||||
self.assertEqual(fltr.median(), 5)
|
||||
self.assertEqual(fltr.value(), (55.4346462061408, 3073.0))
|
||||
self.assertEqual(fltr.value(True), (45.2621990922521, 2048.6666666666665))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue
Block a user