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)
def test_string_in_ascending_mode_with_any_array(self): with self.assertRaises(Exception): match(3, ['aab', 'a', 'rars'])
def test_string_in_ascending_mode(self): # Closest inferior value is found self.assertEqual(match('rars', ['a', 'AAB', 'rars']), 3)
def test_numeric_in_descending_mode(self): # Closest superior value is found self.assertEqual(match(8, [10, 9.1, 6.2], -1), 2)
def test_numeric_in_exact_mode(self): # Value is found self.assertEqual(match(5, [10, 3.3, 5.0], 0), 3)
def test_numeric_in_ascending_mode(self): # Closest inferior value is found self.assertEqual(match(5, [1, 3.3, 5]), 3)
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)
def test_boolean_in_ascending_mode_with_any_array(self): # Not ascending arrays raise exception with self.assertRaises(Exception): match(True, [False, True, False])
def test_string_in_ascending_mode_with_descending_array(self): # Not ascending arrays raise exception with self.assertRaises(Exception): match(3, ['rars', 'aab', 'a'])
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)
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)
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])
def test_string_in_exact_mode_not_found(self): # Value not found raises Exception with self.assertRaises(ValueError): match('b', ['aab', 'a', 'rars'], 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)
def test_boolean_in_exact_mode_not_found(self): # Value not found raises Exception with self.assertRaises(ValueError): match(False, [True, True, True], 0)
def test_string_in_exact_mode(self): # Value is found self.assertEqual(match('a', ['aab', 'a', 'rars'], 0), 2)
def test_match(lookup_value, lookup_array, match_type, result): assert result == match(lookup_value, lookup_array, match_type)
def test_string_in_descending_mode(self): # Closest superior value is found self.assertEqual(match('a', ['c', 'b', 'a'], -1), 3)
def test_boolean_in_ascending_mode(self): # Closest inferior value is found self.assertEqual(match(True, [False, False, True]), 3)
def test_boolean_in_exact_mode(self): # Value is found self.assertEqual(match(False, [True, False, False], 0), 2)
def test_boolean_in_descending_mode(self): # Closest superior value is found self.assertEqual(match(False, [True, False, False], -1), 3)
def test_boolean_in_descending_mode_with_any_array(self): with self.assertRaises(Exception): match(True, [False, True, False], -1)
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)