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