Exemple #1
0
    def test_distance(self):
        self.social_graph.follow(self.terry.uuid, self.eric.uuid)
        self.social_graph.follow(self.eric.uuid, self.graham.uuid)
        self.social_graph.follow(self.graham.uuid, self.john.uuid)
        self.social_graph.follow(self.terry.uuid, self.michael.uuid)

        a = s.User("A")
        b = s.User("B")
        c = s.User("C")

        self.social_graph.add_user(a)
        self.social_graph.add_user(b)
        self.social_graph.add_user(c)

        self.social_graph.follow(self.michael.uuid, a.uuid)
        self.social_graph.follow(a.uuid, b.uuid)
        self.social_graph.follow(b.uuid, self.eric.uuid)
        self.social_graph.follow(self.eric.uuid, c.uuid)
        self.social_graph.follow(c.uuid, self.eric.uuid)
        self.assertEqual(self.social_graph.max_distance(self.terry.uuid), 6)
        self.assertEqual(
            self.social_graph.min_distance(self.terry.uuid, self.eric.uuid), 1)
        self.social_graph.follow(self.michael.uuid, self.terry.uuid)
        self.assertEqual(
            self.social_graph.min_distance(self.michael.uuid, self.eric.uuid),
            2)

        self.social_graph.unfollow(b.uuid, self.eric.uuid)
        self.assertEqual(self.social_graph.max_distance(self.terry.uuid), 3)
Exemple #2
0
    def test_all_paths_1(self):
        self.social_graph.follow(self.terry.uuid, self.eric.uuid)
        self.social_graph.follow(self.eric.uuid, self.graham.uuid)
        self.social_graph.follow(self.graham.uuid, self.john.uuid)
        self.social_graph.follow(self.terry.uuid, self.michael.uuid)

        a = s.User("A")
        b = s.User("B")
        c = s.User("C")

        self.social_graph.add_user(a)
        self.social_graph.add_user(b)
        self.social_graph.add_user(c)

        self.social_graph.follow(self.michael.uuid, a.uuid)
        self.social_graph.follow(a.uuid, b.uuid)
        self.social_graph.follow(b.uuid, self.eric.uuid)
        self.social_graph.follow(self.eric.uuid, c.uuid)
        self.social_graph.follow(c.uuid, self.eric.uuid)

        self.assertEqual(
            self.social_graph.find_all_paths(self.terry.uuid),
            {(self.terry.uuid, self.eric.uuid, self.graham.uuid,
              self.john.uuid), (self.terry.uuid, self.eric.uuid, c.uuid),
             (self.terry.uuid, self.michael.uuid, a.uuid, b.uuid,
              self.eric.uuid, self.graham.uuid, self.john.uuid),
             (self.terry.uuid, self.michael.uuid, a.uuid, b.uuid,
              self.eric.uuid, c.uuid)})
Exemple #3
0
 def setUp(self):
     self.terry = solution.User("Terry Gilliam")
     self.eric = solution.User("Eric Idle")
     self.graham = solution.User("Graham Chapman")
     self.john = solution.User("John Cleese")
     self.michael = solution.User("Michael Palin")
     self.graph = solution.SocialGraph()
     self.graph.add_user(self.terry)
     self.graph.add_user(self.eric)
     self.graph.add_user(self.graham)
     self.graph.add_user(self.john)
     self.graph.add_user(self.michael)
