Пример #1
0
    def test_level2_Y_Wing(self):
#        chains = [[[1, False, True, True, False, False]], [[0, True, False, True, False, False], [2, False, True, False, True, False]], [[1, False, True, False, True, False]]]
        YW = Y_Wing
        cp = copyofgrid
        basic = basicgrid()
        cpbasic = cp(basic)
        YW1 = YW(basic)
        self.assertTrue(YW1[0] == cpbasic)
        self.assertFalse(YW1[1])

        basic[0][1] = '12'
        basic[0][7] = '23'
        basic[7][7] = '13'
        cpbasic = cp(basic)
        YW1 = YW(basic)       
        self.assertTrue(YW1[1])
        self.assertFalse(YW1[0] == cpbasic)
#        print(YW1[0][7][0])
        self.assertTrue(YW1[0][7][0] == '23456789')
        basic = basicgrid()
        basic[0][0] = '12'
        basic[2][2] = '13'
        basic[0][6] = '23'
        cpbasic = cp(basic)
        YW1 = YW(basic)   
        self.assertTrue(YW1[1])
        cpbasic[0][2] = '12456789'
        cpbasic[2][6:] = ['12456789' for i in range(3)]
#        print('*'*30)
#        print(basic[0][2])
#        print(basic[2])
#        print(cpbasic[2])
        self.assertTrue(cpbasic[2] == basic[2])
Пример #2
0
    def test_level1_Box_Line(self):
        cp = copyofgrid
        basic = basicgrid()
        basic[0] = ['12345689' for i in range(9)]
        basic[0][1] = basic[0][0] = '123456789'
        cpbasic = cp(basic)
        BL = Box_Line(basic)

        self.assertFalse(basic == cpbasic)
        self.assertTrue(basic[1][0] == '12345689')
Пример #3
0
    def test_level0_Naked_Single(self):
        cp = copyofgrid
        a = basicgrid()
        b = cp(a)
        NSA = Naked_Single(a)
        self.assertTrue(NSA[0] == b)
        self.assertFalse(NSA[1])

        a[1][2] = '3'
        b = cp(a)
        NSA = Naked_Single(a)
        self.assertTrue(NSA[1])
        self.assertFalse(NSA[0] == b)
        self.assertTrue(NSA[0][1][2] == 3)
Пример #4
0
 def test_level2_Lines_2(self):
     cp = copyofgrid
     L2 = Lines_2
     basic = basicgrid()
     cpbasic = cp(basic)
     L2_1 = L2(basic)
     self.assertTrue(L2_1[0] == cpbasic)
     basic[0][1:-1] = basic[3][1:-1] = ['12345789' for i in range(7)]
     cpbasic = cp(basic)
     L2_1 = L2(basic)
     self.assertFalse(L2_1[0] == cpbasic)
     self.assertTrue(L2_1[1])
     tt = '12345789'
     self.assertTrue(L2_1[0][2][0] == tt)
Пример #5
0
 def test_grid_standardize(self):
     bg = basicgrid()
     self.assertEqual(standardize(bg),basicgrid())
     bg[1][2] = 0
     self.assertEqual(standardize(bg),basicgrid())
     bg[1][2] = None
     self.assertEqual(standardize(bg),basicgrid())
     bg[1][2] = '0'
     self.assertEqual(standardize(bg),basicgrid())
     bg[1][2] = '32'
     self.assertNotEqual(standardize(bg),basicgrid())
     bg[1][2] = 3
     self.assertNotEqual(standardize(bg),basicgrid())
Пример #6
0
    def test_level2_NT(self):
#        cp = copyofgrid
        twins = NT
        basic = basicgrid()
#        cpbasic = cp(basic)
        twins1 = twins(basic)
        self.assertTrue(twins1 == [])
        for i in range(8):
            basic[i][i+1] = f'{i+1}{i+2}'

        twins1 = twins(basic)
#        print(twins1)
        target = [['12', 0, 1, '00'], ['23', 1, 2, '00'],
                ['34', 2, 3, '01'], ['45', 3, 4, '11'],
                ['56', 4, 5, '11'], ['67', 5, 6, '12'],
                ['78', 6, 7, '22'], ['89', 7, 8, '22']]
        self.assertTrue(target == twins1)
Пример #7
0
def sudoku17():
    import random
    global fullsdks
    if not fullsdks:
        # this is link from
        # http://staffhome.ecm.uwa.edu.au/~00013890/sudokumin.php
        url = 'http://staffhome.ecm.uwa.edu.au/~00013890/sudoku17'
        fn = 'sudoku17'
        try:
            with open(fn, 'r') as f:
                sdks = f.readlines()
        except FileNotFoundError:
            import subprocess
            t = subprocess.call(['wget', url])
            try:
                with open(fn, 'r') as f:
                    sdks = f.readlines()

            except FileNotFoundError:
                print(f'please download file from {url} when available')

                print(
                    'http://staffhome.ecm.uwa.edu.au/~00013890/sudokumin.php')
                return basicgrid()
        for s in range(len(sdks)):
            sdks[s] = sdks[s].replace('\n', '')
        fullsdks = [[] for i in sdks]
        for i in range(len(fullsdks)):
            #    while len(fullsdks[i]) < 10:
            #        fullsdks[i].append([])
            start = 0
            end = 9
            while end <= len(sdks[i]):

                fullsdks[i].append([])
                fullsdks[i][-1] = sdks[i][start:end]
                start = end
                end += 9
    ran = random.randint(0, len(fullsdks))
    return standardize(fullsdks[ran])

    for s in range(len(fullsdks)):
        print(fullsdks[s])
        print(sdks[s])
        print(standardize(fullsdks[s]))
Пример #8
0
    def test_level1_Pointing_Line(self):
        cp = copyofgrid
        basic = basicgrid()
        cpbasic = cp(basic)
        PL = Pointing_Line(basic)

        self.assertFalse(PL[1])
        self.assertTrue(PL[0] == cpbasic)
        basic[0][0:3] = ['12346789' for i in range(3)]
        basic[2][0:3] = ['12346789' for i in range(3)]
#        print(basic[0])
        cpbasic = cp(basic)

        PL = Pointing_Line(basic)
        self.assertTrue(PL[1])
        self.assertFalse(PL[0] == cpbasic)
        target = ['12346789' for i in range(6)]
        self.assertTrue(PL[0][1][3:] == target)
Пример #9
0
 def test_grid_basic(self):
     self.assertEqual(basicgrid(),[['123456789' for i in range(9)] for i in range(9)])
Пример #10
0
 def test_copyofgrid(self):
     self.assertFalse(basicgrid() is copyofgrid(basicgrid()))
     self.assertTrue(basicgrid() == copyofgrid(basicgrid()))
Пример #11
0
 def test_grid_done(self):
     self.assertFalse(done(basicgrid())[0])
     g = [[1,2,3,5,4,6,8,9,8] for i in range(9)]
     self.assertTrue(done(g)[0])
     self.assertFalse(done(g)[1])