def is_solution_feasible(self, solution): if not solution.is_valid(): return False return all(( (self.ll <= len(cluster) <= self.lu) and (sum( (solution.instance.weights[cluster_elem] for cluster_elem in cluster) ) <= self.eu) for cluster in solution.clusters ))
def test_solve_diagonal_4(self): diag_sudoku_grid_4 = '..7..5..2.......13.........9...8.7......7...5..2.......1..3.......54.......7....4' expected_solution_4 = '367415892295867413841329657953284761684173925172956348418632579739541286526798134' resp = solve(diag_sudoku_grid_4) if resp is not False: solution_4 = values_grid(resp) print('Expected: {}'.format(expected_solution_4)) print('Solution: {}'.format(solution_4)) print(display(grid_values(solution_4))) self.assertEquals(expected_solution_4, solution_4) self.assertTrue(is_valid(grid_values(solution_4))) else: print('Could not find a valid solution.')
def test_is_valid_anagram_key(passphrase, valid): anagram_key = lambda p: "".join(sorted(p)) assert is_valid(passphrase, key=anagram_key) == valid
def test_is_valid(formula, result): assert is_valid(formula) == result
def test_basic(self): self.assertEqual(is_valid('aabbcc'), True)
def test_is_valid(passphrase, valid): assert is_valid(passphrase) == valid
def test_invalid_longer(self): self.assertEqual(is_valid('ibfdgaeadiaefgbhbdghhhbgdfgeiccbiehhfcggchgghadhdhagfbahhddgghbdehidbibaeaagaeeigffcebfbaieggabcfbiiedcabfihchdfabifahcbhagccbdfifhghcadfiadeeaheeddddiecaicbgigccageicehfdhdgafaddhffadigfhhcaedcedecafeacbdacgfgfeeibgaiffdehigebhhehiaahfidibccdcdagifgaihacihadecgifihbebffebdfbchbgigeccahgihbcbcaggebaaafgfedbfgagfediddghdgbgehhhifhgcedechahidcbchebheihaadbbbiaiccededchdagfhccfdefigfibifabeiaccghcegfbcghaefifbachebaacbhbfgfddeceababbacgffbagidebeadfihaefefegbghgddbbgddeehgfbhafbccidebgehifafgbghafacgfdccgifdcbbbidfifhdaibgigebigaedeaaiadegfefbhacgddhchgcbgcaeaieiegiffchbgbebgbehbbfcebciiagacaiechdigbgbghefcahgbhfibhedaeeiffebdiabcifgccdefabccdghehfibfiifdaicfedagahhdcbhbicdgibgcedieihcichadgchgbdcdagaihebbabhibcihicadgadfcihdheefbhffiageddhgahaidfdhhdbgciiaciegchiiebfbcbhaeagccfhbfhaddagnfieihghfbaggiffbbfbecgaiiidccdceadbbdfgigibgcgchafccdchgifdeieicbaididhfcfdedbhaadedfageigfdehgcdaecaebebebfcieaecfagfdieaefdiedbcadchabhebgehiidfcgahcdhcdhgchhiiheffiifeegcfdgbdeffhgeghdfhbfbifgidcafbfcd'), True)
def test_invalid_long(self): self.assertEqual(is_valid('hfchdkkbfifgbgebfaahijchgeeeiagkadjfcbekbdaifchkjfejckbiiihegacfbchdihkgbkbddgaefhkdgccjejjaajgijdkd'), True)
def test_invalid_multiple(self): self.assertEqual(is_valid('aabbccdeee'), False)
def test_invalid_lets(self): self.assertEqual(is_valid('aabbccde'), False)
def test_invalid_count(self): self.assertEqual(is_valid('aabbcccc'), False)