# Path: app/model/users_graph.py
# class UsersGraph:
#     def __init__(self, users: List[User], mutual_ids: Dict[int, List[int]]):
#         self._users = users
#         
#         self._connections = []
#         for user_id, mutual_friends_ids in mutual_ids.items():
#             for mutual_friend_id in mutual_friends_ids:
#                 self.add_connection(user_id, mutual_friend_id)
# 
#     def add_connection(self, user_id1, user_id2):
#         connection = {user_id1, user_id2}
#         if connection not in self._connections:
#             self._connections.append(connection)
#     
#     @property
#     def users(self):
#         return self._users
# 
#     @property
#     def connections(self) -> List[Set[int]]:
#         return self._connections
#     
#     def to_json(self):
#         return dict(friends=[user.to_json() for user in self._users],
#                     connections=[
#                         dict(source=min(connection), target=max(connection))
#                         for connection in self._connections])


from app.model import UsersGraph


def test_connections_generation():
    mutual_ids = {
        1: [2, 3],
        2: [1, 4],
        3: [1],
        4: [2]
    }
    
    graph = UsersGraph(users=[], mutual_ids=mutual_ids)
    
    assert len(graph.connections) == 3
    assert all(connection in graph.connections for connection in
               ({1, 2}, {1, 3}, {2, 4}))


def test_connections_generation_without_all_links():
    mutual_ids = {
        1: [2],
        3: [1],
        4: [2]
    }
    

# Path: app/model/users_graph.py
# class UsersGraph:
#     def __init__(self, users: List[User], mutual_ids: Dict[int, List[int]]):
#         self._users = users
#         
#         self._connections = []
#         for user_id, mutual_friends_ids in mutual_ids.items():
#             for mutual_friend_id in mutual_friends_ids:
#                 self.add_connection(user_id, mutual_friend_id)
# 
#     def add_connection(self, user_id1, user_id2):
#         connection = {user_id1, user_id2}
#         if connection not in self._connections:
#             self._connections.append(connection)
#     
#     @property
#     def users(self):
#         return self._users
# 
#     @property
#     def connections(self) -> List[Set[int]]:
#         return self._connections
#     
#     def to_json(self):
#         return dict(friends=[user.to_json() for user in self._users],
#                     connections=[
#                         dict(source=min(connection), target=max(connection))
#                         for connection in self._connections])


# Path: tests/users_graph_test.py
from app.model import UsersGraph



def test_connections_generation():
    mutual_ids = {
        1: [2, 3],
        2: [1, 4],
        3: [1],
        4: [2]
    }
    
    graph = UsersGraph(users=[], mutual_ids=mutual_ids)
    
    assert len(graph.connections) == 3
    assert all(connection in graph.connections for connection in
               ({1, 2}, {1, 3}, {2, 4}))


def test_connections_generation_without_all_links():
    mutual_ids = {
        1: [2],
        3: [1],
        4: [2]
    }
    

    graph = UsersGraph(users=[], mutual_ids=mutual_ids)