# Path: backend/components/clock.py
# class Clock:
#     """Holds actual time. 
#     Notifies about actual time
#     Notifies about week day"""
# 
#     _is_initialized = False
#     _instance = None
# 
#     def __new__(cls, *args, **kwargs):
#         if not cls._instance:
#             cls._instance = super().__new__(cls, *args, **kwargs)
#         return cls._instance
# 
#     def __init__(self, ):
#         if not Clock._is_initialized:
#             Clock._is_initialized = True
#             self.objects_to_notify_weekday = set()
#             self.objects_to_notify_time = set()
# 
#             self.now = None
#             self.minute = None
#             self.weekday = None
# 
#             self.system_start = time.time()
# 
#     def subscribe_for_weekday(self, who):
#         self.objects_to_notify_weekday.add(who)
# 
#     def subscribe_for_minute(self, who):
#         self.objects_to_notify_time.add(who)
# 
#     def notify_minute(self):
#         self.minute = self.now.minute
#         for _object in self.objects_to_notify_time:
#             _object.notify(self.now)
# 
#     def notify_weekday(self):
#         self.weekday = self.now.weekday()
#         for _object in self.objects_to_notify_weekday:
#             _object.notify(self.weekday)
# 
#     def evaluate_time(self, ):
#         """Evaluates current time. If minutes or day changes it notifies related objects"""
#         self.now = datetime.datetime.now()
#         
#         if self.now.minute != self.minute:
#             self.notify_minute()
# 
#         if self.weekday != self.now.weekday():
#             self.notify_weekday()
# 
#     def get_seconds(self):
#         return time.time() - self.system_start
# 
#     def get_millis(self):
#         return (time.time() - self.system_start)*1000
# 
#     def restart(self):
#         self.system_start = time.time()
# 
# Path: backend/components/tests/helper_classes.py
# class Notifiable:
# 
#     def __init__(self):
# 
#         self.val = None
# 
#     def notify(self, val):
# 
#         self.val = val


import unittest
import datetime
import time
from backend.components.clock import Clock
from backend.components.tests.helper_classes import Notifiable
        self.clock.restart()

    def test_get_seconds(self):
        self.assertAlmostEqual(self.clock.get_seconds(), 0, 3)

    def test_get_milis(self):
        time.sleep(0.001)
        self.assertAlmostEqual(self.clock.get_millis(), 1, 0)

    def test_subscribe(self):

        notifiables = [Notifiable() for _ in range(3)]

        for notifiable in notifiables:
            self.clock.subscribe_for_weekday(notifiable)
            self.clock.subscribe_for_minute(notifiable)

        for notifiable in notifiables:
            self.assertIn(notifiable, self.clock.objects_to_notify_weekday)
            self.assertIn(notifiable, self.clock.objects_to_notify_time)

    def test_evaluate_time(self):

        self.clock.evaluate_time()
        self.assertEqual(self.clock.now.minute, self.clock.minute)
        self.assertEqual(self.clock.now.weekday(), self.clock.weekday)

    def test_notification(self):

        notifiable_minute = Notifiable()

# Path: backend/components/clock.py
# class Clock:
#     """Holds actual time. 
#     Notifies about actual time
#     Notifies about week day"""
# 
#     _is_initialized = False
#     _instance = None
# 
#     def __new__(cls, *args, **kwargs):
#         if not cls._instance:
#             cls._instance = super().__new__(cls, *args, **kwargs)
#         return cls._instance
# 
#     def __init__(self, ):
#         if not Clock._is_initialized:
#             Clock._is_initialized = True
#             self.objects_to_notify_weekday = set()
#             self.objects_to_notify_time = set()
# 
#             self.now = None
#             self.minute = None
#             self.weekday = None
# 
#             self.system_start = time.time()
# 
#     def subscribe_for_weekday(self, who):
#         self.objects_to_notify_weekday.add(who)
# 
#     def subscribe_for_minute(self, who):
#         self.objects_to_notify_time.add(who)
# 
#     def notify_minute(self):
#         self.minute = self.now.minute
#         for _object in self.objects_to_notify_time:
#             _object.notify(self.now)
# 
#     def notify_weekday(self):
#         self.weekday = self.now.weekday()
#         for _object in self.objects_to_notify_weekday:
#             _object.notify(self.weekday)
# 
#     def evaluate_time(self, ):
#         """Evaluates current time. If minutes or day changes it notifies related objects"""
#         self.now = datetime.datetime.now()
#         
#         if self.now.minute != self.minute:
#             self.notify_minute()
# 
#         if self.weekday != self.now.weekday():
#             self.notify_weekday()
# 
#     def get_seconds(self):
#         return time.time() - self.system_start
# 
#     def get_millis(self):
#         return (time.time() - self.system_start)*1000
# 
#     def restart(self):
#         self.system_start = time.time()
# 
# Path: backend/components/tests/helper_classes.py
# class Notifiable:
# 
#     def __init__(self):
# 
#         self.val = None
# 
#     def notify(self, val):
# 
#         self.val = val


# Path: backend/components/tests/test_clock.py
import unittest
import datetime
import time
from backend.components.clock import Clock
from backend.components.tests.helper_classes import Notifiable

        self.clock.restart()

    def test_get_seconds(self):
        self.assertAlmostEqual(self.clock.get_seconds(), 0, 3)

    def test_get_milis(self):
        time.sleep(0.001)
        self.assertAlmostEqual(self.clock.get_millis(), 1, 0)

    def test_subscribe(self):

        notifiables = [Notifiable() for _ in range(3)]

        for notifiable in notifiables:
            self.clock.subscribe_for_weekday(notifiable)
            self.clock.subscribe_for_minute(notifiable)

        for notifiable in notifiables:
            self.assertIn(notifiable, self.clock.objects_to_notify_weekday)
            self.assertIn(notifiable, self.clock.objects_to_notify_time)

    def test_evaluate_time(self):

        self.clock.evaluate_time()
        self.assertEqual(self.clock.now.minute, self.clock.minute)
        self.assertEqual(self.clock.now.weekday(), self.clock.weekday)

    def test_notification(self):

        notifiable_minute = Notifiable()

        notifiable_weekday = Notifiable()