<commit_before>//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

package org.uma.jmetal.operator.impl.selection;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.springframework.test.util.ReflectionTestUtils;
import org.uma.jmetal.problem.Problem;
import org.uma.jmetal.solution.Solution;
import org.uma.jmetal.util.JMetalException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import static junit.framework.TestCase.assertNotNull;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.*;

/**
 * @author <NAME>
 * @version 1.0
 */
public class NaryTournamentSelectionTest {
  private static final int POPULATION_SIZE = 20 ;

  private NaryTournamentSelection<?> selection ;
  private List<Solution<?>> population ;

  @Rule
  public ExpectedException exception = ExpectedException.none();

  @Test
  public void shouldDefaultConstructorSetTheNumberOfSolutionsToBeReturnedEqualsToTwo() {
    selection = new NaryTournamentSelection<Solution<?>>() ;

    assertEquals(2, ReflectionTestUtils.getField(selection, "numberOfSolutionsToBeReturned"));
  }

  @Test
  public void shouldExecuteRaiseAnExceptionIfTheListOfSolutionsIsNull() {
    exception.expect(JMetalException.class);
    exception.expectMessage(containsString("The solution list is null"));

    selection = new NaryTournamentSelection<Solution<?>>() ;
    population = null ;
    selection.execute(population) ;
  }

  @Test (expected = JMetalException.class)
  public void shouldExecuteRaiseAnExceptionIfTheListOfSolutionsIsEmpty() {
    selection = new NaryTournamentSelection<Solution<?>>() ;

    population = new ArrayList<>(0) ;

    selection.execute(population) ;
  }

  @Test
  public void shouldExecuteReturnAValidSolutionIsWithCorrectParameters() {
    selection = new NaryTournamentSelection<Solution<?>>() ;
    Solution<Object> solution = mock(Solution.class) ;

    Problem<Solution<Object>> problem = mock(Problem.class) ;

    Mockito.when(problem.createSolution()).thenReturn(solution) ;

    population = new ArrayList<>(POPULATION_SIZE) ;
    for (int i = 0 ; i < POPULATION_SIZE; i++) {
      population.add(problem.createSolution());
    }
    assertNotNull(selection.execute(population));
    verify(problem, times(POPULATION_SIZE)).createSolution();
  }

  @Test
  public void shouldExecuteReturnTheSameSolutionIfTheListContainsOneSolution() {
    selection = new NaryTournamentSelection<Solution<?>>(1, mock(Comparator.class)) ;
    Solution<?> solution = mock(Solution.class) ;

    population = new ArrayList<>(1) ;
    population.add(solution) ;
    assertSame(solution, selection.execute(population));
  }

  @Test
  public void shouldExecuteReturnTwoSolutionsIfTheListContainsTwoSolutions() {
    selection = new NaryTournamentSelection<Solution<?>>(2, mock(Comparator.class)) ;

    Solution<?> solution1 = mock(Solution.class) ;
    Solution<?> solution2 = mock(Solution.class) ;

    population = Arrays.asList(solution1, solution2) ;
    assertEquals(2, population.size());
  }

  @Test
  public void shouldExecuteRaiseAnExceptionIfTheListSizeIsOneAndTwoSolutionsAreRequested() {
    exception.expect(JMetalException.class);
    exception.expectMessage(containsString("The solution list size (1) is less than " +
        "the number of requested solutions (4)"));

    selection = new NaryTournamentSelection<Solution<?>>(4, mock(Comparator.class)) ;
    List<Solution<?>> list = new ArrayList<>(1) ;
    list.add(mock(Solution.class)) ;

    selection.execute(list) ;
  }
}
<commit_msg>Fixing compilation errors<commit_after>//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.

package org.uma.jmetal.operator.impl.selection;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mockito;
import org.springframework.test.util.ReflectionTestUtils;
import org.uma.jmetal.problem.Problem;
import org.uma.jmetal.solution.BinarySolution;
import org.uma.jmetal.solution.DoubleSolution;
import org.uma.jmetal.solution.IntegerSolution;
import org.uma.jmetal.util.JMetalException;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