Exemple #4
0
    def test_nth_layer_follwings_2(self):
        a = s.User("a")
        b = s.User("b")
        c = s.User("c")
        d = s.User("d")
        e = s.User("e")
        f = s.User("f")

        self.social_graph.add_user(a)
        self.social_graph.add_user(b)
        self.social_graph.add_user(c)
        self.social_graph.add_user(d)
        self.social_graph.add_user(e)
        self.social_graph.add_user(f)

        self.social_graph.follow(a.uuid, b.uuid)
        self.social_graph.follow(a.uuid, e.uuid)
        self.social_graph.follow(e.uuid, f.uuid)
        self.social_graph.follow(f.uuid, e.uuid)
        self.social_graph.follow(a.uuid, b.uuid)
        self.social_graph.follow(b.uuid, c.uuid)
        self.social_graph.follow(c.uuid, a.uuid)
        self.social_graph.follow(c.uuid, d.uuid)

        self.assertEqual(self.social_graph.nth_layer_followings(a.uuid, 1),
                         {b.uuid, e.uuid})
        self.assertEqual(self.social_graph.nth_layer_followings(a.uuid, 2),
                         {c.uuid, f.uuid})
        self.assertEqual(self.social_graph.nth_layer_followings(a.uuid, 3),
                         {d.uuid})
        self.assertEqual(self.social_graph.nth_layer_followings(a.uuid, 0),
                         set())
        self.assertEqual(self.social_graph.nth_layer_followings(a.uuid, 20),
                         set())
Exemple #5
0
    def test_all_paths_2(self):
        a = s.User("A")
        b = s.User("B")
        c = s.User("C")
        d = s.User("D")

        self.social_graph.add_user(a)
        self.social_graph.add_user(b)
        self.social_graph.add_user(c)
        self.social_graph.add_user(d)

        self.social_graph.follow(a.uuid, b.uuid)
        self.social_graph.follow(a.uuid, c.uuid)
        self.social_graph.follow(b.uuid, c.uuid)
        self.social_graph.follow(b.uuid, d.uuid)
        self.social_graph.follow(c.uuid, d.uuid)
        self.social_graph.follow(d.uuid, c.uuid)

        self.assertEqual(
            self.social_graph.find_all_paths(a.uuid),
            {(a.uuid, b.uuid, c.uuid, d.uuid),
             (a.uuid, b.uuid, d.uuid, c.uuid), (a.uuid, c.uuid, d.uuid)})
Exemple #6
0
    def test_distance(self):
        self.social_graph.follow(self.terry.uuid, self.eric.uuid)
        self.social_graph.follow(self.eric.uuid, self.graham.uuid)
        self.social_graph.follow(self.graham.uuid, self.john.uuid)
        self.social_graph.follow(self.terry.uuid, self.michael.uuid)

        a = s.User("A")
        b = s.User("B")
        c = s.User("C")

        self.social_graph.add_user(a)
        self.social_graph.add_user(b)
        self.social_graph.add_user(c)

        self.social_graph.follow(self.michael.uuid, a.uuid)
        self.social_graph.follow(a.uuid, b.uuid)
        self.social_graph.follow(b.uuid, self.eric.uuid)
        self.social_graph.follow(self.eric.uuid, c.uuid)
        self.social_graph.follow(c.uuid, self.eric.uuid)

        self.assertEqual(self.social_graph.max_distance(self.john.uuid),
                         math.inf)
        self.assertEqual(self.social_graph.max_distance(self.terry.uuid), 3)
        self.assertEqual(
            self.social_graph.min_distance(self.terry.uuid, self.eric.uuid), 1)
        self.social_graph.follow(self.michael.uuid, self.terry.uuid)
        self.assertEqual(
            self.social_graph.min_distance(self.michael.uuid, self.eric.uuid),
            2)
        self.assertEqual(
            self.social_graph.min_distance(self.michael.uuid,
                                           self.michael.uuid), 0)
        self.social_graph.unfollow(b.uuid, self.eric.uuid)
        self.assertEqual(self.social_graph.max_distance(self.terry.uuid), 3)
        with self.assertRaises(s.UsersNotConnectedError):
            self.social_graph.min_distance(a.uuid, self.eric.uuid)
Exemple #7
0
 def setUp(self):
     self.michael = solution.User("Michael Palin")
     self.terry = solution.User("Terry Gilliam")
Exemple #8
0
 def setUp(self):
     self.user = s.User("Lord Bendtner")
Exemple #9
0
 def setUp(self):
     self.michael = solution.User("Michael Palin")