def test_impossible_judges(): clear_db() add_round_stats(1,5,0,0) Debater.objects.create(name = "DebA", novice_status = 0) Debater.objects.create(name = "DebB", novice_status = 0) Debater.objects.create(name = "DebC", novice_status = 0) Debater.objects.create(name = "DebD", novice_status = 0) Debater.objects.create(name = "DebE", novice_status = 0) Debater.objects.create(name = "DebF", novice_status = 0) Debater.objects.create(name = "DebG", novice_status = 0) Debater.objects.create(name = "DebH", novice_status = 0) School.objects.create(name = "SchoolA") School.objects.create(name = "SchoolB") School.objects.create(name = "SchoolC") School.objects.create(name = "SchoolD") School.objects.create(name = "SchoolE") t = Team(name = "TeamA", school = School.objects.get(name = "SchoolA"), seed = 3) t.save() t.debaters = Debater.objects.get(name = "DebA"), Debater.objects.get(name = "DebB") t.save() t = Team(name = "TeamB", school = School.objects.get(name = "SchoolB"), seed = 2) t.save() t.debaters = Debater.objects.get(name = "DebC"), Debater.objects.get(name = "DebD") t.save() t = Team(name = "TeamC", school = School.objects.get(name = "SchoolC"), seed = 1) t.save() t.debaters = Debater.objects.get(name = "DebE"), Debater.objects.get(name = "DebF") t.save() t = Team(name = "TeamD", school = School.objects.get(name = "SchoolD"), seed = 0) t.save() t.debaters = Debater.objects.get(name = "DebG"), Debater.objects.get(name = "DebH") t.save() Room.objects.create(name = "RoomA", rank = 1) Room.objects.create(name = "RoomB", rank = 2) Judge.objects.create(name = "JudgeA", rank = 10, school = School.objects.get(name ="SchoolA")) Judge.objects.create(name = "JudgeD", rank = 0, school = School.objects.get(name = "SchoolD")) add_check_in(1) Scratch.objects.create(judge = Judge.objects.get(name = "JudgeA"), team = Team.objects.get(name = "TeamA"), scratch_type = 1) Scratch.objects.create(judge = Judge.objects.get(name = "JudgeD"), team = Team.objects.get(name = "TeamD"), scratch_type = 1) threwException = False try: tab_logic.pair_round() except errors.ToManyScratchesError: threwException = True finally: assert threwException == True
def test_scale(): create_tourney(100) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time-beg_time <=120 enter_results(1) r = TabSettings.objects.get(key = "cur_round") r.value = 2 r.save() add_check_in(2) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time-beg_time <=120 enter_results(2) r = TabSettings.objects.get(key = "cur_round") r.value = 3 r.save() add_check_in(3) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time-beg_time <=120 enter_results(3) r = TabSettings.objects.get(key = "cur_round") r.value = 4 r.save() add_check_in(4) beg_time = time.time() tab_logic.pair_round() end_time = time.time() print beg_time-end_time assert end_time-beg_time <=120 enter_results(4) r = TabSettings.objects.get(key = "cur_round") r.value = 5 r.save() add_check_in(5) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time-beg_time <=120 enter_results(5) r = TabSettings.objects.get(key = "cur_round") r.value = 6 r.save() beg_time = time.time() var_break() nov_break() var_speaks() nov_speaks() end_time = time.time() assert end_time-beg_time <=120
def test_scale(): create_tourney(100) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time - beg_time <= 120 enter_results(1) r = TabSettings.objects.get(key="cur_round") r.value = 2 r.save() add_check_in(2) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time - beg_time <= 120 enter_results(2) r = TabSettings.objects.get(key="cur_round") r.value = 3 r.save() add_check_in(3) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time - beg_time <= 120 enter_results(3) r = TabSettings.objects.get(key="cur_round") r.value = 4 r.save() add_check_in(4) beg_time = time.time() tab_logic.pair_round() end_time = time.time() print beg_time - end_time assert end_time - beg_time <= 120 enter_results(4) r = TabSettings.objects.get(key="cur_round") r.value = 5 r.save() add_check_in(5) beg_time = time.time() tab_logic.pair_round() end_time = time.time() assert end_time - beg_time <= 120 enter_results(5) r = TabSettings.objects.get(key="cur_round") r.value = 6 r.save() beg_time = time.time() var_break() nov_break() var_speaks() nov_speaks() end_time = time.time() assert end_time - beg_time <= 120
def test_not_enough_judges_ETE(): create_tourney(10) judges = Judge.objects.all() Judge.delete(judges[0]) threwException = False try: tab_logic.pair_round() except errors.NotEnoughJudgesError: threwException = True finally: assert threwException == True
def test_not_enough_rooms(): create_tourney(10) rooms = Room.objects.all() Room.delete(rooms[0]) threwException = False try: tab_logic.pair_round() except errors.NotEnoughRoomsError: threwException = True finally: assert threwException == True
def test_not_enough_judges_checked_in(): create_tourney(10) checked_in_judges = CheckIn.objects.all() CheckIn.delete(checked_in_judges[0]) threwException = False try: tab_logic.pair_round() except errors.NotEnoughJudgesError: threwException = True finally: assert threwException == True
def test_judge_corner(): clear_db() add_round_stats(1,5,0,0) Debater.objects.create(name = "DebA", novice_status = 0) Debater.objects.create(name = "DebB", novice_status = 0) Debater.objects.create(name = "DebC", novice_status = 0) Debater.objects.create(name = "DebD", novice_status = 0) Debater.objects.create(name = "DebE", novice_status = 0) Debater.objects.create(name = "DebF", novice_status = 0) Debater.objects.create(name = "DebG", novice_status = 0) Debater.objects.create(name = "DebH", novice_status = 0) School.objects.create(name = "SchoolA") School.objects.create(name = "SchoolB") School.objects.create(name = "SchoolC") School.objects.create(name = "SchoolD") School.objects.create(name = "SchoolE") t = Team(name = "TeamA", school = School.objects.get(name = "SchoolA"), seed = 3) t.save() t.debaters = Debater.objects.get(name = "DebA"), Debater.objects.get(name = "DebB") t.save() t = Team(name = "TeamB", school = School.objects.get(name = "SchoolB"), seed = 2) t.save() t.debaters = Debater.objects.get(name = "DebC"), Debater.objects.get(name = "DebD") t.save() t = Team(name = "TeamC", school = School.objects.get(name = "SchoolC"), seed = 1) t.save() t.debaters = Debater.objects.get(name = "DebE"), Debater.objects.get(name = "DebF") t.save() t = Team(name = "TeamD", school = School.objects.get(name = "SchoolD"), seed = 0) t.save() t.debaters = Debater.objects.get(name = "DebG"), Debater.objects.get(name = "DebH") t.save() Room.objects.create(name = "RoomA", rank = 1) Room.objects.create(name = "RoomB", rank = 2) Judge.objects.create(name = "JudgeA", rank = 10, school = School.objects.get(name ="SchoolA")) Judge.objects.create(name = "JudgeB", rank = 0, school = School.objects.get(name = "SchoolE")) add_check_in(1) Scratch.objects.create(judge = Judge.objects.get(name = "JudgeA"), team = Team.objects.get(name = "TeamA"), scratch_type = 1) tab_logic.pair_round() rounds = Round.objects.all() assert rounds[0].judge == Judge.objects.get(name = "JudgeB") assert rounds[1].judge == Judge.objects.get(name = "JudgeA")
def test_roundStats_object_missing(): create_tourney_judge_separate_school(10) tab_logic.pair_round() enter_results(1) add_check_in(2) rs = RoundStats.delete(RoundStats.objects.all()[0]) threwException = False try: tab_logic.ready_to_pair(2) except errors.PrevRoundNotEnteredError: threwException = True try: assert threwException == True except AssertionError: print "test_roundStats_object_missing FAILED" return False return True
def pair_round(request): cache_logic.clear_cache() current_round = TabSettings.objects.get(key="cur_round") next_round = current_round.value if request.method == 'POST': try: backup.backup_round("round_%i_before_pairing.db" % (next_round)) tab_logic.pair_round() backup.backup_round("round_%i_after_pairing.db" % (next_round)) except Exception, e: traceback.print_exc(file=sys.stdout) return render_to_response('error.html', {'error_type': "Pair Next Round", 'error_name': "Pairing Round %s" % (current_round.value + 1), 'error_info':"Could not pair next round because of: [%s]" %(e)}, context_instance=RequestContext(request)) current_round.value = current_round.value + 1 current_round.save() return view_status(request)
def test_no_victor_entered(): create_tourney_judge_separate_school(10) tab_logic.pair_round() enter_results(1) add_check_in(2) r = Round.objects.filter(round_number = 1)[0] r.victor = 0 r.save() threwException = False try: tab_logic.ready_to_pair(2) except errors.PrevRoundNotEnteredError: threwException = True try: assert threwException == True except AssertionError: print "test_no_victor_entered FAILED" return False return True
def test_no_victor_entered(): create_tourney_judge_separate_school(10) tab_logic.pair_round() enter_results(1) add_check_in(2) r = Round.objects.filter(round_number=1)[0] r.victor = 0 r.save() threwException = False try: tab_logic.ready_to_pair(2) except errors.PrevRoundNotEnteredError: threwException = True try: assert threwException == True except AssertionError: print "test_no_victor_entered FAILED" return False return True
def test_iron_man(): #Speaks are correct during round. #Ranking at end is correct (this is tested later so don't have to test here) random.seed(1) create_tourney(25) tab_logic.pair_round() enter_results_iron(1) r = TabSettings.objects.get(key = "cur_round") r.value = 2 r.save() add_check_in(2) tab_logic.pair_round() enter_results(2) r = TabSettings.objects.get(key = "cur_round") r.value = 3 r.save() add_check_in(3) tab_logic.pair_round() enter_results(3) r = TabSettings.objects.get(key = "cur_round") r.value = 4 r.save() add_check_in(4) tab_logic.pair_round() enter_results(4) r = TabSettings.objects.get(key = "cur_round") r.value = 5 r.save() add_check_in(5) tab_logic.pair_round() enter_results(5) check_results("ResultsIronMan.xls") r = TabSettings.objects.get(key = "cur_round") r.value = 6 r.save() var_break() nov_break() var_speaks() nov_speaks()
def test_iron_man(): #Speaks are correct during round. #Ranking at end is correct (this is tested later so don't have to test here) random.seed(1) create_tourney(25) tab_logic.pair_round() enter_results_iron(1) r = TabSettings.objects.get(key="cur_round") r.value = 2 r.save() add_check_in(2) tab_logic.pair_round() enter_results(2) r = TabSettings.objects.get(key="cur_round") r.value = 3 r.save() add_check_in(3) tab_logic.pair_round() enter_results(3) r = TabSettings.objects.get(key="cur_round") r.value = 4 r.save() add_check_in(4) tab_logic.pair_round() enter_results(4) r = TabSettings.objects.get(key="cur_round") r.value = 5 r.save() add_check_in(5) tab_logic.pair_round() enter_results(5) check_results("ResultsIronMan.xls") r = TabSettings.objects.get(key="cur_round") r.value = 6 r.save() var_break() nov_break() var_speaks() nov_speaks()
def test_odd(): random.seed(1) create_tourney(21) tab_logic.pair_round() enter_results(1) r = TabSettings.objects.get(key="cur_round") r.value = 2 r.save() add_check_in(2) tab_logic.pair_round() enter_results(2) r = TabSettings.objects.get(key="cur_round") r.value = 3 r.save() add_check_in(3) tab_logic.pair_round() enter_results(3) r = TabSettings.objects.get(key="cur_round") r.value = 4 r.save() add_check_in(4) tab_logic.pair_round() enter_results(4) r = TabSettings.objects.get(key="cur_round") r.value = 5 r.save() add_check_in(5) tab_logic.pair_round() enter_results(5) check_results("ResultsOdd.xls") r = TabSettings.objects.get(key="cur_round") r.value = 6 r.save() var_break() nov_break() var_speaks() nov_speaks()
def test_odd(): random.seed(1) create_tourney(21) tab_logic.pair_round() enter_results(1) r = TabSettings.objects.get(key = "cur_round") r.value = 2 r.save() add_check_in(2) tab_logic.pair_round() enter_results(2) r = TabSettings.objects.get(key = "cur_round") r.value = 3 r.save() add_check_in(3) tab_logic.pair_round() enter_results(3) r = TabSettings.objects.get(key = "cur_round") r.value = 4 r.save() add_check_in(4) tab_logic.pair_round() enter_results(4) r = TabSettings.objects.get(key = "cur_round") r.value = 5 r.save() add_check_in(5) tab_logic.pair_round() enter_results(5) check_results("ResultsOdd.xls") r = TabSettings.objects.get(key = "cur_round") r.value = 6 r.save() var_break() nov_break() var_speaks() nov_speaks()
def pair_round(request): cache_logic.clear_cache() current_round = TabSettings.objects.get(key="cur_round") next_round = current_round.value if request.method == 'POST': try: backup.backup_round("round_%i_before_pairing.db" % (next_round)) tab_logic.pair_round() backup.backup_round("round_%i_after_pairing.db" % (next_round)) except Exception, e: traceback.print_exc(file=sys.stdout) return render_to_response('error.html', { 'error_type': "Pair Next Round", 'error_name': "Pairing Round %s" % (current_round.value + 1), 'error_info': "Could not pair next round because of: [%s]" % (e) }, context_instance=RequestContext(request)) current_round.value = current_round.value + 1 current_round.save() return view_status(request)
def test_full_tourney(): #start a new tournament #Seed random number generator so that can verify correct results random.seed(0) clear_db() add_round_stats(1,5,4,2) #create 64 debaters for i in range(32): nov_stat1 = 0 nov_stat2 = 0 if i%3 == 0: #make some people novices nov_stat1 = 1 if i > 10: nov_stat2 = 1 Debater.objects.create(name = "Debater1fromT" + str(i), novice_status = nov_stat1) Debater.objects.create(name = "Debater2fromT" + str(i), novice_status = nov_stat2) #create 8 schools for i in range(8): School.objects.create(name = "School" + str(i)) #create host school for scratch/judge purposes School.objects.create(name = "HostSchool") #create 32 teams for i in range(32): school_num = i%8 mySchool = School.objects.get(name = "School" + str(school_num)) t = Team(name = "Team" + str(i), school = mySchool, seed = i%4) t.save() deb1 = Debater.objects.get(name = "Debater" + str(1) + "fromT" + str(i)) deb2 = Debater.objects.get(name = "Debater" + str(2) + "fromT" + str(i)) t.debaters = deb1, deb2 t.save() #add some rooms add_rooms(32) #add judges #add 16 judges from host school for i in range(8): Judge.objects.create(name = "JudgeFromHost" + str(i), rank = i, school = School.objects.get(name = "HostSchool")) #add 2 judges from each competeing school for i in range(8): Judge.objects.create(name = "JudgeFromSchool" + str(i), rank = i*2+.3, school = School.objects.get(name = "School" + str(i))) #check in all judges add_check_in(1) #pair first round tab_logic.pair_round() #Check that all full seed teams are hitting unseeded and all free seeds are hitting half-seeds for p in Round.objects.filter(round_number = 1): if p.gov_team.seed == 0: assert p.opp_team.seed == 3 elif p.gov_team.seed == 1: assert p.opp_team.seed == 2 elif p.gov_team.seed == 2: assert p.opp_team.seed == 1 else: assert p.opp_team.seed == 0 #That judge and both teams are from different schools assert p.judge.school != p.gov_team.school assert p.judge.school != p.opp_team.school assert p.gov_team.school != p.opp_team.school #Check that scratches are obeyed assert len(Scratch.objects.filter(judge = p.judge, team = p.gov_team)) == 0 assert len(Scratch.objects.filter(judge = p.judge, team = p.opp_team)) == 0 add_check_in(2) try: tab_logic.ready_to_pair(2) except errors.PrevRoundNotEnteredError: assert True else: assert False enter_results(1) #Check that results are as expected #check_results() r = TabSettings.objects.get(key = "cur_round") r.value = 2 r.save() tab_logic.pair_round() enter_results(2) r = TabSettings.objects.get(key = "cur_round") r.value = 3 r.save() add_check_in(3) tab_logic.pair_round() enter_results(3) r = TabSettings.objects.get(key = "cur_round") r.value = 4 r.save() add_check_in(4) tab_logic.pair_round() enter_results(4) r = TabSettings.objects.get(key = "cur_round") r.value = 5 r.save() add_check_in(5) tab_logic.pair_round() enter_results(5) check_results("ResultsOfTournament.xls") var_break() nov_break() var_speaks() nov_speaks()
def test_full_tourney(): #start a new tournament #Seed random number generator so that can verify correct results random.seed(0) clear_db() add_round_stats(1, 5, 4, 2) #create 64 debaters for i in range(32): nov_stat1 = 0 nov_stat2 = 0 if i % 3 == 0: #make some people novices nov_stat1 = 1 if i > 10: nov_stat2 = 1 Debater.objects.create(name="Debater1fromT" + str(i), novice_status=nov_stat1) Debater.objects.create(name="Debater2fromT" + str(i), novice_status=nov_stat2) #create 8 schools for i in range(8): School.objects.create(name="School" + str(i)) #create host school for scratch/judge purposes School.objects.create(name="HostSchool") #create 32 teams for i in range(32): school_num = i % 8 mySchool = School.objects.get(name="School" + str(school_num)) t = Team(name="Team" + str(i), school=mySchool, seed=i % 4) t.save() deb1 = Debater.objects.get(name="Debater" + str(1) + "fromT" + str(i)) deb2 = Debater.objects.get(name="Debater" + str(2) + "fromT" + str(i)) t.debaters = deb1, deb2 t.save() #add some rooms add_rooms(32) #add judges #add 16 judges from host school for i in range(8): Judge.objects.create(name="JudgeFromHost" + str(i), rank=i, school=School.objects.get(name="HostSchool")) #add 2 judges from each competeing school for i in range(8): Judge.objects.create(name="JudgeFromSchool" + str(i), rank=i * 2 + .3, school=School.objects.get(name="School" + str(i))) #check in all judges add_check_in(1) #pair first round tab_logic.pair_round() #Check that all full seed teams are hitting unseeded and all free seeds are hitting half-seeds for p in Round.objects.filter(round_number=1): if p.gov_team.seed == 0: assert p.opp_team.seed == 3 elif p.gov_team.seed == 1: assert p.opp_team.seed == 2 elif p.gov_team.seed == 2: assert p.opp_team.seed == 1 else: assert p.opp_team.seed == 0 #That judge and both teams are from different schools assert p.judge.school != p.gov_team.school assert p.judge.school != p.opp_team.school assert p.gov_team.school != p.opp_team.school #Check that scratches are obeyed assert len(Scratch.objects.filter(judge=p.judge, team=p.gov_team)) == 0 assert len(Scratch.objects.filter(judge=p.judge, team=p.opp_team)) == 0 add_check_in(2) try: tab_logic.ready_to_pair(2) except errors.PrevRoundNotEnteredError: assert True else: assert False enter_results(1) #Check that results are as expected #check_results() r = TabSettings.objects.get(key="cur_round") r.value = 2 r.save() tab_logic.pair_round() enter_results(2) r = TabSettings.objects.get(key="cur_round") r.value = 3 r.save() add_check_in(3) tab_logic.pair_round() enter_results(3) r = TabSettings.objects.get(key="cur_round") r.value = 4 r.save() add_check_in(4) tab_logic.pair_round() enter_results(4) r = TabSettings.objects.get(key="cur_round") r.value = 5 r.save() add_check_in(5) tab_logic.pair_round() enter_results(5) check_results("ResultsOfTournament.xls") var_break() nov_break() var_speaks() nov_speaks()
def test_judge_corner(): clear_db() add_round_stats(1, 5, 0, 0) Debater.objects.create(name="DebA", novice_status=0) Debater.objects.create(name="DebB", novice_status=0) Debater.objects.create(name="DebC", novice_status=0) Debater.objects.create(name="DebD", novice_status=0) Debater.objects.create(name="DebE", novice_status=0) Debater.objects.create(name="DebF", novice_status=0) Debater.objects.create(name="DebG", novice_status=0) Debater.objects.create(name="DebH", novice_status=0) School.objects.create(name="SchoolA") School.objects.create(name="SchoolB") School.objects.create(name="SchoolC") School.objects.create(name="SchoolD") School.objects.create(name="SchoolE") t = Team(name="TeamA", school=School.objects.get(name="SchoolA"), seed=3) t.save() t.debaters = Debater.objects.get(name="DebA"), Debater.objects.get( name="DebB") t.save() t = Team(name="TeamB", school=School.objects.get(name="SchoolB"), seed=2) t.save() t.debaters = Debater.objects.get(name="DebC"), Debater.objects.get( name="DebD") t.save() t = Team(name="TeamC", school=School.objects.get(name="SchoolC"), seed=1) t.save() t.debaters = Debater.objects.get(name="DebE"), Debater.objects.get( name="DebF") t.save() t = Team(name="TeamD", school=School.objects.get(name="SchoolD"), seed=0) t.save() t.debaters = Debater.objects.get(name="DebG"), Debater.objects.get( name="DebH") t.save() Room.objects.create(name="RoomA", rank=1) Room.objects.create(name="RoomB", rank=2) Judge.objects.create(name="JudgeA", rank=10, school=School.objects.get(name="SchoolA")) Judge.objects.create(name="JudgeB", rank=0, school=School.objects.get(name="SchoolE")) add_check_in(1) Scratch.objects.create(judge=Judge.objects.get(name="JudgeA"), team=Team.objects.get(name="TeamA"), scratch_type=1) tab_logic.pair_round() rounds = Round.objects.all() assert rounds[0].judge == Judge.objects.get(name="JudgeB") assert rounds[1].judge == Judge.objects.get(name="JudgeA")
def test_impossible_judges(): clear_db() add_round_stats(1, 5, 0, 0) Debater.objects.create(name="DebA", novice_status=0) Debater.objects.create(name="DebB", novice_status=0) Debater.objects.create(name="DebC", novice_status=0) Debater.objects.create(name="DebD", novice_status=0) Debater.objects.create(name="DebE", novice_status=0) Debater.objects.create(name="DebF", novice_status=0) Debater.objects.create(name="DebG", novice_status=0) Debater.objects.create(name="DebH", novice_status=0) School.objects.create(name="SchoolA") School.objects.create(name="SchoolB") School.objects.create(name="SchoolC") School.objects.create(name="SchoolD") School.objects.create(name="SchoolE") t = Team(name="TeamA", school=School.objects.get(name="SchoolA"), seed=3) t.save() t.debaters = Debater.objects.get(name="DebA"), Debater.objects.get( name="DebB") t.save() t = Team(name="TeamB", school=School.objects.get(name="SchoolB"), seed=2) t.save() t.debaters = Debater.objects.get(name="DebC"), Debater.objects.get( name="DebD") t.save() t = Team(name="TeamC", school=School.objects.get(name="SchoolC"), seed=1) t.save() t.debaters = Debater.objects.get(name="DebE"), Debater.objects.get( name="DebF") t.save() t = Team(name="TeamD", school=School.objects.get(name="SchoolD"), seed=0) t.save() t.debaters = Debater.objects.get(name="DebG"), Debater.objects.get( name="DebH") t.save() Room.objects.create(name="RoomA", rank=1) Room.objects.create(name="RoomB", rank=2) Judge.objects.create(name="JudgeA", rank=10, school=School.objects.get(name="SchoolA")) Judge.objects.create(name="JudgeD", rank=0, school=School.objects.get(name="SchoolD")) add_check_in(1) Scratch.objects.create(judge=Judge.objects.get(name="JudgeA"), team=Team.objects.get(name="TeamA"), scratch_type=1) Scratch.objects.create(judge=Judge.objects.get(name="JudgeD"), team=Team.objects.get(name="TeamD"), scratch_type=1) threwException = False try: tab_logic.pair_round() except errors.ToManyScratchesError: threwException = True finally: assert threwException == True