def testEight(self):
     """
     Test #8: Tree Parent Limited Infection from leaf.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     e = User('e')
     f = User('f')
     g = User('g')
     coach(a, b)
     coach(a, c)
     coach(b, d)
     coach(b, e)
     coach(c, f)
     coach(c, g)
     users = [a, b, c, d, e, f, g]
     limited_infection(users, f, 1, 'parent', maxint)
     count = 0
     for user in users:
         if user.get_version() == 1:
             count += 1
     self.failUnless(
                     count == 3 and
                     f.get_version() == 1 == c.get_version() == a.get_version()
                     )
	def test_forest_with_less_limit(self):
		coaches = []
		# create a forest of 10 trees
		for i in range(10):									
			c = Coach()
			coaches.append(c)
			import random
			num = int(1 + random.random() * 10)
			# add between 1 and 10 child coaches
			for j in range(num):							
				c1 = c.add_coach()
				students = int(1 + random.random() * 10)
				# add between 1 and 10 students
				for _ in range(students):					
					c1.add_student()

		abs_limit = 0
		for coach in coaches:
			abs_limit += coach.count()

		limit = abs_limit - coaches[-1].count()				
		for i in range(len(coaches) - 1):
			limit = limited_infection(coaches[i], limit)

		# to show that we can't give everyone the new feature
		self.assertFalse(limited_infection(coaches[-1], limit))
 def testSeven(self):
     """
     Test #7: Tree Child Limited Infection from top node.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     e = User('e')
     f = User('f')
     g = User('g')
     coach(a, b)
     coach(a, c)
     coach(b, d)
     coach(b, e)
     coach(c, f)
     coach(c, g)
     users = [a, b, c, d, e, f, g]
     limited_infection(users, a, 1, 'child', 5)
     count = 0
     for user in users:
         if user.get_version() == 1:
             count += 1
     self.failUnless(
                     count == 5 and
                     e.get_version() == 1 == d.get_version() and f.get_version() is g.get_version() is None or
                     f.get_version() == 1 == g.get_version() and e.get_version() is d.get_version() is None
                     )
	def test_limited_infection_when_already_infected(self):
		c = Coach()
		for i in range(5):
			c.add_student()
		limit = limited_infection(c, 8)
		self.assertEqual(limit, 2)
		limit = limited_infection(c, 8)
		self.assertEqual(limit, 8)
	def test_limited_infection_from_student_to_parent(self):
		c = Coach()
		for i in range(5):
			c.add_student()
		s = c.students[0]
		f = limited_infection(s, 3)
		self.assertFalse(f)
	def test_forest_with_full_limit(self):
		coaches = []
		# create a forest of 10 trees
		for i in range(10):									
			c = Coach()
			coaches.append(c)
			import random
			num = int(1 + random.random() * 10)
			# add between 1 and 10 child coaches
			for j in range(num):							
				c1 = c.add_coach()
				students = int(1 + random.random() * 10)
				# add between 1 and 10 students
				for _ in range(students):					
					c1.add_student()

		abs_limit = 0
		for coach in coaches:
			abs_limit += coach.count()	

		# abs_limit should be a number in the hundreds now					
		limit = abs_limit									
		for coach in coaches:
			limit = limited_infection(coach, limit)

		# to show that we can give everyone the new feature
		self.assertEqual(limit, 0)
 def testSix(self):
     """
     Test #6: Simple Link Parent Limited Infection.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     coach(a, b)
     coach(b, c)
     coach(c, d)
     users = [d, c]
     limited_infection([a, b, c, d], d, 1, 'parent', 2)
     correct = True
     for user in users:
         if user.get_version() != 1:
             correct = False
     self.failUnless(correct)
 def testFive(self):
     """
     Test #5: Simple Link Child Limited Infection.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     coach(a, b)
     coach(b, c)
     coach(c, d)
     users = [a, b, c]
     limited_infection([a, b, c, d], a, 1, 'child', 3)
     correct = True
     for user in users:
         if user.get_version() != 1:
             correct = False
     self.failUnless(correct)
	def test_limited_infection_from_coach_to_parent(self):
		c = Coach()
		for i in range(5):
			c1 = c.add_coach()
			for j in range(5):
				c1.add_student()
		coach = c.students[0]
		f = limited_infection(coach, 20)
		self.assertFalse(f)
 def testTen(self):
     """
     Test #10: Tree Parent Limited Infection from middle.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     e = User('e')
     f = User('f')
     g = User('g')
     coach(a, b)
     coach(a, c)
     coach(b, d)
     coach(b, e)
     coach(c, f)
     coach(c, g)
     users = [a, b, c, d, e, f, g]
     limited_infection(users, c, 1, 'parent', maxint)
     self.failUnless(
                     c.get_version() == 1 == a.get_version()
                     )
 def testNine(self):
     """
     Test #9: Tree Child Limited Infection from middle.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     e = User('e')
     f = User('f')
     g = User('g')
     coach(a, b)
     coach(a, c)
     coach(b, d)
     coach(b, e)
     coach(c, f)
     coach(c, g)
     users = [a, b, c, d, e, f, g]
     limited_infection(users, c, 1, 'child', maxint)
     self.failUnless(
                     c.get_version() == 1 == f.get_version() == g.get_version()
                     )
 def testTwelve(self):
     """
     Test #12: Complex Graph Parent Limited Infection from middle.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     e = User('e')
     f = User('f')
     g = User('g')
     h = User('h')
     i = User('i')
     j = User('j')
     k = User('k')
     users = [a,b,c,d,e,f,g,h,i,j,k]
     coach(a, b)
     coach(b, c)
     coach(c, a)
     coach(a, d)
     coach(d, e)
     coach(d, f)
     coach(e, b)
     coach(e, g)
     coach(g, b)
     coach(h, i)
     coach(i, j)
     coach(j, e)
     coach(c, k)
     limited_infection(users, b, 1, 'parent', maxint)
     count = 0
     for user in users:
         if user.get_version() != 1:
             count += 1
     self.failUnless(
                    count == 2 and
                    f.get_version() is k.get_version() is None
     )
 def testEleven(self):
     """
     Test #11: Complex Graph Child Limited Infection from middle.
     """
     a = User('a')
     b = User('b')
     c = User('c')
     d = User('d')
     e = User('e')
     f = User('f')
     g = User('g')
     h = User('h')
     i = User('i')
     j = User('j')
     coach(a, b)
     coach(b, c)
     coach(c, a)
     coach(a, d)
     coach(d, e)
     coach(d, f)
     coach(e, b)
     coach(e, g)
     coach(g, b)
     coach(h, i)
     coach(i, j)
     coach(j, e)
     users=[a,b,c,d,e,f,g,h,i,j]
     limited_infection(users, e, 1, 'child', 6)
     count = 0
     for user in users:
         if user.get_version() == 1:
             count += 1
     self.failUnless(
                    count == 6 and
                    a.get_version() == b.get_version() == c.get_version() == d.get_version() ==
                    e.get_version() == g.get_version() == 1
     )
	def test_single_limited_infection(self):
		self.assertFalse(limited_infection(self.head, 99))
		self.assertEqual(limited_infection(self.head, 100), 0)