Exemple #1
0
def test_search():
    nums = [2, 5, 6, 0, 0, 1, 2]
    target = 0
    assert search(nums, target) == True

    # pudb.set_trace()
    target = 3
    assert search(nums, target) == False
Exemple #2
0
def test():
    board = [['a', 'a']]
    word = 'aaa'
    # pudb.set_trace()

    assert False == search(board, word)

    board = [["A", "B", "C", "E"], ["S", "F", "E", "S"], ["A", "D", "E", "E"]]
    word = "ABCESEEEFS"
    pudb.set_trace()

    assert True == search(board, word)
def test_solution():
    from solution import Node, search

    items = Node(5)
    items.left = Node(6)
    items.right = Node(7)
    items.left.left = Node(8)
    items.left.right = Node(9)
    items.right.left = Node(10)
    items.right.right = Node(11)
    result_value = search(items, 11)
    result_value_2 = search(items, 99)
    assert result_value == True
    assert result_value_2 == False
Exemple #4
0
    def test_search(self):
        # given
        t_values = solution.grid_values(
            '.....97..4..7...2...18...39.3....4...769.531...4....9.84...39...1...8..3..26.....'
        )

        # when
        values = solution.search(t_values)

        # then
        self.assertTrue(solution.is_solved_correctly(values))

        print()
        lines = solution.display(values)
import utils
import solution
if __name__=='__main__':
    solution.search(
            utils.grid2values('..3.2.6..9..3.5..1..18.64....81.29..7.......8..67.82....26.95..8..2.3..9..5.1.3..')
            )
Exemple #6
0
    def test_search(self):
        p = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......'
        p = solution.grid_values(p)
        solution.search(p)
        expected = {
            'A1': '4',
            'A2': '9',
            'A3': '7',
            'A4': '1',
            'A5': '2',
            'A6': '6',
            'A7': '8',
            'A8': '3',
            'A9': '5',
            'B1': '6',
            'B2': '3',
            'B3': '8',
            'B4': '4',
            'B5': '6',
            'B6': '568',
            'B7': '79',
            'B8': '2',
            'B9': '179',
            'C1': '289',
            'C2': '1',
            'C3': '2',
            'C4': '7',
            'C5': '3',
            'C6': '58',
            'C7': '6',
            'C8': '4',
            'C9': '139',
            'D1': '8',
            'D2': '2',
            'D3': '1',
            'D4': '5',
            'D5': '39',
            'D6': '4',
            'D7': '379',
            'D8': '6',
            'D9': '379',
            'E1': '7',
            'E2': '5',
            'E3': '569',
            'E4': '39',
            'E5': '8',
            'E6': '2',
            'E7': '4',
            'E8': '1',
            'E9': '379',
            'F1': '3',
            'F2': '4',
            'F3': '569',
            'F4': '',
            'F5': '1',
            'F6': '7',
            'F7': '5',
            'F8': '8',
            'F9': '239',
            'G1': '2',
            'G2': '8',
            'G3': '9',
            'G4': '6',
            'G5': '5',
            'G6': '3',
            'G7': '1',
            'G8': '7',
            'G9': '4',
            'H1': '5',
            'H2': '7',
            'H3': '3',
            'H4': '2',
            'H5': '4',
            'H6': '1',
            'H7': '',
            'H8': '9',
            'H9': '8',
            'I1': '1',
            'I2': '6',
            'I3': '4',
            'I4': '8',
            'I5': '7',
            'I6': '9',
            'I7': '3',
            'I8': '5',
            'I9': '2'
        }

        self.assertEqual(expected, p)
Exemple #7
0
from solution import search

# basic tests
nums = [4, 5, 6, 7, 0, 1, 2]
target = 0
assert search(nums, target) == 4

nums = [4, 5, 6, 7, 0, 1, 2]
target = 3
assert search(nums, target) == -1

# empty list
assert search([], 3) == -1

# list with one element in nums
assert search([1], 1) == 0

# # list with one element not in nums
assert search([1], 2) == -1

assert search([3, 1], 0) == -1

assert search([1, 3], 1) == 0

assert search([5, 1, 3], 1) == 1

assert search([5, 1, 3], 3) == 2

assert search([1, 3, 5], 5) == 2

assert search([4, 5, 6, 7, 8, 1, 2, 3], 8) == 4
Exemple #8
0
    def test_search_001(self):
        grid = '2.............62....1....7...6..8...3...9...7...6..4...4....8....52.............3'
        values = grid_values(grid)
        values = search(values)

        # with the diagonal constraint
        self.assertEqual(
            {
                'G7': '8',
                'G6': '9',
                'G5': '7',
                'G4': '3',
                'G3': '2',
                'G2': '4',
                'G1': '6',
                'G9': '5',
                'G8': '1',
                'C9': '6',
                'C8': '7',
                'C3': '1',
                'C2': '9',
                'C1': '4',
                'C7': '5',
                'C6': '3',
                'C5': '2',
                'C4': '8',
                'E5': '9',
                'E4': '1',
                'F1': '1',
                'F2': '2',
                'F3': '9',
                'F4': '6',
                'F5': '5',
                'F6': '7',
                'F7': '4',
                'F8': '3',
                'F9': '8',
                'B4': '7',
                'B5': '1',
                'B6': '6',
                'B7': '2',
                'B1': '8',
                'B2': '5',
                'B3': '3',
                'B8': '4',
                'B9': '9',
                'I9': '3',
                'I8': '2',
                'I1': '7',
                'I3': '8',
                'I2': '1',
                'I5': '6',
                'I4': '5',
                'I7': '9',
                'I6': '4',
                'A1': '2',
                'A3': '7',
                'A2': '6',
                'E9': '7',
                'A4': '9',
                'A7': '3',
                'A6': '5',
                'A9': '1',
                'A8': '8',
                'E7': '6',
                'E6': '2',
                'E1': '3',
                'E3': '4',
                'E2': '8',
                'E8': '5',
                'A5': '4',
                'H8': '6',
                'H9': '4',
                'H2': '3',
                'H3': '5',
                'H1': '9',
                'H6': '1',
                'H7': '7',
                'H4': '2',
                'H5': '8',
                'D8': '9',
                'D9': '2',
                'D6': '8',
                'D7': '1',
                'D4': '4',
                'D5': '3',
                'D2': '7',
                'D3': '6',
                'D1': '5'
            }, values)
 def test_solves_complex_grids(self):
     grid = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......'
     values = solution.grid_values(grid)
     solved_values = solution.search(values)
     self.assertNotEqual(solved_values, False)
def test_seach():
    target = ((20, 30), (-10, -5))
    candidates = search(target)
    assert max(candidates, key=lambda item: item[1]) == (6, 9)