Esempio n. 1
0
    def test0096_duplicates(self):
        import time
        from id_0096 import contains_duplicates, contains_duplicates_set
        from random import randint
        
        start = time.time()
        for n in range(20000):
            arr = [randint(1, 9) for x in range(9)]
        end = time.time()
        print("time for creating arrays: ", end - start)
        arrtime = end - start

        start = time.time()
        for n in range(20000):
            arr = [randint(1, 9) for x in range(9)]
            contains_duplicates(arr)
        end = time.time()
        print("time for contains_duplicates: ", end - start - arrtime)

        start = time.time()
        for n in range(20000):
            arr = [randint(1, 9) for x in range(9)]
            contains_duplicates_set(arr)
        end = time.time()
        print("time for contains_duplicates_set: ", end - start - arrtime)
Esempio n. 2
0
    def test0096(self):
        from id_0096 import row, col, cell, check_table, solve, contains_duplicates, contains_duplicates_set
        from random import randint

        f = open('id_0096-test.txt')
        arr = []
        for line in f:
            arr.append([int(x) for x in line.strip()])
        f.close()
        self.assertEqual(row(arr, 1), [9, 0, 0, 3, 0, 5, 0, 0, 1])
        self.assertEqual(col(arr, 2), [3, 0, 1, 8, 0, 6, 2, 0, 5])
        self.assertEqual(cell(arr, 4), [1, 0, 2, 0, 0, 0, 7, 0, 8])
        self.assertEqual(check_table(arr), True)
        sol = solve(arr)
        f = open('id_0096-test-ans.txt')
        arr_sol = []
        for line in f:
            arr_sol.append([int(x) for x in line.strip()])
        f.close()
        self.assertEqual(sol, arr_sol)

        for n in range(100):
            arr = [randint(1, 9) for x in range(9)]
            self.assertEqual(contains_duplicates(arr), contains_duplicates_set(arr))