timeit

Програмиране с Python

Курс във Факултета по Математика и Информатика към СУ

Решение на Социална мрежа от Константин Димитров

Обратно към всички решения

Към профила на Константин Димитров

Резултати

  • 1 точка от тестове
  • 0 бонус точки
  • 1 точка общо
  • 1 успешни тест(а)
  • 7 неуспешни тест(а)

Код

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime

u = []

class Post:
    def __init__(self,author,content):
        self.author = author
        self.content = content
        self.published_at = datetime.now()

class User:
    def __init__(self,full_name):
        self.full_name = full_name
        self.uuid = len(u)
        u.append(self)
        self.posts = []
    def add_post(self, post_content):
        self.posts.append(self.posts(post_content))
        if len(self.posts) == 50:
            del self.posts[0]
    def get_post(selsf):
        return self.posts[0]
    
class SocialGraph:
    def __init__(self):
        self.users = {}
        self.followe = [{},{}]
        
    def add_user(self, user_uuid):
        self.users[user_uuid] = u[user_uuid]
        self.followe[0][user_uuid]=[]
        self.followe[1][user_uuid]=[]
        
    def get_user(self, user_uuid):
        return self.users[user_uuid]
    
    def delete_user(self, user_uuid):
        del self.users[user_uuid]
        del self.followe[0][user_uuid]
        del self.followe[1][user_uuid]

    def follow(self, follower, followee):
        self.followe[0][followee].append(follower)
        self.followe[1][follower].append(followee)
    def unfollow(self, follower, followee):
        del self.followe[0][followee][follower]
        del self.followe[1][follower][followee]
    def is_following(self, follower, followee):
        return followee is self.followe[0][follower]
    def followers(self, user_uuid):
        return self.followe[0][user_uuid]
    def following(self, user_uuid):
        return self.followe[1][user_uuid]
    def friends(self, user_uuid):
        pass
    

Лог от изпълнението

EEEEEEE.
======================================================================
ERROR: test_add_get_and_delete_user (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20160530-24280-uwrwo7/test.py", line 15, in setUp
    self.graph.add_user(self.terry)
  File "/tmp/d20160530-24280-uwrwo7/solution.py", line 30, in add_user
    self.users[user_uuid] = u[user_uuid]
TypeError: list indices must be integers or slices, not User

======================================================================
ERROR: test_distnaces (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20160530-24280-uwrwo7/test.py", line 15, in setUp
    self.graph.add_user(self.terry)
  File "/tmp/d20160530-24280-uwrwo7/solution.py", line 30, in add_user
    self.users[user_uuid] = u[user_uuid]
TypeError: list indices must be integers or slices, not User

======================================================================
ERROR: test_feed (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20160530-24280-uwrwo7/test.py", line 15, in setUp
    self.graph.add_user(self.terry)
  File "/tmp/d20160530-24280-uwrwo7/solution.py", line 30, in add_user
    self.users[user_uuid] = u[user_uuid]
TypeError: list indices must be integers or slices, not User

======================================================================
ERROR: test_following (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20160530-24280-uwrwo7/test.py", line 15, in setUp
    self.graph.add_user(self.terry)
  File "/tmp/d20160530-24280-uwrwo7/solution.py", line 30, in add_user
    self.users[user_uuid] = u[user_uuid]
TypeError: list indices must be integers or slices, not User

======================================================================
ERROR: test_friends (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20160530-24280-uwrwo7/test.py", line 15, in setUp
    self.graph.add_user(self.terry)
  File "/tmp/d20160530-24280-uwrwo7/solution.py", line 30, in add_user
    self.users[user_uuid] = u[user_uuid]
TypeError: list indices must be integers or slices, not User

======================================================================
ERROR: test_layer_followings (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/d20160530-24280-uwrwo7/test.py", line 15, in setUp
    self.graph.add_user(self.terry)
  File "/tmp/d20160530-24280-uwrwo7/solution.py", line 30, in add_user
    self.users[user_uuid] = u[user_uuid]
TypeError: list indices must be integers or slices, not User

======================================================================
ERROR: test_add_post (test.TestUser)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
TypeError: 'list' object is not callable

----------------------------------------------------------------------
Ran 8 tests in 0.046s

FAILED (errors=7)

История (2 версии и 0 коментара)

Константин обнови решението на 18.04.2016 16:26 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime

u = []

class Post:
    def __init__(self,author,content):
        self.author = author
        self.content = content
        self.published_at = datetime.now()

class User:
    def __init__(self,full_name):
        self.full_name = full_name
        self.uuid = len(u)
        u.append(self)
        self.posts = []
    def add_post(self, post_content):
        self.posts.append(self.posts(post_content))
        if len(self.posts) == 50:
            del self.posts[0]
    def get_post(self):
        return self.posts[0]
    
class SocialGraph:
    def __init___(self):
        self.users = {}
        self.is_followed_by = {}
        
    def add_user(self, user_uuid):
        self.users[user_uuid] = u[user_uuid]
        self.is_followed_by[user.uuid] = []
        
    def get_user(self, user_uuid):
        return self.users[user_uuid]
    
    def delete_user(self, user_uuid):
        del self.users[user_uuid]
        del self.is_followed_by[user_uuid]


        


        


a = User('asdas')
g = SocialGraph()
g.add_user(0)

Константин обнови решението на 18.04.2016 16:55 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from datetime import datetime

u = []

class Post:
    def __init__(self,author,content):
        self.author = author
        self.content = content
        self.published_at = datetime.now()

class User:
    def __init__(self,full_name):
        self.full_name = full_name
        self.uuid = len(u)
        u.append(self)
        self.posts = []
    def add_post(self, post_content):
        self.posts.append(self.posts(post_content))
        if len(self.posts) == 50:
            del self.posts[0]
    def get_post(selsf):
        return self.posts[0]
    
class SocialGraph:
    def __init__(self):
        self.users = {}
        self.followe = [{},{}]
        
    def add_user(self, user_uuid):
        self.users[user_uuid] = u[user_uuid]
        self.followe[0][user_uuid]=[]
        self.followe[1][user_uuid]=[]
        
    def get_user(self, user_uuid):
        return self.users[user_uuid]
    
    def delete_user(self, user_uuid):
        del self.users[user_uuid]
        del self.followe[0][user_uuid]
        del self.followe[1][user_uuid]

    def follow(self, follower, followee):
        self.followe[0][followee].append(follower)
        self.followe[1][follower].append(followee)
    def unfollow(self, follower, followee):
        del self.followe[0][followee][follower]
        del self.followe[1][follower][followee]
    def is_following(self, follower, followee):
        return followee is self.followe[0][follower]
    def followers(self, user_uuid):
        return self.followe[0][user_uuid]
    def following(self, user_uuid):
        return self.followe[1][user_uuid]
    def friends(self, user_uuid):
        pass