2 """Module Description: Test functions for online algorithm functions.
4 This code is free software; you can redistribute it and/or modify it
5 under the terms of the BSD License (see the file LICENSE included with
12 # ------------------------------------
14 # ------------------------------------
16 def update_m_s(x
, c
, m
, s
):
23 class Test_Mean(unittest
.TestCase
):
25 # np.random.randint(1,1000,size=10)
26 self
.data
= [410, 710, 891, 312, 453, 460, 237, 622, 268]
27 # [np.mean(self.data[0:x]) for x in range(0,len(self.data)+1)]
28 self
.correct_mean
= [410.0, 560.0, 670.3333333333334, 580.75, 555.2, 539.3333333333334, 496.14285714285717, 511.875, 484.77777777777777]
29 # [np.std(self.data[0:x]) for x in range(0,len(self.data)+1)]
30 self
.correct_stddev
= [0.0, 150.0, 198.36050234078579, 231.48582569997671, 213.25984150795946, 197.8852080261573, 211.55845431425504, 202.2247743848414, 205.48737608036913]
32 def test_mean( self
):
36 for i
in range( 1, len( self
.data
) ):
37 (c
, m
, s
) = update_m_s( self
.data
[ i
], c
, m
, s
)
40 self
.assertAlmostEqual( self
.correct_mean
[i
], m
, 2 )
41 self
.assertAlmostEqual( self
.correct_stddev
[i
], std
, 2 )