<commit_before>package nl.esciencecenter.diffevo;

import static org.junit.Assert.*;

import org.junit.Test;

public class ListOfSamplesTest {

	@Test
	public void testListOfSamples() {

		int nPop = 10;
		int numberOfDimensions = 3;
		double[] lowerBounds = new double[]{-10,2.0,40};
		double[] upperBounds = new double[]{102,4.5,40.17};
		String[] parNames = new String[]{"a","b","c"};
		ParSpace parSpace = new ParSpace(lowerBounds,upperBounds,parNames);
		ListOfSamples listOfSamplesActual = new ListOfSamples(nPop,parSpace);
		
		Sample expectedSample = new Sample(numberOfDimensions);
		double[] parameterVectorExpected = expectedSample.getParameterVector();
		double parameterVectorAcceptableDifference = 0.0;
		double objScoreExpected = expectedSample.getObjScore();
		double objScoreAcceptableDifference = 0.0;
				
		int nSamples = nPop;
		for (int iSample = 0;iSample<nSamples;iSample++){
			
			double[] parameterVectorActual = listOfSamplesActual.getParameterVector(iSample);
			assertArrayEquals(parameterVectorExpected,parameterVectorActual,parameterVectorAcceptableDifference);
			
			double objScoreActual = listOfSamplesActual.getObjScore(iSample);
			assertEquals(objScoreExpected,objScoreActual,objScoreAcceptableDifference);
			
		}

		assertEquals(nPop, listOfSamplesActual.getSize());
		
	}

	@Test
	public void testAdd() {

		// make the list of samples
		int nPop = 2;
		int numberOfDimensions = 3;
		double[] lowerBounds = new double[]{-10,2.0,40};
		double[] upperBounds = new double[]{102,4.5,40.17};
		String[] parNames = new String[]{"a","b","c"};
		ParSpace parSpace = new ParSpace(lowerBounds,upperBounds,parNames);
		ListOfSamples listOfSamplesActual = new ListOfSamples(nPop,parSpace);
		
		// make the new sample
		Sample sample = new Sample(numberOfDimensions);
		int sampleCounterExpected = nPop+1;
		sample.setSampleCounter(sampleCounterExpected);
		
		double[] parameterVectorExpected = new double[]{-3.4,3.2,40.05};
		sample.setParameterVector(parameterVectorExpected);
		
		double objScoreExpected = -1.234;
		sample.setObjScore(objScoreExpected);
		
		// add the new sample to the list of samples
		listOfSamplesActual.add(sample);
		
		// verify the size
		assertEquals(nPop+1, listOfSamplesActual.getSize());
		
		// verify the parameter vector 
		double[] parameterVectorActual = listOfSamplesActual.getParameterVector(nPop);
		double parameterVectorAcceptableDifference = 0.0;
		for (int iDim=0;iDim<numberOfDimensions;iDim++){
			assertEquals(parameterVectorExpected[iDim], parameterVectorActual[iDim],parameterVectorAcceptableDifference);
		}
		
		double objScoreActual = listOfSamplesActual.getObjScore(nPop);
		double objScoreAcceptableDifference = 0.0;
		assertEquals(objScoreExpected, objScoreActual,objScoreAcceptableDifference);
		
		
	}
//
//	@Test
//	public void testSetParameterVector() {
//		fail("Not yet implemented");
//	}
//
//	@Test
//	public void testGetParameterVector() {
//		fail("Not yet implemented");
//	}
//
//	@Test
//	public void testSetObjScore() {
//		fail("Not yet implemented");
//	}
//
//	@Test
//	public void testGetObjScore() {
//		fail("Not yet implemented");
//	}
//
//	@Test
//	public void testCalcObjScore() {
//		fail("Not yet implemented");
//	}

}<commit_msg>added unit tests for ListOfSamples class<commit_after>package nl.esciencecenter.diffevo;

import static org.junit.Assert.*;

import java.util.List;

import org.junit.Test;

public class ListOfSamplesTest {

	private static int nPopExpected;
	private static ParSpace parSpaceExpected;
	private static int nDimsExpected;
	
	public ListOfSamplesTest(){
		nPopExpected = 50;
		double[] lowerBounds = new double[]{-20,-40,-80,-120};
		double[] upperBounds = new double[]{ 20, 40, 80, 120};
		String[] parNames = new String[]{"a","b","c","d"};
		parSpaceExpected = new ParSpace(lowerBounds,upperBounds,parNames);
		nDimsExpected = lowerBounds.length;
		
	}
	
	
	@Test
	public void testListOfSamples() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		int nDimsActual = listOfSamples.getnDims();
		assertTrue(nDimsActual==nDimsExpected);
		 
		int nPopActual = listOfSamples.getnPop();
		assertTrue(nPopActual == nPopExpected);
		
		ParSpace parSpaceActual = listOfSamples.getparSpace();

		assertTrue(parSpaceActual.equals(parSpaceExpected));

		int nPars = parSpaceActual.getNumberOfPars();
		
		List<Sample> sampleList = listOfSamples.getSampleList(); 
		
		int sampleCounterExpected = -1;
		
