import sys
import os
sys.path.append(os.getcwd())
from search_classes import *
import unittest
from datetime import datetime

class DescriptionEntityTest(unittest.TestCase):
    def test_eq_with_self(self):
        desc=DescriptionModel(Text="abc")
        self.assertTrue(desc==desc)

    def test_not_eq_wrong_type(self):
        desc=DescriptionModel(Text="abc")
        timefrm=TimeframeModel(Start=datetime(2015, 8, 5), End=datetime(2019, 8, 5))
        self.assertFalse(desc==timefrm)

    def test_eq_same_text(self):
        desc=DescriptionModel(Text="abc")
        desc_1=DescriptionModel(Text="abc")
        self.assertTrue(desc==desc_1)

    def test_eq_embedding(self):
        desc=DescriptionModel(Embedding=[1,1,1])
        desc_1=DescriptionModel(Embedding=[1,1,0.9])
        self.assertTrue(desc==desc_1)

    def test_not_eq_embedding(self):
        desc=DescriptionModel(Embedding=[1,1,1])
        desc_1=DescriptionModel(Embedding=[-1,-1,-1])
        self.assertFalse(desc==desc_1)

class TimeframeModelTest(unittest.TestCase):
    def test_could_overlap(self):
        start_date_0 = datetime(2023, 8, 5)
        end_date_0 = datetime(2023, 8, 15)
        start_date_1 = datetime(2023, 8, 1)
        end_date_1 = datetime(2023, 8, 10)
        tfm_0 = TimeframeModel(Start=start_date_0, End=end_date_0)
        tfm_1= TimeframeModel(Start= start_date_1, End= end_date_1)
        self.assertTrue(tfm_0.could_overlap(tfm_1))

    def test_could_not_overlap(self):
        start_date_0 = datetime(2023, 8, 5)
        end_date_0 = datetime(2023, 8, 15)
        start_date_1 = datetime(2023, 9, 1)
        end_date_1 = datetime(2023, 9, 10)
        tfm_0 = TimeframeModel(Start=start_date_0, End=end_date_0)
        tfm_1= TimeframeModel(Start= start_date_1, End= end_date_1)
        self.assertFalse(tfm_0.could_overlap(tfm_1))

    def test_could_overlap_missing_start(self):
        end_date_0 = datetime(2023, 8, 15)
        start_date_1 = datetime(2023, 8, 1)
        end_date_1 = datetime(2023, 8, 10)
        tfm_0 = TimeframeModel(End=end_date_0)
        tfm_1= TimeframeModel(Start= start_date_1, End= end_date_1)
        self.assertTrue(tfm_0.could_overlap(tfm_1))

    def test_could_overlap_missing_end(self):
        start_date_0 = datetime(2023, 8, 5)
        start_date_1 = datetime(2023, 8, 1)
        end_date_1 = datetime(2023, 8, 10)
        tfm_0 = TimeframeModel(Start=start_date_0)
        tfm_1= TimeframeModel(Start= start_date_1, End= end_date_1)
        self.assertTrue(tfm_0.could_overlap(tfm_1))

    def test_could_not_overlap_missing_start(self):
        end_date_0 = datetime(2023, 8, 15)
        start_date_1 = datetime(2023, 9, 1)
        end_date_1 = datetime(2023, 9, 10)
        tfm_0 = TimeframeModel(End=end_date_0)
        tfm_1= TimeframeModel(Start= start_date_1, End= end_date_1)
        self.assertFalse(tfm_0.could_overlap(tfm_1))

    def test_could_not_overlap_missing_end(self):
        start_date_0 = datetime(2023, 10, 5)
        start_date_1 = datetime(2023, 9, 1)
        end_date_1 = datetime(2023, 9, 10)
        tfm_0 = TimeframeModel(Start=start_date_0)
        tfm_1= TimeframeModel(Start= start_date_1, End= end_date_1)
        self.assertFalse(tfm_0.could_overlap(tfm_1))

class GeneralExperienceTest(unittest.TestCase):
    def test_init(self):
        general_experience=GeneralExperience(Institution="google", Specialization="accountant")
        self.assertIsNotNone(general_experience.SpecializationDescription)
        self.assertIsNotNone(general_experience.InstitutionDescription)
        self.assertIsNotNone(general_experience.Tagline)

    def test_str(self):
        instit='harvard'
        special='gender studies'
        edu=GeneralExperience(Institution=instit, Specialization=special)
        self.assertTrue(str(edu)=='{} at {}'.format(special, instit))

    def test_eq(self):
        instit='harvard'
        special='gender studies'
        self.assertTrue(GeneralExperience(Institution=instit, Specialization=special)==GeneralExperience(Institution=instit, Specialization=special))

    def test_not_eq(self):
        instit='harvard'
        special='gender studies'
        diff_special="chemistry"
        self.assertFalse(GeneralExperience(Institution=instit, Specialization=diff_special)==GeneralExperience(Institution=instit, Specialization=special))

class CandidateTest(unittest.TestCase):
    def test_init(self):
        skill_list=["dance", "ballet"]
        workplace="American Ballet Theatre"
        school="julliard"
        work_experience_list=[WorkExperience(Institution=workplace, Specialization="Dancer")]
        education_experience_list=[EducationExperience(Institution=school, Specialization="classical ballet")]
        name="Misty Copeland"
        uuid="abcxyz"
        cand=Candidate(
                       Name=name, 
                       WorkExperienceList=work_experience_list,
                       EducationExperienceList=education_experience_list,
                       Skills=skill_list)
        self.assertIsNotNone(cand.Summary)
        summary_text=cand.Summary.Text
        self.assertNotEqual(len(summary_text),0)
        self.assertNotEqual(summary_text.find(name), -1)
        self.assertNotEqual(summary_text.find(workplace), -1)
        self.assertNotEqual(summary_text.find(school), -1)
        
    def test_eq_from_sources(self):
        source_list=["linkedin.com/jacobsmith", "github.com/jakegithubuser"]
        cand_0=Candidate(Name="jake smith",Sources=source_list)
        cand_1=Candidate(Name="jacob smith", Sources=source_list)
        self.assertTrue(cand_0==cand_1)

    def test_eq_from_summaries(self):
        work_experience_list=[WorkExperience(Institution="new york times", Specialization="reporter")]
        education_experience_list=[EducationExperience(Institution="harvard", Specialization="english")]
        cand_0=Candidate(Name="nick kristof",WorkExperienceList=work_experience_list,
                         EducationExperienceList=education_experience_list)
        cand_1=Candidate( Name="nicholas kristof", WorkExperienceList=work_experience_list,
                         EducationExperienceList=education_experience_list)
        self.assertTrue(cand_0==cand_1)



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