def test_slice_list(): lst = [1, 3, 4, 5, 7, 9, 10] lst2 = list(range(9)) assert grouper.slice_list(lst, 2) == [[1, 3], [4, 5], [7, 9], [10]] assert grouper.slice_list(lst, 1) == [[1], [3], [4], [5], [7], [9], [10]] assert grouper.slice_list(lst, 3) == [[1, 3, 4], [5, 7, 9], [10]] assert grouper.slice_list(lst, 6) == [[1, 3, 4, 5, 7, 9], [10]]
def test_str(self, students): new_grouping = grouper.Grouping() group_list = grouper.slice_list(students, 2) for group in group_list: new_grouping.add_group(grouper.Group(group)) grouping_string = str(new_grouping) for group in new_grouping.get_groups(): for student in group.get_members(): assert student.name in grouping_string
def test_slice_list_even(self): big_list_even = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] small_list_even = [0, 1] sliced = grouper.slice_list(big_list_even, 2) for sublist in sliced: assert len(sublist) == 2 win = grouper.slice_list(big_list_even, 3) for i in range(0, len(win)): if i == (len(win) - 1): assert len(win[i]) <= 3 assert len(win[i]) != 0 else: assert len(win[i]) == 3 win = grouper.slice_list(small_list_even, 2) assert len(win[0]) == 2 assert len(win) == 1 win = grouper.slice_list(small_list_even, 1) assert len(win) == 2
def test_slicing(self): assert grouper.slice_list([], 2) == [] assert grouper.slice_list([1, 2, 3, 4, 5], 10) == [[1, 2, 3, 4, 5]] assert grouper.slice_list([1, 2, 3, 4, 5, 6], 2) == [[1, 2], [3, 4], [5, 6]] assert grouper.slice_list([1, 2, 3, 4, 5], 2) == [[1, 2], [3, 4], [5]] assert grouper.slice_list([1, 2, 3, 4, 5, 6], 3) == [[1, 2, 3], [4, 5, 6]] assert grouper.slice_list([1, 2, 3, 4, 5], 3) == [[1, 2, 3], [4, 5]]
def test_slice_list_odd(self): big_list_odd = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] small_list_odd = [0] sliced = grouper.slice_list(big_list_odd, 2) for i in range(0, len(sliced)): if i == (len(sliced) - 1): assert len(sliced[i]) == 1 else: assert len(sliced[i]) == 2 win = grouper.slice_list(big_list_odd, 3) for i in range(0, len(win)): if i == (len(win) - 1): assert len(win[i]) <= 3 assert len(win[i]) != 0 else: assert len(win[i]) == 3 win = grouper.slice_list(small_list_odd, 1) assert len(win[0]) == 2 assert len(win) == 1 win = grouper.slice_list(small_list_odd, 1) assert len(win) == 2
def test_slice_list_odd(self): big_list_odd = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] small_list_odd = [0] sliced = grouper.windows(big_list_odd, 2) assert [] not in sliced for i in range(0, len(sliced)): assert len(sliced[i]) == 2 win = grouper.windows(big_list_odd, 3) for i in range(0, len(win)): assert len(win[i]) == 3 win = grouper.windows(small_list_odd, 2) assert len(win[0]) == 1 assert len(win) == 1 win = grouper.slice_list(small_list_odd, 1) assert len(win) == 1
def test_slice_list() -> None: lst = list(range(7)) assert grouper.slice_list(lst, 3) == [[0, 1, 2], [3, 4, 5], [6]]
def test_grouper_slice_list() -> None: lst = [1, [1, 2, 4], 'Jennifer', False, [True, False], 3, 4] assert grouper.slice_list(lst, 1) == [[1], [[1, 2, 4]], ['Jennifer'], [False], [[True, False]], [3], [4]] assert grouper.slice_list(lst, 3) == [[1, [1, 2, 4], 'Jennifer'], [False, [True, False], 3], [4]]
def test_slice_list() -> None: assert grouper.slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]] assert grouper.slice_list(['a', 1, 6.0, False], 3) \ == [['a', 1, 6.0], [False]]
def test_slice_list() -> None: lst = list(range(5)) assert grouper.slice_list(lst, 2) == [[0, 1], [2, 3], [4]]
def test_grouper_slice_list() -> None: """A test for helper function slice_list().""" assert slice_list([1, 2, 3, 4, 5], 2) == [[1, 2], [3, 4], [5]]
def test_slice_empty(self): lst = [] assert slice_list(lst, 0) == [[]]
def test_slice(self): lst = list(range(10)) assert slice_list(lst, 5) == [[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
def test_grouper() -> None: assert windows([3, 4, 6, 2, 3], 2) == [[3, 4], [4, 6], [6, 2], [2, 3]] assert windows(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [1, 6.0, False]] assert slice_list([3, 4, 6, 2, 3], 2) == [[3, 4], [6, 2], [3]] assert slice_list(['a', 1, 6.0, False], 3) == [['a', 1, 6.0], [False]] g = Group([Student(1, "roney"), Student(2, "tim"), Student(3, "allen")]) g_1 = Group([Student(1, "roney"), Student(2, "tim"), Student(3, "allen")]) g_2 = Group([Student(5, "roney"), Student(6, "tim"), Student(7, "allen")]) assert len(g) == 3 assert Student(1, "roney") in g assert "roney" in str(g) gr = Grouping() assert gr.add_group(g) assert not gr.add_group(g_1) assert gr.add_group(g_2) assert len(gr) == 2 course_0 = Course("Snake") course_0.enroll_students( [Student(1, "a"), Student(2, "b"), Student(3, "c")]) s = Survey([YesNoQuestion(1, "Is earth round")]) ag = AlphaGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 course_0 = Course("Snake") course_0.enroll_students( [Student(1, "a"), Student(2, "b"), Student(3, "c")]) s = Survey([YesNoQuestion(1, "Is earth round")]) ag = AlphaGrouper(3) gr = ag.make_grouping(course_0, s) assert len(gr) == 1 course_0 = Course("Snake") course_0.enroll_students( [Student(1, "a"), Student(2, "b"), Student(3, "c")]) s = Survey([YesNoQuestion(1, "Is earth round")]) ag = RandomGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 course_0 = Course("Snake") course_0.enroll_students( [Student(1, "a"), Student(2, "b"), Student(3, "c")]) s = Survey([YesNoQuestion(1, "Is earth round")]) ag = RandomGrouper(3) gr = ag.make_grouping(course_0, s) assert len(gr) == 1 course_0 = Course("Snake") s1 = Student(1, "a") s2 = Student(2, "b") s3 = Student(3, "c") q = YesNoQuestion(1, "Is earth round") s1.set_answer(q, Answer(True)) s2.set_answer(q, Answer(False)) s3.set_answer(q, Answer(True)) course_0.enroll_students([s1, s2, s3]) s = Survey([q]) ag = GreedyGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 course_0 = Course("Snake") s1 = Student(1, "a") s2 = Student(2, "b") s3 = Student(3, "c") q = YesNoQuestion(1, "Is earth round") s1.set_answer(q, Answer(True)) s2.set_answer(q, Answer(False)) s3.set_answer(q, Answer(True)) course_0.enroll_students([s1, s2, s3]) s = Survey([q]) ag = GreedyGrouper(3) gr = ag.make_grouping(course_0, s) assert len(gr) == 1 groups = gr.get_groups() assert groups[0]._member_id == [1, 3, 2] course_0 = Course("Snake") s1 = Student(1, "a") s2 = Student(2, "b") s3 = Student(3, "c") q = YesNoQuestion(1, "Is earth round") s1.set_answer(q, Answer(True)) s2.set_answer(q, Answer(False)) s3.set_answer(q, Answer(True)) course_0.enroll_students([s1, s2, s3]) s = Survey([q]) s.set_criterion(LonelyMemberCriterion(), q) ag = GreedyGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 groups = gr.get_groups() assert groups[0]._member_id == [1, 3] assert groups[1]._member_id == [2] course_0 = Course("Snake") s1 = Student(1, "a") s2 = Student(2, "b") s3 = Student(3, "c") s4 = Student(4, "d") q = YesNoQuestion(1, "Is earth round") s1.set_answer(q, Answer(True)) s2.set_answer(q, Answer(True)) s3.set_answer(q, Answer(True)) s4.set_answer(q, Answer(True)) course_0.enroll_students([s1, s2, s3, s4]) s = Survey([q]) s.set_criterion(LonelyMemberCriterion(), q) ag = WindowGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 groups = gr.get_groups() assert groups[0]._member_id == [1, 2] assert groups[1]._member_id == [3, 4] course_0 = Course("Snake") s1 = Student(1, "a") s2 = Student(2, "b") s3 = Student(3, "c") s4 = Student(4, "d") q = YesNoQuestion(1, "Is earth round") s1.set_answer(q, Answer(True)) s2.set_answer(q, Answer(False)) s3.set_answer(q, Answer(True)) s4.set_answer(q, Answer(False)) course_0.enroll_students([s1, s2, s3, s4]) s = Survey([q]) s.set_criterion(HeterogeneousCriterion(), q) ag = WindowGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 groups = gr.get_groups() assert groups[0]._member_id == [1, 2] assert groups[1]._member_id == [3, 4] course_0 = Course("Snake") s1 = Student(1, "a") s2 = Student(2, "b") s3 = Student(3, "c") s4 = Student(4, "d") q = YesNoQuestion(1, "Is earth round") s1.set_answer(q, Answer(True)) s2.set_answer(q, Answer(False)) s3.set_answer(q, Answer(True)) s4.set_answer(q, Answer(False)) course_0.enroll_students([s1, s2, s3, s4]) s = Survey([q]) s.set_criterion(HomogeneousCriterion(), q) ag = WindowGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 groups = gr.get_groups() assert groups[0]._member_id == [1, 2] assert groups[1]._member_id == [3, 4] course_0 = Course("Snake") s1 = Student(1, "a") s2 = Student(2, "b") s3 = Student(3, "c") s4 = Student(4, "d") q = YesNoQuestion(1, "Is earth round") s1.set_answer(q, Answer(True)) s2.set_answer(q, Answer(False)) s3.set_answer(q, Answer(False)) s4.set_answer(q, Answer(False)) course_0.enroll_students([s1, s2, s3, s4]) s = Survey([q]) s.set_criterion(HomogeneousCriterion(), q) ag = WindowGrouper(2) gr = ag.make_grouping(course_0, s) assert len(gr) == 2 groups = gr.get_groups() assert groups[0]._member_id == [2, 3] assert groups[1]._member_id == [1, 4]
def test_len(self, students): new_grouping = grouper.Grouping() group_list = grouper.slice_list(students, 2) for group in group_list: new_grouping.add_group(grouper.Group(group)) assert len(new_grouping) == 4