timeit

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

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

Решение на Социална мрежа от Христо Владев

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

Към профила на Христо Владев

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 3 успешни тест(а)
  • 5 неуспешни тест(а)

Код

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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from uuid import uuid4
from datetime import datetime
from collections import deque, defaultdict

class UserDoesNotExistError(Exception):
    pass


class UserAlreadyExistsError(Exception):
    pass


class UsersNotConnectedError(Exception):
    pass


class User:
    MAX_POSTS_COUNT = 50

    def __init__(self, full_name):
        self.full_name = full_name
        self.uuid = uuid4()
        self.__posts = deque()

    def add_post(self, post_content):
        self.__posts.append(Post(self.uuid, post_content, datetime.now()))

        if len(self.__posts) > 50:
            self.__posts.popleft()

    def get_post(self):
        for post in self.__posts:
            yield post


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


class SocialGraph:
    def __init__(self):
        self.__users = []

    def add_user(self, user):
        if user.uuid in map(lambda user: user.uuid, self.__users):
            raise UserAlreadyExistsError

        self.__users.append(user)

    def get_user(self, user_uuid):
        user = self.find_user_by_id(user_uuid)

        if user:
            return user
        else:
            raise UserDoesNotExistError

    def delete_user(self, user_uuid):
        user = self.find_user_by_id(user_uuid)

        if user:
            del self.__users[self.__users.index(user)]
        else:
            raise UserDoesNotExistError

    def find_user_by_id(self, user_uuid):
        try:
            return next(
                user for user in self.__users if user.uuid == user_uuid
            )
        except StopIteration:
            return None

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

.EEEEE..
======================================================================
ERROR: test_distnaces (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'SocialGraph' object has no attribute 'follow'

======================================================================
ERROR: test_feed (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'SocialGraph' object has no attribute 'follow'

======================================================================
ERROR: test_following (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'SocialGraph' object has no attribute 'follow'

======================================================================
ERROR: test_friends (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'SocialGraph' object has no attribute 'follow'

======================================================================
ERROR: test_layer_followings (test.TestSocialGraph)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 67, in thread
    raise result
AttributeError: 'SocialGraph' object has no attribute 'follow'

----------------------------------------------------------------------
Ran 8 tests in 0.097s

FAILED (errors=5)

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

Христо обнови решението на 18.04.2016 16:59 (преди над 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from uuid import uuid4
from datetime import datetime
from collections import deque, defaultdict

class UserDoesNotExistError(Exception):
    pass


class UserAlreadyExistsError(Exception):
    pass


class UsersNotConnectedError(Exception):
    pass


class User:
    MAX_POSTS_COUNT = 50

    def __init__(self, full_name):
        self.full_name = full_name
        self.uuid = uuid4()
        self.__posts = deque()

    def add_post(self, post_content):
        self.__posts.append(Post(self.uuid, post_content, datetime.now()))

        if len(self.__posts) > 50:
            self.__posts.popleft()

    def get_post(self):
        for post in self.__posts:
            yield post


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


class SocialGraph:
    def __init__(self):
        self.__users = []

    def add_user(self, user):
        if user.uuid in map(lambda user: user.uuid, self.__users):
            raise UserAlreadyExistsError

        self.__users.append(user)

    def get_user(self, user_uuid):
        user = self.find_user_by_id(user_uuid)

        if user:
            return user
        else:
            raise UserDoesNotExistError

    def delete_user(self, user_uuid):
        user = self.find_user_by_id(user_uuid)

        if user:
            del self.__users[self.__users.index(user)]
        else:
            raise UserDoesNotExistError

    def find_user_by_id(self, user_uuid):
        try:
            return next(
                user for user in self.__users if user.uuid == user_uuid
            )
        except StopIteration:
            return None