/**
 * @author <NAME>
 * @version 1.0
 */
public class NaryTournamentSelectionTest {

  private static final int POPULATION_SIZE = 20 ;

  @Rule
  public ExpectedException exception = ExpectedException.none();

  @Test
  public void shouldDefaultConstructorSetTheNumberOfSolutionsToBeReturnedEqualsToTwo() {
    NaryTournamentSelection<IntegerSolution> selection = new NaryTournamentSelection<>() ;

    assertEquals(2, ReflectionTestUtils.getField(selection, "numberOfSolutionsToBeReturned"));
  }

  @Test
  public void shouldExecuteRaiseAnExceptionIfTheListOfSolutionsIsNull() {
    exception.expect(JMetalException.class);
    exception.expectMessage(containsString("The solution list is null"));

    NaryTournamentSelection<IntegerSolution> selection = new NaryTournamentSelection<>() ;
    List<IntegerSolution> population ;
    population = null ;

    selection.execute(population) ;
  }

  @Test (expected = JMetalException.class)
  public void shouldExecuteRaiseAnExceptionIfTheListOfSolutionsIsEmpty() {
    NaryTournamentSelection<IntegerSolution> selection = new NaryTournamentSelection<>() ;

    List<IntegerSolution> population = new ArrayList<>(0) ;

    selection.execute(population) ;
  }

  @Test
  public void shouldExecuteReturnAValidSolutionIsWithCorrectParameters() {
    NaryTournamentSelection<BinarySolution> selection = new NaryTournamentSelection<>() ;
    BinarySolution solution = mock(BinarySolution.class) ;

    Problem<BinarySolution> problem = mock(Problem.class) ;

    Mockito.when(problem.createSolution()).thenReturn(solution) ;

    List<BinarySolution> population = new ArrayList<>(POPULATION_SIZE) ;
    for (int i = 0 ; i < POPULATION_SIZE; i++) {
      population.add(problem.createSolution());
    }
    assertNotNull(selection.execute(population));
    verify(problem, times(POPULATION_SIZE)).createSolution();
  }

  @Test
  public void shouldExecuteReturnTheSameSolutionIfTheListContainsOneSolution() {
    NaryTournamentSelection<DoubleSolution>selection =
        new NaryTournamentSelection<DoubleSolution>(1, mock(Comparator.class)) ;
    DoubleSolution solution = mock(DoubleSolution.class) ;

    List<DoubleSolution> population = new ArrayList<>(1) ;
    population.add(solution) ;
    assertSame(solution, selection.execute(population));
  }

  @Test
  public void shouldExecuteReturnTwoSolutionsIfTheListContainsTwoSolutions() {
    NaryTournamentSelection<IntegerSolution> selection =
        new NaryTournamentSelection<>(2, mock(Comparator.class)) ;

    IntegerSolution solution1 = mock(IntegerSolution.class) ;
    IntegerSolution solution2 = mock(IntegerSolution.class) ;

    List<IntegerSolution> population = Arrays.asList(solution1, solution2) ;
    assertEquals(2, population.size());
  }

  @Test
  public void shouldExecuteRaiseAnExceptionIfTheListSizeIsOneAndTwoSolutionsAreRequested() {
    exception.expect(JMetalException.class);
    exception.expectMessage(containsString("The solution list size (1) is less than " +
        "the number of requested solutions (4)"));

    NaryTournamentSelection<IntegerSolution> selection =
        new NaryTournamentSelection<>(4, mock(Comparator.class)) ;
    List<IntegerSolution> list = new ArrayList<>(1) ;
    list.add(mock(IntegerSolution.class)) ;

    selection.execute(list) ;
  }
}

{'fraction_non_alphanumeric': 0.10077092511013216, 'fraction_numerical': 0.004405286343612335, 'mean_word_length': 4.862491930277598, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5941174', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2483, 'n_words': 606}