from repositories.textfile import TextFileRepository
from repositories.memory import MemoryRepository
from repositories.binaryfile import BinaryFileRepository
from domain.domain import Expense

import unittest

class UnitTester(unittest.TestCase):
    def test_memory_repo(self):
        repo=MemoryRepository()
        list_of_expenses=repo.get_elements()
        e=Expense(10,200,"Gucci")
        list_of_expenses.append(e)
        repo.insert_element(e)
        self.assertEqual(list_of_expenses,repo.get_elements())

    def test_textfile_repo(self):
        repo=TextFileRepository(path="src/templetes/textmemory.bin")
        e=Expense(10,200,"Gucci")
        list_of_expenses=repo.get_elements()
        repo.insert_element(e)
        list_of_expenses.append(e)
        repo_list=repo.get_elements()
        self.assertEqual(len(list_of_expenses),len(repo_list))
        for i in range(len(list_of_expenses)):
            self.assertEqual(list_of_expenses[i].get_day(),repo_list[i].get_day())
            self.assertEqual(list_of_expenses[i].get_money(),repo_list[i].get_money())
            self.assertEqual(list_of_expenses[i].get_type_of_expense(),repo_list[i].get_type_of_expense())
        repo.undo()


    def test_binaryfile_repo(self):
        repo=BinaryFileRepository(path="src/templetes/binarymemory.bin")
        e=Expense(10,200,"Gucci")
        list_of_expenses=repo.get_elements()
        repo.insert_element(e)
        list_of_expenses.append(e)
        repo_list=repo.get_elements()
        self.assertEqual(len(list_of_expenses),len(repo_list))
        for i in range(len(list_of_expenses)):
            self.assertEqual(list_of_expenses[i].get_day(),repo_list[i].get_day())
            self.assertEqual(list_of_expenses[i].get_money(),repo_list[i].get_money())
            self.assertEqual(list_of_expenses[i].get_type_of_expense(),repo_list[i].get_type_of_expense())
        repo.undo()

if __name__=="__main__":
    unittest.main()