		for (int iPop=0;iPop<nPopActual;iPop++){
			
			int sampleCounterActual = sampleList.get(iPop).getSampleCounter(); 
			assertTrue(sampleCounterActual==sampleCounterExpected);
			
			double[] parameterVectorActual = sampleList.get(iPop).getParameterVector();
			for (int iPar=0;iPar<nPars;iPar++){
				assertTrue(Double.isNaN(parameterVectorActual[iPar]));
			}
			
			double objScoreActual = sampleList.get(iPop).getObjScore();
			assertTrue(Double.isNaN(objScoreActual));
			
		}
		
	}

	@Test
	public void testAdd() {
		
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		int nParsActual = listOfSamples.getparSpace().getNumberOfPars();

		Sample sampleExpected = new Sample(nDimsExpected);
		
		int sampleCounterExpected = 51;
		double[] parameterVectorExpected = new double[]{-0.11,1.2,-13.0,140};
		double objScoreExpected = -12345.6789;
		
		sampleExpected.setSampleCounter(sampleCounterExpected);
		sampleExpected.setParameterVector(parameterVectorExpected);
		sampleExpected.setObjScore(objScoreExpected);
		
		listOfSamples.add(sampleExpected);
		
		assertTrue(listOfSamples.getSize()==nPopExpected+1);

		double[] parameterVectorActual = listOfSamples.getParameterVector(nPopExpected);
		for (int iPar=0; iPar<nParsActual;iPar++){
			assertTrue(parameterVectorActual[iPar] == parameterVectorExpected[iPar]);
		}
		
		double objScoreActual = listOfSamples.getObjScore(nPopExpected);
		assertTrue(objScoreActual==objScoreExpected);

	}

	@Test
	public void testSetParameterVector() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		double[] parameterVectorExpected = new double[]{-1.0,2.0,-3.0,4.0};
		listOfSamples.setParameterVector(0, parameterVectorExpected);
		
		double[] parameterVectorActual = listOfSamples.getParameterVector(0);
		
		int nPars = listOfSamples.getparSpace().getNumberOfPars();
		
		for (int iPar=0;iPar<nPars;iPar++){
			assertTrue(parameterVectorActual[iPar]==parameterVectorExpected[iPar]);
		}
		
	}

	@Test
	public void testGetParameterVector() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		double[] parameterVectorExpected = new double[]{-1.0,2.0,-3.0,4.0};
		listOfSamples.setParameterVector(0, parameterVectorExpected);
		
		double[] parameterVectorActual = listOfSamples.getParameterVector(0);
		
		int nPars = listOfSamples.getparSpace().getNumberOfPars();
		
		for (int iPar=0;iPar<nPars;iPar++){
			assertTrue(parameterVectorActual[iPar]==parameterVectorExpected[iPar]);
		}

	}

	@Test
	public void testSetObjScore() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		double objScoreExpected = -123.456;
		listOfSamples.setObjScore(0, objScoreExpected);
		
		double objScoreActual = listOfSamples.getObjScore(0);
		
		assertTrue(objScoreActual==objScoreExpected);

	}

	@Test
	public void testGetObjScore() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		double objScoreExpected = -123.456;
		listOfSamples.setObjScore(0, objScoreExpected);
		
		double objScoreActual = listOfSamples.getObjScore(0);
		
		assertTrue(objScoreActual==objScoreExpected);
	}

	@Test
	public void testCalcObjScore() {
		//TODO
	}

	@Test
	public void testGetSize() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		int nPopActual = listOfSamples.getSize();
		
		assertTrue(nPopActual==nPopExpected);

	}

	@Test
	public void testGetnPop() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		int nPopActual = listOfSamples.getnPop();
		
		assertTrue(nPopActual==nPopExpected);

	}

	@Test
	public void testGetnDims() {
		ListOfSamples listOfSamples = new ListOfSamples(nPopExpected,parSpaceExpected);
		
		int nDimsActual = listOfSamples.getparSpace().getNumberOfPars();
		
		assertTrue(nDimsActual==nDimsExpected);

	}

	@Test
	public void testGetparSpace() {
		//TODO
	}

	@Test
	public void testGetSampleList() {
		ListOfSamples listOfSamples = new ListOfSamples(0,parSpaceExpected);

		int nPars = listOfSamples.getparSpace().getNumberOfPars();

		for (int iPop=0;iPop<nPopExpected;iPop++){
			
			Sample sample = new Sample(nDimsExpected);
			double[] parameterVectorExpected = new double[]{0.3+iPop,0.4+iPop,0.5+iPop,0.6+iPop}; 
			double objScoreExpected = iPop*-10.0;
			
			sample.setSampleCounter(iPop);
			sample.setParameterVector(parameterVectorExpected);
			sample.setObjScore(objScoreExpected);
			
			listOfSamples.add(sample);
		}
		
		
		List<Sample> sampleList = listOfSamples.getSampleList(); 
		
		for (int iPop=0;iPop<nPopExpected;iPop++){
			
			int sampleCounterExpected = iPop;
			double[] parameterVectorExpected = new double[]{0.3+iPop,0.4+iPop,0.5+iPop,0.6+iPop}; 
			double objScoreExpected = iPop*-10.0;
			
			int sampleCounterActual = sampleList.get(iPop).getSampleCounter();
			assertTrue(sampleCounterActual==sampleCounterExpected);
			
			double[] parameterVectorActual = listOfSamples.getParameterVector(iPop);
			for (int iPar = 0;iPar<nPars;iPar++){
				assertTrue(parameterVectorActual[iPar]==parameterVectorExpected[iPar]); 
			}

			
			double objScoreActual = sampleList.get(iPop).getObjScore();
			assertTrue(objScoreActual==objScoreExpected);
		}
		
		
	}

}
{'fraction_non_alphanumeric': 0.11684059750358093, 'fraction_numerical': 0.017393083691426232, 'mean_word_length': 5.2024111675126905, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6717625', 'n_tokens_mistral': 3598, 'n_tokens_neox': 3050, 'n_words': 536}