當前位置: 首頁>>代碼示例>>Python>>正文


Python Course.add_prereq方法代碼示例

本文整理匯總了Python中course.Course.add_prereq方法的典型用法代碼示例。如果您正苦於以下問題:Python Course.add_prereq方法的具體用法?Python Course.add_prereq怎麽用?Python Course.add_prereq使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在course.Course的用法示例。


在下文中一共展示了Course.add_prereq方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestCourseAddPrereq

# 需要導入模塊: from course import Course [as 別名]
# 或者: from course.Course import add_prereq [as 別名]
class TestCourseAddPrereq(unittest.TestCase):

    def setUp(self):
        self.c1 = Course('Highschoolcalc')
        self.c2 = Course('MAT136')
        self.c3 = Course('MAT137', [self.c1])
        self.c4 = Course('MAT237', [self.c2, self.c3])

    def test_add_prereq_no_prereqs(self):
        prereq = Course('MAT223')
        self.c1.add_prereq(prereq)
        self.assertEqual([prereq], self.c1.prereqs)

    def test_add_prereqs_many_prereqs(self):
        prereq = Course('MAT136')
        self.c1.add_prereq(prereq)
        self.assertEqual(prereq.name, self.c1.prereqs[-1].name)

    def test_error_in_tree(self):
        self.assertRaises(PrerequisiteError, self.c3.add_prereq, self.c1)
        self.assertRaises(PrerequisiteError, self.c4.add_prereq, self.c1)

    def test_error_in_prereq_tree(self):
        self.assertRaises(PrerequisiteError, self.c1.add_prereq, self.c3)
        self.assertRaises(PrerequisiteError, self.c1.add_prereq, self.c4)

    def test_error_add_self(self):
        self.assertRaises(PrerequisiteError, self.c3.add_prereq, self.c3)
開發者ID:sinoforever,項目名稱:Assignment-2,代碼行數:30,代碼來源:course_test.py

示例2: TestCourseAddPrereq

# 需要導入模塊: from course import Course [as 別名]
# 或者: from course.Course import add_prereq [as 別名]
class TestCourseAddPrereq(unittest.TestCase):

    def setUp(self):
        self.c3 = Course('alone101')

    def test_add_prereq_no_prereqs(self):
        prereq = Course('MAT223')
        self.c3.add_prereq(prereq)
        self.assertEqual([prereq], self.c3.prereqs)
開發者ID:ooo125258,項目名稱:Assignment-2,代碼行數:11,代碼來源:course_test.py

示例3: TestCourse

# 需要導入模塊: from course import Course [as 別名]
# 或者: from course.Course import add_prereq [as 別名]
class TestCourse(unittest.TestCase):

    def setUp(self):
        self.a = Course('A')
        self.b = Course('B')
        self.c = Course('C', [self.a])
        self.d = Course('D', [self.b, self.c])

    def test_initializes_with_values(self):
        self.assertEqual([self.b, self.c], self.d.prereqs)
        self.assertEqual([], self.a.prereqs)
        self.assertEqual('A', self.a.name)
        self.assertEqual(False, self.a.taken)

    def test_is_not_takeable_without_prereqs(self):
        self.assertEqual(False, self.d.is_takeable())
        self.assertEqual(False, self.c.is_takeable())

    def test_is_takeable_with_prereqs(self):
        self.a.take()
        self.assertEqual(True, self.c.is_takeable())
        self.assertEqual(False, self.d.is_takeable())
        self.b.take()
        self.assertEqual(False, self.d.is_takeable())
        self.c.take()
        self.assertEqual(True, self.d.is_takeable())

    def test_take_works(self):
        self.assertEqual(False, self.a.taken)
        self.a.take()
        self.assertEqual(True, self.a.taken)
        self.a.take()
        self.assertEqual(True, self.a.taken)

    def test_raises_error_if_cant_take(self):
        self.assertEqual(False, self.d.is_takeable())
        with self.assertRaises(UntakeableError):
            self.d.take()

    def test_add_prereq_works(self):
        self.a.add_prereq(self.b)
        self.assertEqual([self.b], self.a.prereqs)

    def test_add_prereq_fails_if_already_there(self):
        with self.assertRaises(PrerequisiteError):
            self.c.add_prereq(self.a)

    def test_add_prereq_fails_if_circular(self):
        with self.assertRaises(PrerequisiteError):
            self.a.add_prereq(self.c)

    def test_find(self):
        self.assertEqual(self.a, self.d.find('A'))
        self.assertEqual(None, self.d.find('G'))

    def test_missing_prereqs_works(self):
        self.assertEqual([], self.a.missing_prereqs())
        self.assertEqual(['A'], self.c.missing_prereqs())
        self.assertEqual(['A', 'B', 'C'], self.d.missing_prereqs())

    def test_adds_self_as_prereq(self):
        with self.assertRaises(PrerequisiteError):
            self.a.add_prereq(self.a)
開發者ID:connor4312,項目名稱:CSC148-assignment-2,代碼行數:65,代碼來源:course_test.py


注:本文中的course.Course.add_prereq方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。