# -*- coding: utf-8 -*-

import main
import unittest


class GeneticChromosomeFloatConvertTest(unittest.TestCase):
    def test_genetic_chromosome_length_should_be_the_same(self):
        g = main.Genetic()
        self.assertEqual(len(g.chromosome), g.length)

    def test_set_negative_10_chromosome_and_should_convert_to_negative_10(self):
        negative_10 = '1100000000100100000000000000000000000000000000000000000000000000'
        g = main.Genetic()
        g.chromosome = negative_10

        self.assertEqual(g.value, -10.0)

    def test_set_positive_14_chromosome_should_convert_to_positive_10(self):
        positive_14 = '0100000000101100000000000000000000000000000000000000000000000000'
        g = main.Genetic()
        g.chromosome = positive_14

        self.assertEqual(g.value, 14.0)

    def test_set_chromosome_in_string_should_get_with_string(self):
        chromosome = '0100000000101100000000000000000000000000000000000000000000000000'
        g = main.Genetic()
        g.chromosome = chromosome

        self.assertEqual(g.chromosome, chromosome)

    def test_chromosome_should_convert_to_float(self):
        g = main.Genetic()
        self.assertIsInstance(g.value, float)


class GeneticMutationTest(unittest.TestCase):
    def test_genetic_mutation_in_10_parts_should_mutate_10_different_position(self):
        g = main.Genetic()
        gc_before = g.chromosome

        g.mutation(10)
        gc_after = g.chromosome

        diff_count = 0
        for before, after in zip(gc_before, gc_after):
            if before != after:
                diff_count += 1

        self.assertEqual(diff_count, 10)


class GeneticCrossoverTest(unittest.TestCase):
    def test_after_genetic_crossover_should_get_value_successfully(self):
        a = main.Genetic()
        b = main.Genetic()

        child = a.crossover(b, 60)
        self.assertIsInstance(child.value, float)


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