<commit_before>import unittest
import nose.tools
import numpy as np

from ..generator.tsp_generator import TSPGenerator
from ..ga.population_generation import SimplePopulationGenerator
from ..ga.selection import RouletteWheelSelection


class RouletteWheelSelectionTest(unittest.TestCase):

    def setUp(self):
        self._num_points = 100
        self._pop_size = 20
        self._subset_size = 10

        gen = TSPGenerator(self._num_points)
        self._data, self._distances = gen.generate()

        popGen = SimplePopulationGenerator(self._pop_size, self._distances)
        self._population = popGen.generate()

    def test_evaluate_simple_fitness(self):
        distances = np.array([[1., 1.41421356],
                              [1.41421356, 1.]])

        population = np.array([[0, 0],
                               [0, 1],
                               [1, 0],
                               [1, 1]])

        selector = RouletteWheelSelection(distances, 1)
        fitness = selector.fitness(population)

        nose.tools.assert_equal(fitness.size, 4)

        expected = np.array([2., 2.82842712, 2.82842712, 2.])
        np.testing.assert_array_equal(fitness, expected)

    def test_evaluate_fitness(self):
        selector = RouletteWheelSelection(self._distances, self._subset_size)
        fitness = selector.fitness(self._population)

        nose.tools.assert_equal(fitness.size, 20)

    def test_selection(self):
        selector = RouletteWheelSelection(self._distances, self._subset_size)
        subset = selector.selection(self._population)
        print subset

        exp_shape = (self._subset_size, self._num_points)
        nose.tools.assert_equal(subset.shape, exp_shape)<commit_msg>Refs #4 Remove debug statement.<commit_after>import unittest
import nose.tools
import numpy as np

from ..generator.tsp_generator import TSPGenerator
from ..ga.population_generation import SimplePopulationGenerator
from ..ga.selection import RouletteWheelSelection


class RouletteWheelSelectionTest(unittest.TestCase):

    def setUp(self):
        self._num_points = 100
        self._pop_size = 20
        self._subset_size = 10

        gen = TSPGenerator(self._num_points)
        self._data, self._distances = gen.generate()

        popGen = SimplePopulationGenerator(self._pop_size, self._distances)
        self._population = popGen.generate()

    def test_evaluate_simple_fitness(self):
        distances = np.array([[1., 1.41421356],
                              [1.41421356, 1.]])

        population = np.array([[0, 0],
                               [0, 1],
                               [1, 0],
                               [1, 1]])

        selector = RouletteWheelSelection(distances, 1)
        fitness = selector.fitness(population)

        nose.tools.assert_equal(fitness.size, 4)

        expected = np.array([2., 2.82842712, 2.82842712, 2.])
        np.testing.assert_array_equal(fitness, expected)

    def test_evaluate_fitness(self):
        selector = RouletteWheelSelection(self._distances, self._subset_size)
        fitness = selector.fitness(self._population)

        nose.tools.assert_equal(fitness.size, 20)

    def test_selection(self):
        selector = RouletteWheelSelection(self._distances, self._subset_size)
        subset = selector.selection(self._population)

        exp_shape = (self._subset_size, self._num_points)
        nose.tools.assert_equal(subset.shape, exp_shape)
{'fraction_non_alphanumeric': 0.09730668983492616, 'fraction_numerical': 0.034462785983203015, 'mean_word_length': 2.5101626016260163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2865572', 'n_tokens_mistral': 1091, 'n_tokens_neox': 979, 'n_words': 187}