def test_seed_float(self): """ Test if seed change affects output """ random.seed(1) data_num = 10 distribution = 'uniform' min_value = 0 max_value = 1 got1 = gen_float(data_num, distribution, min_value, max_value, 0, 0) random.seed(2) got2 = gen_float(data_num, distribution, min_value, max_value, 0, 0) random.seed(1) got3 = gen_float(data_num, distribution, min_value, max_value, 0, 0) self.assertTrue(got1 == got3 and got1 != got2)
def test_num_float(self): """ Test number of generated floats """ data_num = 10 distribution = 'uniform' min_value = 0 max_value = 1 got = gen_float(data_num, distribution, min_value, max_value, 0, 0) result = got.count('\n') self.assertEqual(result, data_num)
def test_random(self): """ Test if generated floats are random """ random.seed(0) data_num = 10 distribution = 'uniform' min_value = 0 max_value = 1 got = [ gen_float(data_num, distribution, min_value, max_value, 0, 0) for _ in range(1000) ] self.assertTrue(len(set(got)) == len(got))
def test_uniform(self): """ Test uniform distribution Value N should be [a; b] """ data_num = 10000 distribution = 'uniform' a = 0 b = 1 got = gen_float(data_num, distribution, a, b, 0, 0).split('\n') del got[-1] float_arr = [float(x) for x in got] flag = False for i in float_arr: if i < a or i > b: flag = True self.assertFalse(flag)
def test_normal(self): """ Test normal distribution Value should be (x-3σ; x+3σ) - three-sigma rule (99.7%) """ random.seed(0) data_num = 100000 distribution = 'normal' mean = 5 std = 0.5 got = gen_float(data_num, distribution, 0, 0, mean, std).split('\n') del got[-1] float_arr = [float(x) for x in got] counter = 0 for i in float_arr: if i < mean - 3 * std or i > mean + 3 * std: counter += 1 self.assertTrue(counter <= data_num * 0.3 / 100)