Exemplo n.º 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)
Exemplo n.º 2
0
 def test_string_in_ascending_mode_with_any_array(self):
     with self.assertRaises(Exception):
         match(3, ['aab', 'a', 'rars'])
Exemplo n.º 3
0
 def test_string_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match('rars', ['a', 'AAB', 'rars']), 3)
Exemplo n.º 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)
Exemplo n.º 5
0
 def test_numeric_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(5, [10, 3.3, 5.0], 0), 3)
Exemplo n.º 6
0
 def test_numeric_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(5, [1, 3.3, 5]), 3)
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 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'])
Exemplo n.º 10
0
 def test_string_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match('rars', ['a', 'AAB', 'rars']), 3)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 14
0
 def test_numeric_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(5, [10, 3.3, 5.0], 0), 3)
Exemplo n.º 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])
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 18
0
 def test_string_in_ascending_mode_with_any_array(self):
     with self.assertRaises(Exception):
         match(3, ['aab', 'a', 'rars'])
Exemplo n.º 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)
Exemplo n.º 20
0
 def test_string_in_exact_mode(self):
     # Value is found
     self.assertEqual(match('a', ['aab', 'a', 'rars'], 0), 2)
Exemplo n.º 21
0
def test_match(lookup_value, lookup_array, match_type, result):
    assert result == match(lookup_value, lookup_array, match_type)
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 24
0
 def test_string_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match('a', ['c', 'b', 'a'], -1), 3)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 28
0
 def test_boolean_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(True, [False, False, True]), 3)
Exemplo n.º 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'])
Exemplo n.º 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])
Exemplo n.º 31
0
 def test_string_in_exact_mode(self):
     # Value is found
     self.assertEqual(match('a', ['aab', 'a', 'rars'], 0), 2)
Exemplo n.º 32
0
 def test_boolean_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(False, [True, False, False], 0), 2)
Exemplo n.º 33
0
 def test_string_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match('a', ['c', 'b', 'a'], -1), 3)
Exemplo n.º 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)
Exemplo n.º 35
0
 def test_boolean_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(True, [False, False, True]), 3)
Exemplo n.º 36
0
 def test_boolean_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match(False, [True, False, False], -1), 3)
Exemplo n.º 37
0
 def test_boolean_in_exact_mode(self):
     # Value is found
     self.assertEqual(match(False, [True, False, False], 0), 2)
Exemplo n.º 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)
Exemplo n.º 39
0
 def test_boolean_in_descending_mode(self):
     # Closest superior value is found
     self.assertEqual(match(False, [True, False, False], -1), 3)
Exemplo n.º 40
0
 def test_boolean_in_descending_mode_with_any_array(self):    
     with self.assertRaises(Exception):
         match(True, [False, True, False], -1)
Exemplo n.º 41
0
 def test_boolean_in_descending_mode_with_any_array(self):
     with self.assertRaises(Exception):
         match(True, [False, True, False], -1)
Exemplo n.º 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)
Exemplo n.º 43
0
 def test_numeric_in_ascending_mode(self):
     # Closest inferior value is found
     self.assertEqual(match(5, [1, 3.3, 5]), 3)
Exemplo n.º 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)