def test_group_random1(): """Testing that the group_random() function creates the appropriate number of groups with the appropriate number""" lst = [ "Austin", "Dan", "Angie", "Cullen", "Chase", "Vinny", "Nick", "Jeff", "James", "Kelly", "Nikki", "Robert", ] lst2 = ["Dan", "Angie", "Austin", "Izaak", "Nick", "Jeff"] group_size = 3 group_size2 = 2 num_group = 2 num_group2 = 3 actual_output = group_creation.group_random_group_size(lst, group_size) actual_output2 = group_creation.group_random_group_size(lst2, group_size2) actual_output3 = group_creation.group_random_num_group(lst, num_group) actual_output4 = group_creation.group_random_num_group(lst2, num_group2) assert len(actual_output) == 4 assert len(actual_output[0]) == 3 assert len(actual_output2) == 3 assert len(actual_output2[0]) == 2 assert len(actual_output3) == 2 assert len(actual_output3[0]) == 6 assert len(actual_output4) == 3 assert len(actual_output4[0]) == 2
def input_interface( students, method=None, num_group=None, preferences=None, preferences_weight=None, preferences_weight_match=None, objective_weights=None, objective_measures=None, ): """ Run conditional logic statment to ran different methods """ students_reshuffle = group_creation.shuffle_students(students) if method == constants.ALGORITHM_ROUND_ROBIN: # Note that this only checks the first student if len(students_reshuffle[0]) < 2: grouped_students = group_creation.group_random_num_group( students_reshuffle, num_group) else: grouped_students = group_creation.group_rrobin_num_group( students_reshuffle, num_group) elif method == constants.ALGORITHM_GRAPH: grouped_students = group_graph.group_graph_partition( students_reshuffle, num_group, preferences=preferences, preferences_weight=preferences_weight, preferences_weight_match=preferences_weight_match, objective_weights=objective_weights, objective_measures=objective_measures, ) else: grouped_students = group_creation.group_random_num_group( students_reshuffle, num_group) return grouped_students
def test_hypothesis_group_random(numgrp): """Testing the random type of grouping with everyone in an assigned group with hypothesis""" responses = [ ["Nick", True, False, True, False], ["Marvin", False, False, True, True], ["Evin", True, True, True, False], ["Nikki", True, True, False, False], ["Dan", False, True, False, True], ["Michael", True, True, False, False], ] num_group = numgrp returned_groups1 = group_creation.group_random_num_group( responses, num_group) assert len(returned_groups1[0]) == len(responses) / num_group
def test_group_random_extra(): """Testing the random type of grouping with a group of extra people not assigned to their own group""" responses = [ ["Nick", True, False, True, False], ["Marvin", False, False, True, True], ["Evin", True, True, True, False], ["Nikki", True, True, False, False], ["Dan", False, True, False, True], ] num_group = 2 returned_groups1 = group_creation.group_random_num_group( responses, num_group) assert len(returned_groups1) == 2 assert num_group == 2
def test_group_random(): """Testing the random type of grouping with everyone in an assigned group""" responses = [ ["Nick", True, False, True, False], ["Marvin", False, False, True, True], ["Evin", True, True, True, False], ["Nikki", True, True, False, False], ["Dan", False, True, False, True], ["Michael", True, True, False, False], ] grpsize = 2 num_group = 3 returned_groups = group_creation.group_random_group_size( responses, grpsize) returned_groups1 = group_creation.group_random_num_group( responses, num_group) assert len(returned_groups) == 3 assert len(returned_groups1[0]) == 2
def test_hypothesis_random(numgrp): """Testing the random grouping function to assure proper output""" lst = [ ["Dan", True, True, True], ["Jesse", True, True, True], ["Austin", True, True, True], ["Nick", False, False, False], ["Nikki", False, False, False], ["Maria", False, False, False], ["Jeff", False, False, False], ["Simon", False, False, False], ["Jon", False, False, False], ["Angie", False, False, False], ["Izaak", False, False, False], ["Jacob", False, False, False], ] num_group = numgrp actual_output1 = group_creation.group_random_num_group(lst, num_group) assert len(actual_output1) == num_group assert len(actual_output1[0]) == len(lst) / numgrp
def test_group_random_conflict_numgrp(): """ Test that groups are still created randomly, even when given conflict tuples as input. Note that there is no guarantee that a conflict will be avoided, but rather that it is more likely that the conflict will be avoided than it won't. Perfect group creation with guaranteed conflict avoidance is an NP-Hard problem. To test that conflict management is effective at least most of the time (>90%), groups will be generated multiple times, and results will be collected as a 0 (conflict avoided) or 1 (conflict still present), and the test case will pass as long as more than 90% of the results as a 0 and not a 1. """ responses = [ ["Nick", True, False, True, False], ["Marvin", False, False, True, True], ["Evin", True, True, True, False], ["Nikki", True, True, False, False], ["Dan", False, True, False, True], ["Michael", True, True, False, False], ] num_group = 3 # A conflict is added. conflict = ("Nick", "Marvin", 5) results = [] # Run 1000 tests for significance for _x in range(0, 1000): returned_groups = group_creation.group_random_num_group( responses, num_group) for grp in returned_groups: # if both members of the conflict relation are in a group, avoidance failed if (conflict[0] in grp) and (conflict[1] in grp): # 1 denotes conflict avoidance failure results.append(1) else: # 0 denotes conflict avoidance failure results.append(0) # calculate the average of the results results_avg = sum(results) / len(results) # assert that the success rate of conflict avoidance is 90% minimum assert results_avg < 0.9
def test_random(): """Testing the random grouping function to assure proper output""" lst = [ ["Dan", True, True, True], ["Jesse", True, True, True], ["Austin", True, True, True], ["Nick", False, False, False], ["Nikki", False, False, False], ["Maria", False, False, False], ["Jeff", False, False, False], ["Simon", False, False, False], ["Jon", False, False, False], ["Angie", False, False, False], ["Izaak", False, False, False], ["Jacob", False, False, False], ] group_size = 4 num_group = 3 actual_output = group_creation.group_random_group_size(lst, group_size) actual_output1 = group_creation.group_random_num_group(lst, num_group) assert len(actual_output) == 3 assert len(actual_output[0]) == 4 assert len(actual_output1) == 3 assert len(actual_output1[0]) == 4