sys.path.insert(0, "../") from tester import Tester t = Tester() ## from task import sumNumbers, sumNumbersWithoutRed ## write tests here -- # part 1 t.test("array", sumNumbers("[1,2,3]"), 6); t.test("negative value", sumNumbers("[1,4,-3]"), 2); t.test("nested json with red value", sumNumbers("{\"a\": [1,3], \"b\":{\"color\": \"red\",\"number\":-3,\"data\":{\"x\":5}}}"), 6); t.test("nested json", sumNumbers("[{\"a\":5}, 3, [1, {\"red\": \"not-red\", \"x\": 6}, {\"n\": -50, \"green\":\"red\"}]]"), -35) # part 2 t.test("array", sumNumbersWithoutRed("[1,2,3]"), 6); t.test("negative value", sumNumbersWithoutRed("[1,4,-3]"), 2); t.test("nested json with red value", sumNumbersWithoutRed("{\"a\": [1,3], \"b\":{\"color\": \"red\",\"number\":-3,\"data\":{\"x\":5}}}"), 4); t.test("nested json", sumNumbersWithoutRed("[{\"a\":5}, 3, [1, {\"red\": \"not-red\", \"x\": 6}, {\"n\": -50, \"green\":\"red\"}]]"), 15) ## -- end of tests if t.report() == True: ARGUMENTS = [] print("Running 'run.py' process with arguments {}".format(ARGUMENTS)) print("---") args = ["python", "run.py"] + ARGUMENTS p = subprocess.Popen(args)
t = Tester() ## # from task import parseLine ## write tests here -- # part 1 # part 2 ## -- end of tests def askYesNo(question): print(question + " [y/n]") yes = set(['yes','y', 'ye', '']) no = set(['no','n']) while True: choice = raw_input().lower() if choice in yes: return True elif choice in no: return False else: print("Answer with 'y' (yes) or 'n' (no).") ARGUMENTS = [ ] if t.report() == True and askYesNo("Run the program with arguments {}?".format(ARGUMENTS)): print("---") args = ["python", "run.py"] + ARGUMENTS p = subprocess.Popen(args)
movement = move(5, (0, 4), reindeer[1:]) t.test("respect max travel time in movement - move only for one second", movement[0], 1) t.test("respect max travel time in movement - reach end after one second", movement[1], 5) rested = rest(5, (0, 4), reindeer[1:]) # rest for one second t.test("respect max travel time in resting - do not move", rested[0], 0) t.test("respect max travel time in resting - rest for one second only", rested[1], 5) # part 2 ## -- end of tests def askYesNo(question): print(question + " [y/n]") yes = set(['yes','y', 'ye', '']) no = set(['no','n']) while True: choice = raw_input().lower() if choice in yes: return True elif choice in no: return False else: print("Answer with 'y' (yes) or 'n' (no).") if t.report() == True and askYesNo("Run the program?"): ARGUMENTS = [ "2503" ] print("Running 'run.py' process with arguments {}".format(ARGUMENTS)) print("---") args = ["python", "run.py"] + ARGUMENTS p = subprocess.Popen(args)