当前位置: 首页>>代码示例>>Python>>正文


Python User.add_student方法代码示例

本文整理汇总了Python中user.User.add_student方法的典型用法代码示例。如果您正苦于以下问题:Python User.add_student方法的具体用法?Python User.add_student怎么用?Python User.add_student使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在user.User的用法示例。


在下文中一共展示了User.add_student方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_basic_total_infection

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_basic_total_infection(self):
        """
        Basic test of the total infection algorithm. There are 3 users such that user 1 coaches
        user 2 and user 2 coaches user 3. All of the users should be infected.
        """
        u1 = User("u1", 1)
        u2 = User("u2", 1)
        u3 = User("u3", 1)
        u1.add_student(u2)
        u2.add_student(u3)

        network = UserNetwork()
        network.add_user(u1)
        network.add_user(u2)
        network.add_user(u3)

        network.total_infection(u1, 2)
        self.assertEqual(u1.version, 2)
        self.assertEqual(u2.version, 2)
        self.assertEqual(u3.version, 2)

        network.total_infection(u2, 3)
        self.assertEqual(u1.version, 3)
        self.assertEqual(u2.version, 3)
        self.assertEqual(u3.version, 3)

        network.total_infection(u2, 4)
        self.assertEqual(u1.version, 4)
        self.assertEqual(u2.version, 4)
        self.assertEqual(u3.version, 4)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:32,代码来源:test_user_network.py

示例2: test_user_creation

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
 def test_user_creation(self):
     u = User('A')
     self.assertEqual(u.get_name(), 'A')
     self.assertEqual(u.get_status(), 'Clean')
     v = User('B')
     u.add_student(v)
     self.assertTrue(v in u.get_students())
开发者ID:chenhoward,项目名称:infections,代码行数:9,代码来源:unit_test.py

示例3: test_basic_limited_infection

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_basic_limited_infection(self):
        """
        Tests the limited infection algorithm on a network of 3 users such that user 1 coaches user 2 and
        user 2 coaches user 3.
        """
        u1 = User("u1", 1)
        u2 = User("u2", 1)
        u3 = User("u3", 1)
        u1.add_student(u2)
        u2.add_student(u3)

        network = UserNetwork()
        network.add_user(u1)
        network.add_user(u2)
        network.add_user(u3)

        network.limited_infection(u1, 2, 2)
        self.assertEqual(u1.version, 2)
        self.assertEqual(u2.version, 2)
        self.assertEqual(u3.version, 1)

        network.limited_infection(u2, 2, 3)
        self.assertEqual(u1.version, 2)
        self.assertEqual(u2.version, 3)
        self.assertEqual(u3.version, 3)

        # Make sure it finds user w/ most infected students
        network.limited_infection(u3, 2, 4)
        self.assertEqual(u1.version, 2)
        self.assertEqual(u2.version, 4)
        self.assertEqual(u3.version, 4)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:33,代码来源:test_user_network.py

示例4: add_student

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def add_student(self, other):
        """
        Adds student to self.students and adds an edge for the connection on the graph

        :param other: Student of self
        :type other: VisualUser
        :return: None
        """
        User.add_student(self, other)
        self.edges.append(Edge(self.node, other.node, weight=1, stroke=VisualUser.EDGE_COLOR, strokewidth=2))
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:12,代码来源:visual_user.py

示例5: test_user_add

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
 def test_user_add(self):
     a = User()
     b = User()
     c = User()
     d = User()
     a.add_student(b)
     b.add_coach(c)
     c.add_students([d])
     c.add_students([d])
     self.assertEqual(a.get_num_students(), 1)
     self.assertEqual(c.get_num_students(), 2)
     self.assertEqual(b.get_num_coaches(), 2)
     self.assertEqual(d.get_num_coaches(), 1)
开发者ID:chenhoward,项目名称:infections,代码行数:15,代码来源:unit_test.py

