def test_grade_returns_the_students_in_that_grade_in_alphabetical_order(self): school = School() school.add_student(name="Franklin", grade=5) school.add_student(name="Bradley", grade=5) school.add_student(name="Jeff", grade=1) expected = ["Bradley", "Franklin"] self.assertEqual(school.grade(5), expected)
def test_students_are_sorted_by_name_in_a_grade(self): school = School() school.add_student(name="Franklin", grade=5) school.add_student(name="Bradley", grade=5) school.add_student(name="Jeff", grade=1) expected = ["Bradley", "Franklin"] self.assertEqual(school.grade(5), expected)
def test_adding_more_student_adds_them_to_the_sorted_roster(self): school = School() school.add_student(name="Blair", grade=2) school.add_student(name="Paul", grade=2) school.add_student(name="James", grade=2) expected = ["Blair", "James", "Paul"] self.assertEqual(school.roster(), expected)
def test_grade_returns_students_in_that_grade_in_alphabetical_order(self): school = School() school.add_student(name='Franklin', grade=5) school.add_student(name='Bradley', grade=5) school.add_student(name='Jeff', grade=1) expected = ['Bradley', 'Franklin'] self.assertEqual(school.grade(5), expected)
def test_cannot_add_student_to_same_grade_in_the_roster_more_than_once(self): school = School() school.add_student(name="Blair", grade=2) school.add_student(name="James", grade=2) school.add_student(name="James", grade=2) school.add_student(name="Paul", grade=2) expected = [True, True, False, True] self.assertEqual(school.added(), expected)
def test_student_not_added_to_other_grade_for_multiple_grades(self): school = School() school.add_student(name="Blair", grade=2) school.add_student(name="James", grade=2) school.add_student(name="James", grade=3) school.add_student(name="Paul", grade=3) expected = ["Paul"] self.assertEqual(school.grade(3), expected)
def test_student_not_added_to_same_grade_more_than_once(self): school = School() school.add_student(name="Blair", grade=2) school.add_student(name="James", grade=2) school.add_student(name="James", grade=2) school.add_student(name="Paul", grade=2) expected = ["Blair", "James", "Paul"] self.assertEqual(school.grade(2), expected)
def test_students_are_sorted_by_name_in_the_roster(self): school = School() school.add_student(name="Peter", grade=2) school.add_student(name="Zoe", grade=2) school.add_student(name="Alex", grade=2) expected = ["Alex", "Peter", "Zoe"] self.assertEqual(school.roster(), expected)
def test_cannot_add_same_student_to_multiple_grades_in_the_roster(self): school = School() school.add_student(name="Blair", grade=2) school.add_student(name="James", grade=2) school.add_student(name="James", grade=3) school.add_student(name="Paul", grade=3) expected = [True, True, False, True] self.assertEqual(school.added(), expected)
def test_students_are_sorted_by_grades_in_the_roster(self): school = School() school.add_student(name="Jim", grade=3) school.add_student(name="Peter", grade=2) school.add_student(name="Anna", grade=1) expected = ["Anna", "Peter", "Jim"] self.assertEqual(school.roster(), expected)
def test_student_not_added_to_multiple_grades_in_the_roster(self): school = School() school.add_student(name="Blair", grade=2) school.add_student(name="James", grade=2) school.add_student(name="James", grade=3) school.add_student(name="Paul", grade=3) expected = ["Blair", "James", "Paul"] self.assertEqual(school.roster(), expected)
def test_roster_is_sorted_by_grade_then_name(self): school = School() for name, grade in [ ('Peter', 2), ('Anna', 1), ('Barb', 1), ('Zoe', 2), ('Alex', 2), ('Jim', 3), ('Charlie', 1), ]: school.add_student(name, grade) expected = ['Anna', 'Barb', 'Charlie', 'Alex', 'Peter', 'Zoe', 'Jim'] self.assertEqual(school.roster(), expected)
def test_roster_is_sorted_by_grade_then_name(self): school = School() for name, grade in [ ("Peter", 2), ("Anna", 1), ("Barb", 1), ("Zoe", 2), ("Alex", 2), ("Jim", 3), ("Charlie", 1), ]: school.add_student(name, grade) expected = ["Anna", "Barb", "Charlie", "Alex", "Peter", "Zoe", "Jim"] self.assertEqual(school.roster(), expected)
def test_students_in_multiple_grades_are_added_to_the_roster(self): school = School() school.add_student(name="Chelsea", grade=3) school.add_student(name="Logan", grade=7) expected = ["Chelsea", "Logan"] self.assertEqual(school.roster(), expected)
def test_adding_students(self): school = School() school.add_student(name="Aimee", grade=2) school.add_student(name="Amine", grade=2) school.add_student(name="Magmine", grade=2) expected = ["Aimee", "Amine", "Magmine"] self.assertEqual(school.grade(2), expected)
def test_adding_students_to_different_grades_adds_them_to_the_same_sorted_roster( self): school = School() school.add_student(name="Chelsea", grade=3) school.add_student(name="Logan", grade=7) expected = ["Chelsea", "Logan"] self.assertEqual(school.roster(), expected)
def test_adding_more_students_adds_them_to_sorted_roster(self): school = School() school.add_student(name='Blair', grade=2) school.add_student(name='James', grade=2) school.add_student(name='Paul', grade=2) expected = ['Blair', 'James', 'Paul'] self.assertEqual(school.roster(), expected)
def test_student_names_with_grades_are_displayed_in_the_same_sorted_roster( self): school = School() school.add_student(name="Peter", grade=2) school.add_student(name="Anna", grade=1) school.add_student(name="Barb", grade=1) school.add_student(name="Zoe", grade=2) school.add_student(name="Alex", grade=2) school.add_student(name="Jim", grade=3) school.add_student(name="Charlie", grade=1) expected = ["Anna", "Barb", "Charlie", "Alex", "Peter", "Zoe", "Jim"] self.assertEqual(school.roster(), expected)
def test_roster_returns_an_empty_list_if_there_are_no_students_enrolled( self): school = School() expected = [] self.assertEqual(school.roster(), expected)
def test_adding_student_adds_them_to_sorted_roster(self): school = School() school.add_student(name='Aimee', grade=2) expected = ['Aimee'] self.assertEqual(school.roster(), expected)
class SchoolTest(unittest.TestCase): def setUp(self): # assertCountEqual is py3, py2 only knowns assetItemsEqual if not hasattr(self, 'assertCountEqual'): self.assertCountEqual = self.assertItemsEqual self.school = School("Haleakala Hippy School") def test_an_empty_school(self): for n in range(1, 9): self.assertCountEqual(set(), self.school.grade(n)) def test_add_student(self): self.school.add("Aimee", 2) self.assertCountEqual(("Aimee",), self.school.grade(2)) def test_add_more_students_in_same_class(self): self.school.add("James", 2) self.school.add("Blair", 2) self.school.add("Paul", 2) self.assertCountEqual(("James", "Blair", "Paul"), self.school.grade(2)) def test_add_students_to_different_grades(self): self.school.add("Chelsea", 3) self.school.add("Logan", 7) self.assertCountEqual(("Chelsea",), self.school.grade(3)) self.assertCountEqual(("Logan",), self.school.grade(7)) def test_get_students_in_a_grade(self): self.school.add("Franklin", 5) self.school.add("Bradley", 5) self.school.add("Jeff", 1) self.assertCountEqual(("Franklin", "Bradley"), self.school.grade(5)) def test_get_students_in_a_non_existant_grade(self): self.assertCountEqual(set(), self.school.grade(1)) def test_sort_school(self): students = [ (3, ("Kyle",)), (4, ("Christopher", "Jennifer",)), (6, ("Kareem",)) ] for grade, students_in_grade in students: for student in students_in_grade: self.school.add(student, grade) result = self.school.sort() # Attempts to catch false positives self.assertTrue(isinstance(result, Sequence) or isinstance(result, GeneratorType) or callable(getattr(result, '__reversed__', False))) result_list = list(result.items() if hasattr(result, "items") else result) self.assertEqual(result_list, students)
class SchoolTest(unittest.TestCase): def setUp(self): # assertCountEqual is py3, py2 only knowns assetItemsEqual if not hasattr(self, 'assertCountEqual'): self.assertCountEqual = self.assertItemsEqual self.school = School("Haleakala Hippy School") def test_an_empty_school(self): for n in range(1, 9): self.assertCountEqual(self.school.grade(n), set()) def test_add_student(self): self.school.add("Aimee", 2) self.assertCountEqual(self.school.grade(2), ("Aimee", )) def test_add_more_students_in_same_class(self): self.school.add("James", 2) self.school.add("Blair", 2) self.school.add("Paul", 2) self.assertCountEqual(self.school.grade(2), ("James", "Blair", "Paul")) def test_add_students_to_different_grades(self): self.school.add("Chelsea", 3) self.school.add("Logan", 7) self.assertCountEqual(self.school.grade(3), ("Chelsea", )) self.assertCountEqual(self.school.grade(7), ("Logan", )) def test_get_students_in_a_grade(self): self.school.add("Franklin", 5) self.school.add("Bradley", 5) self.school.add("Jeff", 1) self.assertCountEqual(self.school.grade(5), ("Franklin", "Bradley")) def test_get_students_in_a_non_existant_grade(self): self.assertCountEqual(self.school.grade(1), set()) def test_sort_school(self): students = [(3, ("Kyle", )), (4, ("Christopher", "Jennifer", )), (6, ("Kareem", ))] for grade, students_in_grade in students: for student in students_in_grade: self.school.add(student, grade) result = self.school.sort() # Attempts to catch false positives self.assertTrue( isinstance(result, Sequence) or isinstance(result, GeneratorType) or callable(getattr(result, '__reversed__', False))) result_list = list(result.items() if hasattr(result, "items") else result) self.assertEqual(students, result_list)
def test_roster_is_empty_when_no_student_is_added(self): school = School() expected = [] self.assertEqual(school.roster(), expected)
def test_grade_is_empty_if_no_students_in_the_roster(self): school = School() expected = [] self.assertEqual(school.grade(1), expected)
def test_grade_is_empty_if_no_students_in_that_grade(self): school = School() school.add_student(name="Peter", grade=2) school.add_student(name="Zoe", grade=2) school.add_student(name="Alex", grade=2) school.add_student(name="Jim", grade=3) expected = [] self.assertEqual(school.grade(1), expected)
def test_student_is_added_to_the_roster(self): school = School() school.add_student(name="Aimee", grade=2) expected = ["Aimee"] self.assertEqual(school.roster(), expected)
def test_add_a_student(self): school = School() school.add_student(name="Aimee", grade=2) expected = [True] self.assertEqual(school.added(), expected)
def test_change_grade_of_student(self): with self.assertRaisesWithMessage(ValueError): school = School() school.add_student(name="Johnny", grade=10) school.add_student(name="Johnny", grade=5)
def test_grade_returns_an_empty_list_if_there_are_no_students_in_that_grade( self): school = School() expected = [] self.assertEqual(school.grade(1), expected)
def test_students_in_different_grades_in_same_roster(self): school = School() school.add_student(name='Chelsea', grade=3) school.add_student(name='Logan', grade=7) expected = ['Chelsea', 'Logan'] self.assertEqual(school.roster(), expected)
def test_adding_a_student_adds_them_to_the_sorted_roster(self): school = School() school.add_student(name="Aimee", grade=2) expected = ["Aimee"] self.assertEqual(school.roster(), expected)
def setUp(self): # assertCountEqual is py3, py2 only knowns assetItemsEqual if not hasattr(self, 'assertCountEqual'): self.assertCountEqual = self.assertItemsEqual self.school = School("Haleakala Hippy School")
def test_adding_students_in_multiple_grades(self): school = School() school.add_student(name="Chelsea", grade=3) school.add_student(name="Logan", grade=7) expected = [True, True] self.assertEqual(school.added(), expected)