def testRepeatedConnectionIndex(self): file = open("test3.txt", "w") file.write("1 2 3 IN EA 2 2 4 2") file.close() puzzle = NewPuzzle() with self.assertRaises(SystemExit): self.assertEqual("Clue 1 has two connections at the same index", puzzle.readIn("test3.txt"))
def testBadBSI(self): file = open("test3.txt", "w") file.write("1 4 3 IN EA 2 2") file.close() puzzle = NewPuzzle() with self.assertRaises(SystemExit): self.assertEqual("Clue 1 has a Block Start Index that's out of bounds", puzzle.readIn("test3.txt"))
def testBadLength(self): file = open("test3.txt", "w") file.write("1 2 3 IN EA 2 2") file.close() puzzle = NewPuzzle() with self.assertRaises(SystemExit): self.assertEqual("Clue 1 has an invalid length", puzzle.readIn("test3.txt"))
def testIDType(self): file = open("test3.txt", "w") file.write("R 4 0 IN EA 2 2") file.close() puzzle = NewPuzzle() with self.assertRaises(SystemExit): self.assertEqual("Clue R 4 0 IN EA 2 2 is not formatted correctly.", puzzle.readIn("test3.txt"))
def test(self): puzzle = NewPuzzle() with self.assertRaises(SystemExit): self.assertEqual("Could not read file: badfile.txt", puzzle.readIn("badfile.txt"))
def testClueFormatLength(self): puzzle = NewPuzzle() with self.assertRaises(SystemExit): self.assertEqual("Clue 1 doesn't have the correct formatting.", puzzle.readIn("testpuzzles/test3.txt"))
def testBlockFormatLength(self): puzzle = NewPuzzle() with self.assertRaises(SystemExit): self.assertEqual("The block in clue 1 is not formatted correctly", puzzle.readIn("testpuzzles/test2.txt"))
import sys from NewPuzzle import NewPuzzle puzzle = NewPuzzle() if (len(sys.argv) > 1): print(sys.argv[1]) else: print( "Please run this program again with a .txt file as a command line argument." ) exit(0) input = str(sys.argv[1]) if (input[-4:] != ".txt"): print(input[-4:]) print("Please run this with a .txt file") exit(0) else: try: f = open(input, "r") except: print("Could not open file") puzzle.readIn(input) puzzle.solve() puzzle.print()