def testValidation(): tests = [("", "6_2"), ("0_1-2-3-4-5", "6_2"), ("2_3-1-4-5-20", "6_2"), ("4_5-6-1-2-2", "6_2"), ("123456----", "6_2")] for test in tests: pytest.raises(PuzzleException, PuzzleManager.validate, TopSpin.puzzleid, test[0], test[1]) PuzzleManager.validate(TopSpin.puzzleid, "6_2", "2_1-5-3-6-4")
def testValidation(): tests = [("", "Triangle"), ("111_0_11_22_22_11011", "Triangle"), ("1_11_111_1111_11111_", "Triangle"), ("1_11_000_0111_11111_", "Not Triangle")] for test in tests: pytest.raises(PuzzleException, PuzzleManager.validate, Peg.id, test[1], test[0]) PuzzleManager.validate(Peg.id, "Triangle", "1_11_000_0111_11111_")
def testValidation(): tests = [("", "2"), ("123---", "2"), ("1-2-3-3", "2"), ("1-2-3-0", "3")] for test in tests: pytest.raises(PuzzleException, PuzzleManager.validate, Npuzzle.puzzleid, test[1], test[0]) PuzzleManager.validate(Npuzzle.puzzleid, "2", "1-2-3-0")
def testValidation(): tests = [("", "10"), ("xxxyx_ooo--oo", "10"), ("xxxoo-ooooo", "10"), ("xxxoo-ooooo", "10")] for test in tests: pytest.raises(PuzzleException, PuzzleManager.validate, Chairs.puzzleid, test[1], test[0]) PuzzleManager.validate(Chairs.puzzleid, "10", "oooxx-ooxxx")
def testValidation(): """Tests four different serializations and checks if it matches the expected response.""" # Four invalid serializations tests = [("", "3_3"), ("15-0-0", "4_3"), ("7-0-0", "3_4"), ("7-0-0-", "3_3")] for test in tests: pytest.raises(PuzzleException, PuzzleManager.validate, Hanoi.id, test[1], test[0]) PuzzleManager.validate(Hanoi.id, "3_3", "7-0-0")
def testValidation(): """Tests four different serializations and checks if it matches the expected response.""" # Four invalid serializations tests = [("", "2x5"), ("2-5-a1_c1-a5_c5", "2x5"), ("2_5_a5_a1-c1", "2x5"), ("2_5_a5-c5_a1-c1", "3x7")] # Four exceptions raised for test in tests: pytest.raises(PuzzleException, PuzzleManager.validate, Bishop.puzzleid, test[1], test[0]) PuzzleManager.validate(Bishop.puzzleid, "2x5", "2_5_a5-c5_a1-c1")
def validate(puzzleid=None, variantid=None, position=None): if puzzleid == None: raise ValueError("Nothing to validate") if not PuzzleManager.hasPuzzleId(puzzleid): abort(404, description="PuzzleId not found") if variantid != None: variants = PuzzleManager.getPuzzleClass(puzzleid).variants if variantid not in variants: abort(404, description="VariantId not found") if position != None: try: PuzzleManager.validate(puzzleid, variantid, position) except PuzzleException as e: abort(404, description=str(e))
def testValidation(): """Tests four different serializations and checks if it matches the expected response.""" # Four invalid serializations tests = [("", "3"), ("R_A_3_3_-*-*-*-*-", "2"), ("R_A_2_2_-*-*-*-*-", "3"), ("R_A_2_2_-*-*", "3")] for test in tests: try: PuzzleManager.validate(p_cls.id, test[1], test[0]) except PuzzleException: pass else: print("Validation: {}".format(test)) raise Exception