def testGen(self): seat = algo.generateSeats() def check(arr): num_list = [] if len(arr) != 6 or len(arr[0]) != 7: return False if arr[5][0] != 0 or arr[5][1] != 0 or arr[5][5] != 0 or arr[5][ 5] != 0 or arr[5][6] != 0: return False for i in range(len(arr)): for j in range(len(arr[0])): if arr[i][j] != 0: num_list.append(arr[i][j]) num_list = set(num_list) return len(num_list) == 38 self.assertTrue(check(seat))
help_msg = '''Please provide mode! generate - generate a random seat switch <no1> <no2> - switch seats of two students run - apply requirements export - export requirements to requirements.txt print - print the current seat debug - dry run''' if __name__ == "__main__": if len(sys.argv) <= 1 or sys.argv[1] == "help": print(help_msg) sys.exit(1 if len(sys.argv) <= 1 else 0) else: mode = sys.argv[1] if mode == "generate": seats = Seat(generateSeats()) printArr(seats.seats) seats.save() print("Done!") elif mode == "run" or mode == "debug": seats = Seat() print("Original:") printArr(seats.seats) seats.apply_requirements() print("Result:") printArr(seats.seats) # save if mode == "run":
print("Please input with the correct format:\npython "+__file__+" [number to find] [times to analyse] [filename of requirements(optional)]") exit(1) try: filename=argv[3] except: filename="requirements.txt" reqs=read_reqs(filename) poss_rand=np.zeros((6,7)) poss_swap=np.zeros((6,7)) poss_push=np.zeros((6,7)) poss_inst=np.zeros((6,7)) poss=[poss_rand, poss_swap, poss_push, poss_inst] for _ in range(times): luckier=randrange(len(reqs)) reqs=reqs[luckier:]+reqs[:luckier] swap=algo.generateSeats() #swap serves as random seat at first, and then does its work push=dp(swap) inst=dp(swap) i_index, j_index=find(swap, number) poss_rand[i_index][j_index]+=1 swap=execute(swap, reqs, methods.swap()) i_index, j_index=find(swap, number) poss_swap[i_index][j_index]+=1 push=execute(push, reqs, methods.push()) i_index, j_index=find(push, number) poss_push[i_index][j_index]+=1 inst=execute(inst, reqs, methods.inst()) i_index, j_index=find(inst, number) poss_inst[i_index][j_index]+=1 print('data generated this time:') filname='data'