def test_example_cumulative(self): f1 = Fremen() f2 = Fremen() for i in range(0, len(times), 5): f1.add(times[i:min(i + 6, len(times))], states[i:min(i + 6, len(times))]) f2.add(times, states) self.assertLessEqual( (f1.estimate(times, orderi=3) - f2.estimate(times, orderi=3)).sum(), 1e-15, "In the test case provided building the model incrementally and one-shot provided different results." )
def test_order_repr(self): nper = 100 o = random.randint(1, nper) f = Fremen(num_periodicities=nper, default_orderi=o) self.assertEqual( len(str(f).split('\n')), o + 1, "Lines in string representation don't match with the default order + 1" )
def test_example_entropy_case(self): f = Fremen() f.add(times, states) self.assertLessEqual( f.estimateEntropy(times, orderi=11).sum() - 69.35590258966235, 1e-15, "The test case provided had a wrong entropy estimation!")
def test_example_estimate_case(self): f = Fremen() f.add(times, states) self.assertLessEqual( f.estimate(times, orderi=4).sum() - 54.47299842276188, 1e-15, "The test case provided had a wrong function approximation!")
def test_add_empty_xy(self): f = Fremen() up = f.add([], []) self.assertEqual( up, 0, 'Adding empty observations should keep the model static.')
def test_add_different_xy(self): f = Fremen() with self.assertRaises(ValueError): f.add([i for i in range(5)], [random.randint(0, 1) for i in range(6)])
def test_add_empty_y(self): f = Fremen() with self.assertRaises(ValueError): f.add([i for i in range(5)], [])
def test_add_empty_x(self): f = Fremen() with self.assertRaises(ValueError): f.add([], [random.randint(0, 1) for i in range(5)])
def test_str_max_period(self): with self.assertRaises(ValueError): f = Fremen(max_period='osjdhgodsn')
def test_str_orderi(self): with self.assertRaises(ValueError): s = Fremen(default_orderi='osjdhgodsn')
def test_str_num_periodicities(self): with self.assertRaises(ValueError): s = Fremen(num_periodicities='osjdhgodsn')