package org.uma.jmetal.solution.compositesolution;

import org.apache.commons.lang3.tuple.MutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Test;
import org.uma.jmetal.solution.Solution;
import org.uma.jmetal.solution.binarysolution.BinarySolution;
import org.uma.jmetal.solution.binarysolution.impl.DefaultBinarySolution;
import org.uma.jmetal.solution.doublesolution.DoubleSolution;
import org.uma.jmetal.solution.doublesolution.impl.DefaultDoubleSolution;
import org.uma.jmetal.solution.integersolution.IntegerSolution;
import org.uma.jmetal.solution.integersolution.impl.DefaultIntegerSolution;

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

import static org.junit.Assert.*;

public class CompositeSolutionTest {
  @Test
  public void shouldConstructorCreateAValidNotNullCompositeSolutionComposedOfABinarySolution() {
    BinarySolution solution = new DefaultBinarySolution(Arrays.asList(2, 2, 2), 3);

    assertNotNull(new CompositeSolution(Arrays.asList(solution)));
  }

  @Test
  public void
      shouldConstructorCreateAValidCompositeSolutionComposedOfaDoubleAndAnIntegerSolutions() {
    int numberOfObjectives = 2;
    int numberOfConstraints = 1;
    DoubleSolution doubleSolution =
        new DefaultDoubleSolution(
            Arrays.asList(new MutablePair<>(3.0, 5.0)), numberOfObjectives, numberOfConstraints);
    IntegerSolution integerSolution =
        new DefaultIntegerSolution(
            Arrays.asList(new MutablePair<>(2, 10)), numberOfObjectives, numberOfConstraints);

    CompositeSolution solution =
        new CompositeSolution(Arrays.asList(doubleSolution, integerSolution));
    assertNotNull(solution);
    assertEquals(2, solution.getNumberOfVariables());
    assertEquals(numberOfObjectives, solution.getNumberOfObjectives());
    assertEquals(numberOfConstraints, solution.getNumberOfConstraints());
    assertEquals(numberOfObjectives, solution.getVariable(0).getNumberOfObjectives());
    assertEquals(numberOfObjectives, solution.getVariable(1).getNumberOfObjectives());
    assertEquals(numberOfConstraints, solution.getVariable(0).getNumberOfConstraints());
    assertEquals(numberOfConstraints, solution.getVariable(1).getNumberOfConstraints());
    assertTrue(solution.getVariable(0) instanceof DoubleSolution);
    assertTrue(solution.getVariable(1) instanceof IntegerSolution);
  }

  @Test
  public void shouldCopyConstructorWorkProperly() {
    int numberOfObjectives = 2;
    int numberOfConstraints = 1;
    DoubleSolution doubleSolution =
        new DefaultDoubleSolution(
            Arrays.asList(new MutablePair<>(3.0, 5.0), new MutablePair<>(1.0, 3.0)),
            numberOfObjectives,
            numberOfConstraints);
    IntegerSolution integerSolution =
        new DefaultIntegerSolution(
            Arrays.asList(new MutablePair<>(2, 10)), numberOfObjectives, numberOfConstraints);

    CompositeSolution solution =
        new CompositeSolution(Arrays.asList(doubleSolution, integerSolution));

    CompositeSolution newSolution = new CompositeSolution(solution) ;

    assertEquals(solution.getNumberOfVariables(), newSolution.getNumberOfVariables());
    assertEquals(solution.getNumberOfObjectives(), newSolution.getNumberOfObjectives());
    assertEquals(solution.getNumberOfConstraints(), newSolution.getNumberOfConstraints());

    assertEquals(solution.getVariable(0).getNumberOfVariables(), newSolution.getVariable(0).getNumberOfVariables());
    assertEquals(solution.getVariable(1).getNumberOfVariables(), newSolution.getVariable(1).getNumberOfVariables());
    assertNotSame(solution.getVariable(0), newSolution.getVariable(0));
    assertNotSame(solution.getVariable(1), newSolution.getVariable(1));

    assertEquals(solution.getVariable(0).getVariables(), newSolution.getVariable(0).getVariables());
    assertEquals(solution.getVariable(1).getVariables(), newSolution.getVariable(1).getVariables());
  }
}

@@ -766,24 +766,25 @@
 nTest %7B%0A
+%0A
   @Test%0A
   public
@@ -767,32 +767,161 @@
 Test %7B%0A%0A  @Test%0A
+  public void shouldContructorRaiseAnExceptionIfTheNumberOfObjectivesIsIncoherent() %7B%0A%0A  %7D%0A%0A  @Test (expected = Exception.class)%0A
   public void sh
@@ -1005,22 +1005,22 @@
 ) %7B%0A    
-Binary
+Double
 Solution
@@ -1012,33 +1012,39 @@
  DoubleSolution 
-s
+doubleS
 olution = new De
@@ -1032,24 +1032,36 @@
 leSolution =
+%0A           
  new Default
@@ -1056,30 +1056,30 @@
  new Default
-Binary
+Double
 Solution(Arr
@@ -1079,55 +1079,231 @@
 ion(
-Arrays.asList(2, 2, 2), 3);%0A%0A    assertNotNull(
+%0A                    Arrays.asList(new MutablePair%3C%3E(3.0, 5.0)), 3, 0);%0A    IntegerSolution integerSolution =%0A            new DefaultIntegerSolution(%0A                    Arrays.asList(new MutablePair%3C%3E(2, 10)), 2, 0);%0A%0A    
 new 
@@ -1338,19 +1338,42 @@
 ist(
-solution)
+doubleSolution, integerSolution
 ))
+ 
 ;%0A  

Add unit test case