def tests(): runTests(SlipstremingTester())
for (rider, path) in moves: self.animateMove(rider, path) sleep(self.clock * 2) for group in groups: sleep(self.clock * 2) self.animateGroup(group) for color in ["yellow", "red", "default"]: for rider in exhausted: self.display.setBackground(rider, color) self.display.update() sleep(self.clock) def animateMove(self, rider, path): for i in range(len(path) - 1): sleep(self.clock) self.display.move(rider, path[i], path[i + 1]) self.display.update() def animateGroup(self, group): for (rider, end) in group: start = (end[0] - 1, end[1]) self.display.move(rider, start, end) self.display.update() import tkinter as tk if __name__ == "__main__": runTests(AnimateTester(tk.Tk()))
def tests(): runTests(ExhaustTester())
self.move(1) assert_equals((0, 0), self.rider.position()) class Race(): def __init__(self, length=100): self.obstacles = [] self.length = length self.setAll("normal") def addRider(self, square, lane): self.obstacles.append((square, lane)) def setAll(self, field): self.field = [field for i in range(self.length)] def set(self, field, square): self.field[square] = field def getRoadType(self, square): if square >= self.length: return "out" return self.field[square] def isFree(self, slot): return not slot in self.obstacles if __name__ == "__main__": runTests(RiderTest())
def tests(): runTests(RaceTest())
RiderToken(3, 0), RiderToken(3, 1) ] obstacles = Obstacles(riders) assert_equals([(0, 0), (1, 1), (2, 0), (3, 2), (4, 0)], findPath(obstacles, (0, 0), (4, 0))) def findPath(obstacles, start, end): if start[0] == end[0]: return [end] next = findNextEmpty(obstacles, start, end) return [start] + findPath(obstacles, next, end) def findNextEmpty(obstacles, start, end): nextSquare = start[0] + 1 if nextSquare == end[0]: return end for lane in range(2): if obstacles.isFree((nextSquare, lane)): return nextSquare, lane return nextSquare, 2 if __name__ == "__main__": runTests(PathTester())
def tests(): runTests(TrackTest())
def tests(): runTests(PlayerTest())
def runVisualTestsInWindow(testerClass): window = tk.Tk() runTests(testerClass(window)) window.mainloop()
def tests(): runTests(CardsTester())