Пример #1
0
def test_match_crazy_order(lookup_array, lookup_value, result1, result0,
                           resultm1):
    assert result0 == match(lookup_value, lookup_array, 0)
    assert resultm1 == match(lookup_value, lookup_array, -1)
    if result1 != match(lookup_value, lookup_array, 1):
        lookup_array = [ExcelCmp(x) for x in lookup_array]
        if sorted(lookup_array) == lookup_array:
            # only complain on failures for mode 0 when array is sorted
            assert result1 == match(lookup_value, lookup_array, 1)
Пример #2
0
 def test_string_in_ascending_mode_with_any_array(self):
     with self.assertRaises(Exception):
         match(3, ['aab', 'a', 'rars'])
Пример #3
0
 def test_string_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match('rars', ['a', 'AAB', 'rars']), 3)
Пример #4
0
 def test_numeric_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match(8, [10, 9.1, 6.2], -1), 2)
Пример #5
0
 def test_numeric_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(5, [10, 3.3, 5.0], 0), 3)
Пример #6
0
 def test_numeric_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(5, [1, 3.3, 5]), 3)
Пример #7
0
 def test_boolean_in_descending_mode_with_ascending_array(self):
     # Non descending arrays raise exception
     with self.assertRaises(Exception):
         match(False, [False, False, True], -1)
Пример #8
0
 def test_boolean_in_ascending_mode_with_any_array(self):
     # Not ascending arrays raise exception
     with self.assertRaises(Exception):
         match(True, [False, True, False])
Пример #9
0
 def test_string_in_ascending_mode_with_descending_array(self):
     # Not ascending arrays raise exception
     with self.assertRaises(Exception):
         match(3, ['rars', 'aab', 'a'])
Пример #10
0
 def test_string_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match('rars', ['a', 'AAB', 'rars']), 3)
Пример #11
0
 def test_numeric_in_descending_mode_with_any_array(self):
     # Non descending arrays raise exception
     with self.assertRaises(Exception):
         match(3, [10, 3.3, 5, 2], -1)
Пример #12
0
 def test_numeric_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match(8, [10, 9.1, 6.2], -1), 2)
Пример #13
0
 def test_numeric_in_exact_mode_not_found(self):
     # Value not found raises Exception
     with self.assertRaises(ValueError):
         match(3, [10, 3.3, 5, 2], 0)
Пример #14
0
 def test_numeric_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(5, [10, 3.3, 5.0], 0), 3)
Пример #15
0
 def test_numeric_in_ascending_mode_with_descending_array(self):
     # Not ascending arrays raise exception
     with self.assertRaises(Exception):
         match(3, [10, 9.1, 6.23, 1])
Пример #16
0
 def test_string_in_exact_mode_not_found(self):
     # Value not found raises Exception
     with self.assertRaises(ValueError):
         match('b', ['aab', 'a', 'rars'], 0)
Пример #17
0
 def test_string_in_descending_mode_with_any_array(self):
     # Non descending arrays raise exception
     with self.assertRaises(Exception):
         match('a', ['aab', 'a', 'rars'], -1)
Пример #18
0
 def test_string_in_ascending_mode_with_any_array(self):
     with self.assertRaises(Exception):
         match(3, ['aab', 'a', 'rars'])
Пример #19
0
 def test_boolean_in_exact_mode_not_found(self):
     # Value not found raises Exception
     with self.assertRaises(ValueError):
         match(False, [True, True, True], 0)
Пример #20
0
 def test_string_in_exact_mode(self):
     # Value is found
     self.assertEqual(match('a', ['aab', 'a', 'rars'], 0), 2)
Пример #21
0
def test_match(lookup_value, lookup_array, match_type, result):
    assert result == match(lookup_value, lookup_array, match_type)
Пример #22
0
 def test_string_in_exact_mode_not_found(self):
     # Value not found raises Exception
     with self.assertRaises(ValueError):
         match('b', ['aab', 'a', 'rars'], 0)
Пример #23
0
 def test_numeric_in_ascending_mode_with_descending_array(self):
     # Not ascending arrays raise exception
     with self.assertRaises(Exception):
         match(3, [10, 9.1, 6.23, 1])
Пример #24
0
 def test_string_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match('a', ['c', 'b', 'a'], -1), 3)
Пример #25
0
 def test_numeric_in_exact_mode_not_found(self):
     # Value not found raises Exception
     with self.assertRaises(ValueError):
         match(3, [10, 3.3, 5, 2], 0)
Пример #26
0
 def test_string_in_descending_mode_with_any_array(self):
     # Non descending arrays raise exception
     with self.assertRaises(Exception):
         match('a', ['aab', 'a', 'rars'], -1)
Пример #27
0
 def test_numeric_in_descending_mode_with_any_array(self):
     # Non descending arrays raise exception
     with self.assertRaises(Exception):
         match(3, [10, 3.3, 5, 2], -1)
Пример #28
0
 def test_boolean_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(True, [False, False, True]), 3)
Пример #29
0
 def test_string_in_ascending_mode_with_descending_array(self):
     # Not ascending arrays raise exception
     with self.assertRaises(Exception):
         match(3, ['rars', 'aab', 'a'])
Пример #30
0
 def test_boolean_in_ascending_mode_with_any_array(self):
     # Not ascending arrays raise exception
     with self.assertRaises(Exception):
         match(True, [False, True, False])
Пример #31
0
 def test_string_in_exact_mode(self):
     # Value is found
     self.assertEqual(match('a', ['aab', 'a', 'rars'], 0), 2)
Пример #32
0
 def test_boolean_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(False, [True, False, False], 0), 2)
Пример #33
0
 def test_string_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match('a', ['c', 'b', 'a'], -1), 3)
Пример #34
0
 def test_boolean_in_exact_mode_not_found(self):
     # Value not found raises Exception
     with self.assertRaises(ValueError):
         match(False, [True, True, True], 0)
Пример #35
0
 def test_boolean_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(True, [False, False, True]), 3)
Пример #36
0
 def test_boolean_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match(False, [True, False, False], -1), 3)
Пример #37
0
 def test_boolean_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(False, [True, False, False], 0), 2)
Пример #38
0
 def test_boolean_in_descending_mode_with_ascending_array(self):
     # Non descending arrays raise exception
     with self.assertRaises(Exception):
         match(False, [False, False, True], -1)
Пример #39
0
 def test_boolean_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match(False, [True, False, False], -1), 3)
Пример #40
0
 def test_boolean_in_descending_mode_with_any_array(self):    
     with self.assertRaises(Exception):
         match(True, [False, True, False], -1)
Пример #41
0
 def test_boolean_in_descending_mode_with_any_array(self):
     with self.assertRaises(Exception):
         match(True, [False, True, False], -1)
Пример #42
0
def test_match(lookup_value, lookup_array, match_type, result):
    lookup_row = (tuple(lookup_array), )
    lookup_col = tuple((i, ) for i in lookup_array)
    assert result == match(lookup_value, lookup_row, match_type)
    assert result == match(lookup_value, lookup_col, match_type)
Пример #43
0
 def test_numeric_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(5, [1, 3.3, 5]), 3)
Пример #44
0
def test_match(lookup_value, lookup_array, match_type, result):
    lookup_row = (tuple(lookup_array), )
    lookup_col = tuple((i, ) for i in lookup_array)
    assert result == match(lookup_value, lookup_row, match_type)
    assert result == match(lookup_value, lookup_col, match_type)