示例6: test_user_add_single_student

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_user_add_single_student(self):
        """
        Tests adding a single student to a user's students.
        """
        u1 = User("u1", 1)
        u2 = User("u2", 1)
        u1.add_student(u2)

        self.assertEqual(len(u1.students), 1)
        self.assertTrue(u2 in u1.students)

        self.assertEqual(len(u2.coaches), 1)
        self.assertTrue(u1 in u2.coaches)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:15,代码来源:test_user.py

示例7: test_user_double_remove_student

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_user_double_remove_student(self):
        """
        Tests that an error is raised when double removing a student
        """
        u1 = User("u1", 1)
        u2 = User("u2", 1)
        u1.add_student(u2)
        u1.remove_student(u2)
        self.assertRaises(MissingStudentError, u1.remove_student, u2)

        self.assertEqual(len(u1.students), 0)
        self.assertFalse(u2 in u1.students)
        self.assertFalse(u1 in u2.coaches)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:15,代码来源:test_user.py

示例8: test_user_add_duplicate_students

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_user_add_duplicate_students(self):
        """
        Tests that an error is raised when duplicate students are added
        """
        u1 = User("u1", 1)
        u2 = User("u2", 1)
        u1.add_student(u2)
        self.assertRaises(DuplicateStudentError, u1.add_student, u2)

        self.assertEqual(len(u1.students), 1)
        self.assertTrue(u2 in u1.students)

        self.assertEqual(len(u2.coaches), 1)
        self.assertTrue(u1 in u2.coaches)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:16,代码来源:test_user.py

示例9: test_user_remove_single_student

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_user_remove_single_student(self):
        """
        Tests removing a student from a user's students
        """
        u1 = User("u1", 1)
        u2 = User("u2", 1)
        u1.add_student(u2)
        u1.remove_student(u2)

        self.assertEqual(len(u1.students), 0)
        self.assertFalse(u2 in u1.students)

        self.assertEqual(len(u2.coaches), 0)
        self.assertFalse(u1 in u2.coaches)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:16,代码来源:test_user.py

示例10: test_user_num_infected_students

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_user_num_infected_students(self):
        """
        Tests the calculation of the number of infected students of a user.
        """
        u1 = User("u1", 1)
        u2 = User("u2", 2)
        u3 = User("u3", 2)
        u4 = User("u4", 1)
        u1.add_student(u2)
        u1.add_student(u3)
        u1.add_student(u4)

        num_infected = u1.num_infected_students(2)
        self.assertEqual(len(u1.students), 3)
        self.assertEqual(num_infected, 2)

        num_infected = u1.num_infected_students(1)
        self.assertEqual(num_infected, 1)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:20,代码来源:test_user.py

示例11: test_user_add_multiple_students

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
    def test_user_add_multiple_students(self):
        """
        Tests adding multiple students to a user's students
        """
        u1 = User("u1", 1)
        u2 = User("u2", 1)
        u3 = User("u3", 1)
        u1.add_student(u2)
        u1.add_student(u3)

        self.assertEqual(len(u1.students), 2)
        self.assertTrue(u2 in u1.students)
        self.assertTrue(u3 in u1.students)

        self.assertEqual(len(u2.coaches), 1)
        self.assertTrue(u1 in u2.coaches)

        self.assertEqual(len(u3.coaches), 1)
        self.assertTrue(u1 in u3.coaches)
开发者ID:lemonade512,项目名称:KhanAcademyProject,代码行数:21,代码来源:test_user.py

示例12: test_total_infection_rand

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
 def test_total_infection_rand(self):
     users = []
     user_num = 50
     for i in xrange(user_num):
         user = User(i)
         users.append(user)
         coaching = random.randint(0, 1)
         if i:
             related_user = users[random.randint(0, i - 1)]
             if coaching:
                 user.add_student(related_user)
             else:
                 user.add_coach(related_user)
     for user in users:
         self.assertEqual(user.get_status(), 'Clean')
     user = users[random.randint(0, user_num - 1)]
     infections.total_infection(user)
     for user in users:
         self.assertEqual(user.get_status(), 'Infected')
开发者ID:chenhoward,项目名称:infections,代码行数:21,代码来源:unit_test.py

