package lfsom.test;

import java.io.File;
import java.io.IOException;

import lfsom.data.LFSData;
import lfsom.experiment.TrainSelector;
import lfsom.properties.LFSExpProps;
import lfsom.properties.LFSSOMProperties;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class TestTrainSelector {

	static LFSData datos;
	static LFSExpProps expProps;
	static String dataPath = "./";
	static String rootPath = "./";
	static TrainSelector trainSel;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		// An expprops object is created
		expProps = new LFSExpProps();
		// Configure expProps
		expProps.useOnline(true);
		expProps.useBatch(true);
		// Autocalc width and height
		expProps.setWidthSOM(0);
		expProps.setHeightSOM(0);
		expProps.setSizeAut(true);

		expProps.setDataPath(dataPath);
		expProps.setRootPath(rootPath);

		expProps.setExpName("Test");

		expProps.setSigma("4");
		expProps.setBucleLearnRate("0.4");
		expProps.setBuclePcNeighWidth("8");

		// Type of SOM
		expProps.setGCHSOM(false);
		expProps.setGrowing(false);
		expProps.setHier(false);

		// Initializations
		expProps.setInitPCA(true);
		expProps.setInitRandom(false);
		expProps.setInitInterval(false);
		expProps.setInitVector(false);

		expProps.setBuclePcNeighWidth("0.1");
		// Neighbour functions
		expProps.setNeighCutGauss(true);
		expProps.setNeighGauss(false);
		expProps.setNeighBobble(false);

		// Parallel?
		expProps.setNumCPUs(1);

		expProps.setFicheroEntrada("noMatter");

		datos = LFSDataTest.generateTest(8, 1000);
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		// delete all files
		String[] fichs = new String[] { "ExpProps.xml", "kaski.xml",
				"kaski.xmlprops", "quan.xml", "quan.xmlprops", "topo.xml",
				"topo.xmlprops", "results.csv" };
		for (int i = 0; i < fichs.length; i++) {
			File fich = new File(dataPath + fichs[i]);
			fich.delete();
		}
	}

	@Test
	public void testLanzaExperimentoLFSDataLFSExpProps() throws IOException {

		LFSSOMProperties[] listaProps = expProps.generateLFSSOMProperties();

		trainSel = new TrainSelector();
		trainSel.LanzaExperimento(datos, expProps);

		// Now, read results.csv to see if there are results for all the nets
		File fich = new File(dataPath + "results.csv");
		Assert.assertTrue("Generated results file", fich.exists());
		/**
		 * TODO: read file an compare
		 */
		/*
		 * int nLines = 0; if (fich.exists()) { try (BufferedReader br = new
		 * BufferedReader(new FileReader(dataPath + "results.csv"))) { String
		 * line = br.readLine(); while (line != null) { nLines++; } } }
		 * Assert.assertEquals(nLines, listaProps.length * expProps.getNumRepe()
		 * + 1);
		 */

	}
}

@@ -31,20 +31,80 @@
 java.io.
-File
+BufferedReader;%0D%0Aimport java.io.File;%0D%0Aimport java.io.FileReader
 ;%0D%0Aimpor
@@ -2547,66 +2547,12 @@
 );%0D%0A
+%0D%0A
 %09%09
-/**%0D%0A%09%09 * TODO: read file an compare%0D%0A%09%09 */%0D%0A%09%09/*%0D%0A%09%09 * 
 int 
@@ -2562,17 +2562,20 @@
 nes = 0;
- 
+%0D%0A%09%09
 if (fich
@@ -2586,17 +2586,21 @@
 sts()) %7B
- 
+%0D%0A%09%09%09
 try (Buf
@@ -2619,22 +2619,16 @@
 br = new
-%0D%0A%09%09 *
  Buffere
@@ -2650,33 +2650,39 @@
 eReader(dataPath
- 
+%0D%0A%09%09%09%09%09
 + %22results.csv%22)
@@ -2689,21 +2689,20 @@
 )) %7B
- String%0D%0A%09%09 *
+%0D%0A%09%09%09%09String
  lin
@@ -2719,17 +2719,22 @@
 dLine();
- 
+%0D%0A%09%09%09%09
 while (l
@@ -2751,31 +2751,74 @@
 l) %7B
- nLines++; %7D %7D 
+%0D%0A%09%09%09%09%09line = br.readLine();%0D%0A%09%09%09%09%09nLines++;%0D%0A%09%09%09%09%7D%0D%0A%09%09%09%7D%0D%0A%09%09
 %7D%0D%0A%09%09
- * 
 Asse
@@ -2839,18 +2839,27 @@
 s(nLines
-,
  
+- 1,%0D%0A%09%09%09%09
 listaPro
@@ -2895,27 +2895,10 @@
 pe()
-%0D%0A%09%09 * + 1);%0D%0A%09%09 */
+);
 %0D%0A%0D%0A

test TrainSelector