class ElfTest(unittest.TestCase):

    def setUp(self):
        self.elf1 = Elf(1)
        self.elf2 = Elf(2)

        # soln_file = os.path.join(os.getcwd(), 'test.csv')
        # self.wcsv = csv.writer(open(soln_file, "wb"))

    def test_num_of_working_minutes_left(self):

        self.assertEquals(self.elf1.num_of_working_minutes_left(), 600)

        self.elf1.set_next_available_time(600)

        self.assertEquals(self.elf1.num_of_working_minutes_left(), 600-60)

        self.elf1.set_next_available_time(540 + 595)

        self.assertEquals(self.elf1.num_of_working_minutes_left(), 5)

        self.elf1.set_next_available_time(540 + 605)

        self.assertEquals(self.elf1.num_of_working_minutes_left(), 0)

    def test_get_productivity(self):

        self.assertEquals(self.elf1.get_productivity(), 1.0)

        self.elf1.set_productivity(2.0)

        self.assertEquals(self.elf1.get_productivity(), 2.0)

    def test_wait_till_next_day(self):

        self.assertEquals(self.elf1.get_next_available_time(), 540)

        self.elf1.set_next_available_time(700)

        self.assertEquals(self.elf1.get_next_available_time(), 700)

        self.elf1.wait_till_next_day()

        self.assertEquals(self.elf1.get_next_available_time(), 1440+(9*60))

        self.elf1.wait_till_next_day()

        self.assertEquals(self.elf1.get_next_available_time(), (2*1440)+(9*60))
                print("TOYPOOL WAITING LEN : %d, TOYPOOL AVAILABLE LEN : %d" % (mytoypool.length_waiting_list(), mytoypool.length_available_list()))

            # Etape 1 Bis : Mettre à jour le toy pool par rapport à la date de disponibilité de l'elfe
            # Avancer jusqu'à ce qu'il y ait des jouets dans l'available list
            while True:
                mytoypool.update_available_toy_list_according_to_elf(elf)
                if mytoypool.length_available_list() > 0:
                    break
                else:
                    t = elf.get_next_available_time()
                    next_t = hrs.next_sanctioned_minute(t)
                    elf.set_next_available_time(next_t)


            # Etape 2 : Recupérer la productivité de l'elfe
            productivity = elf.get_productivity()
            
            # Gros jouet au hasard
            r = random.random()
            if r > RATIO_RANDOM:
                toy = mytoypool.get_next_longest_toy_for_elf(elf)
                elf.make_toy(toy, wcsv)
                continue

            # Etape 2, Cas 1 : La productivité est supérieure au seuil
            if productivity > PRODUCTIVITY_THRESHOLD and mytoypool.get_max_available_duration() > MIN_DURATION:
                # Etape 3 : Récupérer le jouet le plus gros disponible
                toy = mytoypool.get_next_longest_toy_for_elf(elf)

                if toy is not None:
                    # Etape 4 : Faire le jouet