示例13: test_total_infection1

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
 def test_total_infection1(self):
     a = User()
     b = User()
     c = User()
     d = User()
     e = User()
     f = User()
     e.add_student(f)
     a.add_coach(b)
     b.add_student(c)
     d.add_student(a)
     self.assertEqual(a.get_status(), 'Clean')
     self.assertEqual(b.get_status(), 'Clean')
     self.assertEqual(c.get_status(), 'Clean')
     self.assertEqual(d.get_status(), 'Clean')
     self.assertEqual(e.get_status(), 'Clean')
     self.assertEqual(f.get_status(), 'Clean')
     infections.total_infection(a)
     self.assertEqual(a.get_status(), 'Infected')
     self.assertEqual(b.get_status(), 'Infected')
     self.assertEqual(c.get_status(), 'Infected')
     self.assertEqual(d.get_status(), 'Infected')
     self.assertEqual(e.get_status(), 'Clean')
     self.assertEqual(f.get_status(), 'Clean')
     infections.total_infection(f)
     self.assertEqual(e.get_status(), 'Infected')
     self.assertEqual(f.get_status(), 'Infected')
开发者ID:chenhoward,项目名称:infections,代码行数:29,代码来源:unit_test.py

示例14: test_exact_infection1

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
 def test_exact_infection1(self):
     a = User('A')
     b = User('B')
     c = User('C')
     d = User('D')
     e = User('E')
     f = User('F')
     user_lst = [a, b, c, d]
     e.add_student(f)
     a.add_coach(b)
     b.add_student(c)
     d.add_student(a)
     self.assertEqual(a.get_status(), 'Clean')
     self.assertEqual(b.get_status(), 'Clean')
     self.assertEqual(c.get_status(), 'Clean')
     self.assertEqual(d.get_status(), 'Clean')
     self.assertEqual(e.get_status(), 'Clean')
     self.assertEqual(f.get_status(), 'Clean')
     result = infections.exact_infection(a, 4)
     self.assertTrue(result)
     infected_count = 0
     for user in user_lst:
         infected_count += user.get_status_num()
     self.assertEqual(infected_count, 4)
     result = infections.exact_infection(f, 10)
     self.assertFalse(result)
     self.assertEqual(e.get_status(), 'Clean')
     self.assertEqual(f.get_status(), 'Clean')
开发者ID:chenhoward,项目名称:infections,代码行数:30,代码来源:unit_test.py

示例15: test_limited_infection1

# 需要导入模块: from user import User [as 别名]
# 或者: from user.User import add_student [as 别名]
 def test_limited_infection1(self):
     a = User('A')
     b = User('B')
     c = User('C')
     d = User('D')
     e = User('E')
     f = User('F')
     e.add_student(f)
     a.add_coach(b)
     b.add_student(c)
     d.add_student(a)
     self.assertEqual(a.get_status(), 'Clean')
     self.assertEqual(b.get_status(), 'Clean')
     self.assertEqual(c.get_status(), 'Clean')
     self.assertEqual(d.get_status(), 'Clean')
     self.assertEqual(e.get_status(), 'Clean')
     self.assertEqual(f.get_status(), 'Clean')
     infections.limited_infection(a, 3)
     self.assertEqual(a.get_status(), 'Infected')
     self.assertEqual(b.get_status(), 'Infected')
     self.assertEqual(c.get_status(), 'Clean')
     self.assertEqual(d.get_status(), 'Infected')
     self.assertEqual(e.get_status(), 'Clean')
     self.assertEqual(f.get_status(), 'Clean')
     infections.limited_infection(f, 0)
     self.assertEqual(e.get_status(), 'Clean')
     self.assertEqual(f.get_status(), 'Clean')
     infections.limited_infection(f, 10)
     self.assertEqual(e.get_status(), 'Infected')
     self.assertEqual(f.get_status(), 'Infected')
开发者ID:chenhoward,项目名称:infections,代码行数:32,代码来源:unit_test.py


注:本文中的user.User.add_student方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。