コード例 #1
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_doesnt_lose_or_add_items(self):
     original_list = [('Something', 10), ('Another', 5), ('Again', 1),
                      ('And', 700), ('More', 5)]
     shuffled = rand.weighted_order(original_list)
     self.assertEqual(len(original_list), len(shuffled))
     for item in original_list:
         self.assertIn(item[0], shuffled)
コード例 #2
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_output_type(self):
     original_list = [('Something', 10),
                      ('Another',   5),
                      ('Again',     1),
                      ('And',       700),
                      ('More',      5)]
     shuffled = rand.weighted_order(original_list)
     for item in shuffled:
         self.assertIsInstance(item, str)
コード例 #3
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_doesnt_modify_original(self):
     original_list = [('Something', 10),
                      ('Another',   5),
                      ('Again',     1),
                      ('And',       700),
                      ('More',      5)]
     input_list = original_list[:]
     shuffled = rand.weighted_order(input_list)
     self.assertEqual(input_list, original_list)
コード例 #4
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_doesnt_lose_or_add_items(self):
     original_list = [('Something', 10),
                      ('Another',   5),
                      ('Again',     1),
                      ('And',       700),
                      ('More',      5)]
     shuffled = rand.weighted_order(original_list)
     self.assertEqual(len(original_list), len(shuffled))
     for item in original_list:
         self.assertIn(item[0], shuffled)
コード例 #5
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_extremely_strong_weight(self):
     original_list = [('Something', 10), ('Another', 5), ('Again', 1),
                      ('And', 7000), ('More', 5)]
     success_count = 0
     TRIALS = 500
     for i in range(TRIALS):
         shuffled = rand.weighted_order(original_list)
         if shuffled.index('And') == 0:
             success_count += 1
     self.assertGreater(success_count, TRIALS * 0.75)
コード例 #6
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_extremely_strong_weight(self):
     original_list = [('Something', 10),
                      ('Another',   5),
                      ('Again',     1),
                      ('And',       7000),
                      ('More',      5)]
     success_count = 0
     TRIALS = 500
     for i in range(TRIALS):
         shuffled = rand.weighted_order(original_list)
         if shuffled.index('And') == 0:
             success_count += 1
     self.assertGreater(success_count, TRIALS * 0.75)
コード例 #7
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_all_1_weights(self):
     # When every weight is 0, the probability spread should be uniform
     original_list = [('Something', 1), ('Another', 1), ('Again', 1),
                      ('And', 1), ('More', 1)]
     landing_positions = {
         'Something': [],
         'Another': [],
         'Again': [],
         'And': [],
         'More': []
     }
     for i in range(1000):
         shuffled_list = rand.weighted_order(original_list)
         for index, value in enumerate(shuffled_list):
             landing_positions[value].append(index)
     # With an even distribution, landing indices should average near 2.5
     for positions in landing_positions.values():
         average = sum(positions) / len(positions)
         self.assertLess(abs(average - 2.5), 1)
コード例 #8
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_all_1_weights(self):
     # When every weight is 0, the probability spread should be uniform
     original_list = [('Something', 1),
                      ('Another',   1),
                      ('Again',     1),
                      ('And',       1),
                      ('More',      1)]
     landing_positions = {'Something': [],
                          'Another': [],
                          'Again': [],
                          'And': [],
                          'More': []}
     for i in range(1000):
         shuffled_list = rand.weighted_order(original_list)
         for index, value in enumerate(shuffled_list):
             landing_positions[value].append(index)
     # With an even distribution, landing indices should average near 2.5
     for positions in landing_positions.values():
         average = sum(positions) / len(positions)
         self.assertLess(abs(average - 2.5), 1)
コード例 #9
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_empty_list_returns_empty_list(self):
     self.assertEqual(rand.weighted_order([]), [])
コード例 #10
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_invalid_weight(self):
     with self.assertRaises(rand.ProbabilityUndefinedError):
         foo = rand.weighted_order([('bar', 0), ('baz', 5), ('buzz', -3)])
コード例 #11
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_empty_list_returns_empty_list(self):
     self.assertEqual(rand.weighted_order([]), [])
コード例 #12
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_with_invalid_weight(self):
     with self.assertRaises(rand.ProbabilityUndefinedError):
         foo = rand.weighted_order([('bar', 0), ('baz', 5), ('buzz', -3)])
コード例 #13
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_output_type(self):
     original_list = [('Something', 10), ('Another', 5), ('Again', 1),
                      ('And', 700), ('More', 5)]
     shuffled = rand.weighted_order(original_list)
     for item in shuffled:
         self.assertIsInstance(item, str)
コード例 #14
0
ファイル: test_rand.py プロジェクト: ajyoon/blur
 def test_weighted_order_doesnt_modify_original(self):
     original_list = [('Something', 10), ('Another', 5), ('Again', 1),
                      ('And', 700), ('More', 5)]
     input_list = original_list[:]
     shuffled = rand.weighted_order(input_list)
     self.assertEqual(input_list, original_list)