diff --git a/student_lists/studentlists.py b/student_lists/studentlists.py index 2a81205..9436729 100644 --- a/student_lists/studentlists.py +++ b/student_lists/studentlists.py @@ -54,6 +54,8 @@ def index_of_student(self, student): ## TODO add a method called is_class_full. # This should return True or False to indicate if the class is full. + def is_class_full(self): + if self.class_list.count == self.class_list. def __str__(self): diff --git a/student_lists/test_studentlists.py b/student_lists/test_studentlists.py index 76636fb..97d2805 100644 --- a/student_lists/test_studentlists.py +++ b/student_lists/test_studentlists.py @@ -10,6 +10,7 @@ """ +from cgi import test from studentlists import ClassList, StudentError from unittest import TestCase @@ -43,11 +44,19 @@ def test_add_remove_student_ensure_removed(self): ## TODO write a test that adds some example students, # then removes a student not in the list, and asserts a StudentError is raised - + def test_removing_student_from_populated_list_raises_student_error(self): + test_class = ClassList(4) + test_class.add_student('Example') + test_class.add_student('Another Example') + with self.assertRaises(StudentError): + test_class.remove_student('Not there') ## TODO write a test that removes a student from an # empty list, and asserts a StudentError is raised - + def test_removing_student_from_empty_list_raises_student_error(self): + test_class = ClassList(3) + with self.assertRaises(StudentError): + test_class.remove_student('Example') def test_is_enrolled_when_student_present(self): @@ -66,7 +75,12 @@ def test_is_enrolled_empty_class_list(self): ## TODO write a test that adds some example students to a test class, ## then, call is_enrolled for a student who is not enrolled. # Use assertFalse to verify is_enrolled returns False. - + def test_is_enrolled_returns_false_if_student_not_enrolled(self): + test_class = ClassList(3) + test_class.add_student('Example 1') + test_class.add_student('Example 2') + test_class.add_student('Example 3') + self.assertFalse(test_class.is_enrolled('Example 4')) def test_string_with_students_enrolled(self): test_class = ClassList(2) @@ -99,15 +113,27 @@ def test_index_of_student_student_present(self): ## TODO write a test for index_of_student when the class_list list is empty. # Assert index_of_student returns None for a student if the list is empty. # use assertIsNone. - + def test_index_of_student_returns_none_if_empty(self): + test_class = ClassList(4) + self.assertIsNone(test_class.index_of_student('Example')) ## TODO write another test for index_of_student. In the case when the # class_list is not empty but has some students. # assert that searching for a student name that is not in the list, returns None. - + def test_index_of_student_not_in_list(self): + test_class = ClassList(3) + test_class.add_student('Exapmle 1') + test_class.add_student('Exapmle 2') + test_class.add_student('Exapmle 3') + self.assertIsNone(test_class.index_of_student('Example 4')) ## TODO write a test for your new is_class_full method when the class is full. # use assertTrue. - + def test_class_is_full(self): + test_class = ClassList(2) + test_class.add_student('Example 1') + test_class.add_student('Example 2') + self.assertTrue(test_class.) + ## TODO write a test for your new is_class_full method for when is empty, # and when it is not full. Use assertFalse.