def test_main(self): for case in self.cases[:3]: inputs = case["input"] output = level3.main([self, inputs["reviewee_id"], inputs["json_path"], \ inputs["lang"], inputs["deadline"]], "2017-04-26") output_list = output.split(',') # check duplicates of reviewer s = set() duplicates = len(list(set([x for x in output_list if (x in s and x != "N/A") or s.add(x)]))) self.assertEqual(duplicates, 0) # check output is in "x,x,x" self.assertEqual(type(output), unicode) self.assertEqual(len(output_list), 3) # test whether reviewer is in expected output. output_dict = dict(zip(["teammate_reviewer", "otherteam_recviewer", "last_reviewer"], output_list)) self.assertIn(output_dict["teammate_reviewer"], case["output"]["teammate_candidates"]) self.assertIn(output_dict["otherteam_recviewer"], case["output"]["otherteam_candidates"]) self.assertIn(output_dict["last_reviewer"], case["output"]["last_candidates"])
pygame.init() pygame.mixer.init() if __name__ == "__main__": donePlaying = False while donePlaying == False: level = mainmenu.mainmenu() while level >= 0: if level == 0: level = mainmenu.mainmenu() if level == 1: level = level1.main() if level == 2: level = level2.main() if level == 3: level = level3.main() level, donePlaying = gameOver.main()
def test_Main(self): self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 3, 'W', 'W', 'W' ]), '-1 3' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 3, 16, 8, 'S', 'E', 'E', 'N', 'N', 'E', 'E', 'S' ]), '1 8' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 3, 'N', 'W', 'W' ]), '-1 3' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 14, 'S', 'E', 'E', 'S', 'S', 'S', 'W', 'W', 'W', 'N', 'N', 'N', 'N', 'W' ]), '-1 3' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 11, 'S', 'W', 'W', 'W', 'N', 'N', 'E', 'E', 'S', 'S' ]), '-1 10' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 3, 'S', 'S', 'W' ]), '-1 2' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 4, 'N', 'W', 'S', 'E' ]), '-1 4' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 10, 'S', 'W', 'W', 'W', 'N', 'N', 'E', 'E', 'S', 'S' ]), '-1 10' ) self.assertEqual( main([ 5, 5, 8, 7, 1, 9, 1, 10, 2, 16, 3, 17, 2, 19, 4, 20, 3, 25, 4, 1, 1, 9, 10, 'S', 'W', 'W', 'W', 'N', 'E', 'E', 'N', 'W', 'S' ]), '-1 10' )
for i in pygame.event.get(): if i.type == QUIT or press[K_q]: exit() screen.fill((0, 0, 0)) mousepress = pygame.mouse.get_pressed() l1 = pygame.font.SysFont("comicsansms", 50) l2 = pygame.font.SysFont("comicsansms", 30) l3 = pygame.font.SysFont("comicsansms", 30) l4 = pygame.font.SysFont("comicsansms", 30) r2 = Rect((100, 200), l2.size("Press 1 for Level 1 ")) r3 = Rect((100, 250), l3.size("Press 2 for Level 2 ")) r4 = Rect((100, 300), l3.size("Press 3 for Level 3 ")) screen.blit(l1.render("Select Your Level", True, (0, 255, 0)), (100, 100)) screen.blit(l2.render("Press 1 for Level 1 ", True, (0, 255, 0)), (100, 200)) screen.blit(l3.render("Press 2 for level 2 ", True, (0, 255, 0)), (100, 250)) screen.blit(l4.render("Press 3 for level 3 ", True, (0, 255, 0)), (100, 300)) pygame.display.update() if press[K_1] or (r2.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level1.main() if press[K_2] or (r3.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level2.main() if press[K_3] or (r4.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level3.main()
def main(): screen = pygame.display.set_mode((pygame.display.Info().current_w, pygame.display.Info().current_h), pygame.FULLSCREEN) background = pygame.Surface(screen.get_size()) background = background.convert_alpha() background.fill((39, 174, 96)) CENTER_W = int(pygame.display.Info().current_w / 2) CENTER_H = int(pygame.display.Info().current_h / 2) BARRIER_BLUE = 187 BARRIER_WHITE = 238 ROAD_BRIGHT_COLOR = 177 ROAD_DARK_COLOR = 187 GRASS = 174 clock = pygame.time.Clock() font = pygame.font.Font(None, 50) car = pygame_classes.Player(car_customization.change_color(), CENTER_W, CENTER_H) car.x -= 200 cam = pygame_classes.Camera() target = pygame_classes.Finish(9, 7) bound_alert = pygame_classes.BoundsAlert() time_alert = pygame_classes.TimeAlert() win_alert = pygame_classes.WinAlert() map_s = pygame.sprite.Group() player_s = pygame.sprite.Group() tracks_s = pygame.sprite.Group() target_s = pygame.sprite.Group() timer_alert_s = pygame.sprite.Group() bound_alert_s = pygame.sprite.Group() win_alert_s = pygame.sprite.Group() map_tile = ['mud1.png', 'mud2.png', 'mud3.png', 'mud4.png', 'mud5.png', 'mud6.png', 'mud7.png', 'race.png', 'tree.png', 'tribune.png', 'grass.png'] map = [ [9, 9, 9, 2, 0, 0, 0, 0, 3, 8], [2, 0, 3, 1, 10, 10, 10, 10, 1, 8], [1, 10, 1, 1, 10, 2, 0, 3, 1, 8], [1, 10, 1, 10, 8, 1, 8, 1, 1, 8], [1, 10, 1, 8, 8, 1, 10, 1, 1, 8], [1, 10, 1, 10, 10, 1, 8, 4, 5, 9], [1, 10, 1, 10, 8, 1, 8, 8, 7, 10], [1, 10, 1, 8, 10, 1, 10, 8, 7, 6], [1, 10, 4, 0, 0, 5, 9, 9, 7, 1], [4, 0, 0, 0, 0, 0, 0, 0, 0, 5] ] pygame_classes.map_files.clear() for tile_num in range(0, len(map_tile)): pygame_classes.map_files.append(pygame_classes.load_image(map_tile[tile_num], False)) for x in range(0, 10): for y in range(0, 10): map_s.add(pygame_classes.Map(map[x][y], x * 500, y * 500)) pygame_classes.initialize_tracks() target_s.add(target) timer_alert_s.add(time_alert) bound_alert_s.add(bound_alert) win_alert_s.add(win_alert) player_s.add(car) cam.set_position(car.x, car.y) win = None current_crashes_number = 0 crashes_limit = 5 collided = False crash = False running = True while running: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: car.reset() car.x -= 200 target.reset() current_crashes_number = 0 win = None collided = False crash = False elif event.key == pygame.K_ESCAPE: running = False break keys = pygame.key.get_pressed() if target.time_left > 0 and win is None: if keys[K_LEFT]: car.steer_left() if keys[K_RIGHT]: car.steer_right() if keys[K_UP]: car.accelerate() else: car.soften() if keys[K_DOWN]: car.deaccelerate() cam.set_position(car.x, car.y) text_timer = font.render( 'Timer: ' + str(int((target.time_left / 60) / 60)) + ":" + str(int((target.time_left / 60) % 60)), 1, (255, 255, 255)) text_crashes_limit = font.render("Actual limit of crashes: " + str(crashes_limit - current_crashes_number), 1, (255, 255, 255)) screen.blit(background, (0, 0)) map_s.update(cam.x, cam.y) map_s.draw(screen) car.slow_down_on_grass(screen.get_at((int(CENTER_W - 5), int(CENTER_H - 5))).g, GRASS) if car.tracks: tracks_s.add(pygame_classes.Track(cam.x + CENTER_W, cam.y + CENTER_H, car.dir)) tracks_s.update(cam.x, cam.y) tracks_s.draw(screen) player_s.update(cam.x, cam.y) player_s.draw(screen) target_s.update(cam.x, cam.y) target_s.draw(screen) if car.is_collision(screen, BARRIER_WHITE, BARRIER_BLUE): if current_crashes_number == crashes_limit: car.speed = 0 win = False crash = True else: car.speed = 0 if car.is_out_of_road(screen.get_at((car.rect.left + car.rect.width, car.rect.top - car.rect.height)).r, ROAD_BRIGHT_COLOR, ROAD_DARK_COLOR): car.x = car.x + car.rect.width car.y = car.y - 0.5 * car.rect.height elif car.is_out_of_road( screen.get_at((car.rect.right - car.rect.width, car.rect.top - car.rect.height)).r, ROAD_BRIGHT_COLOR, ROAD_DARK_COLOR): car.x = car.x - car.rect.width car.y = car.y - 0.5 * car.rect.height elif car.is_out_of_road( screen.get_at((car.rect.left + car.rect.width, car.rect.bottom + car.rect.height)).r, ROAD_BRIGHT_COLOR, ROAD_DARK_COLOR): car.x = car.x + car.rect.width car.y = car.y + car.rect.height elif car.is_out_of_road( screen.get_at((car.rect.right - car.rect.width, car.rect.bottom + car.rect.height)).r, ROAD_BRIGHT_COLOR, ROAD_DARK_COLOR): car.x = car.x - car.rect.width car.y = car.y + car.rect.height current_crashes_number += 1 if crash: bound_alert_s.update() bound_alert_s.draw(screen) if target.time_left == 0: timer_alert_s.draw(screen) car.speed = 0 win = False if pygame.sprite.spritecollide(car, target_s, True): car.speed = 0 win = True collided = True if collided: win_alert_s.draw(screen) running = False screen.blit(text_timer, (CENTER_W - 600, CENTER_H - 300)) screen.blit(text_crashes_limit, (CENTER_W - 600, CENTER_H - 240)) pygame.display.flip() clock.tick(64) pygame.time.wait(1000) level3.main()
break # Level screen while True: press=pygame.key.get_pressed() for i in pygame.event.get(): if i.type==QUIT or press[K_q]: exit() screen.fill((0,0,0)) mousepress=pygame.mouse.get_pressed() l1=pygame.font.SysFont("comicsansms",50) l2=pygame.font.SysFont("comicsansms",30) l3=pygame.font.SysFont("comicsansms",30) l4=pygame.font.SysFont("comicsansms",30) r2=Rect((100,200),l2.size("Press 1 for Level 1 ")) r3=Rect((100,250),l3.size("Press 2 for Level 2 ")) r4=Rect((100,300),l3.size("Press 3 for Level 3 ")) screen.blit(l1.render("Select Your Level",True,(0,255,0)),(100,100)) screen.blit(l2.render("Press 1 for Level 1 ",True,(0,255,0)),(100,200)) screen.blit(l3.render("Press 2 for level 2 ",True,(0,255,0)),(100,250)) screen.blit(l4.render("Press 3 for level 3 ",True,(0,255,0)),(100,300)) pygame.display.update() if press[K_1] or (r2.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level1.main() if press[K_2] or (r3.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level2.main() if press[K_3] or (r4.collidepoint(pygame.mouse.get_pos()) and mousepress[0]): level3.main()
import os import glob from level3 import main if __name__ == '__main__': for fileInPath in glob.glob('data/in/*.in'): fileIn = open(fileInPath, "r") fileInBasename = os.path.basename(fileInPath); fileOut = open("data/out/" + fileInBasename + ".out", "w") fileInContent = fileIn.read() args = fileInContent.split(" ") print("Processing", fileInBasename + ": ", end="") out = main(args) fileOut.write("%s" % (out)) print("done")
def test_main_exit(self): inputs = self.cases[3]["input"] with self.assertRaises(SystemExit) as cm: level3.main([self, inputs["reviewee_id"], inputs["json_path"], \ inputs["lang"], inputs["deadline"]], "2017-04-26") self.assertEqual(cm.exception.code, 1)