/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2019 JaamSim Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.BasicObjects;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

import com.jaamsim.basicsim.JaamSimModel;
import com.jaamsim.basicsim.Simulation;
import com.jaamsim.input.ExpResult;
import com.jaamsim.input.InputAgent;

public class TestFileToMatrix {

	JaamSimModel simModel;

	@Before
	public void setupTests() {
		simModel = new JaamSimModel();
		simModel.createInstance(Simulation.class);
	}

	@Test
	public void testValue() {
		FileToMatrix fileToMatrix = InputAgent.defineEntityWithUniqueName(simModel, FileToMatrix.class, "FileToMatrix1", "", true);
		ArrayList<ArrayList<Object>> data = new ArrayList<>();

		ArrayList<Object> list1 = new ArrayList<>();
		list1.add(1.5d);
		list1.add("abc");
		data.add(list1);

		ArrayList<Object> list2 = new ArrayList<>();
		list2.add(2.5d);
		list2.add("def");
		data.add(list2);
		try {
			fileToMatrix.setValue(data);
		}
		catch (Exception e) {
			System.out.println(e.getMessage());
		}

		ArrayList<ArrayList<ExpResult>> val = fileToMatrix.getOutputHandle("Value").getValue(0.0d, ArrayList.class);
		//System.out.println(val);
		assertTrue( val.get(0).get(0).value == 1.5d );
		assertTrue( val.get(0).get(1).stringVal.equals("abc") );
		assertTrue( val.get(1).get(0).value == 2.5d );
		assertTrue( val.get(1).get(1).stringVal.equals("def") );
	}

}

@@ -878,16 +878,51 @@
 lation;%0A
+import com.jaamsim.input.ExpError;%0A
 import c
@@ -985,16 +985,91 @@
 utAgent;
+%0Aimport com.jaamsim.units.DimensionlessUnit;%0Aimport com.jaamsim.units.Unit;
 %0A%0Apublic
@@ -1712,102 +1712,12 @@
 a);%0A
+%0A%09
 %09%09
-%7D%0A%09%09catch (Exception e) %7B%0A%09%09%09System.out.println(e.getMessage());%0A%09%09%7D%0A%0A%09%09ArrayList%3CArrayList%3C
 ExpR
@@ -1721,18 +1721,16 @@
 xpResult
-%3E%3E
  val = f
@@ -1781,24 +1781,24 @@
 e(0.0d, 
-ArrayLis
+ExpResul
 t.class)
@@ -1799,16 +1799,17 @@
 class);%0A
+%09
 %09%09//Syst
@@ -1833,38 +1833,250 @@
 l);%0A
+%0A
 %09%09
-assertTrue( val.get(0).get(0
+%09Class%3C? extends Unit%3E ut = DimensionlessUnit.class;%0A%09%09%09ExpResult ind1 = ExpResult.makeNumResult(1, ut);%0A%09%09%09ExpResult ind2 = ExpResult.makeNumResult(2, ut);%0A%0A%09%09%09ExpResult row1 = val.colVal.index(ind1);%0A%09%09%09assertTrue( row1.colVal.index(ind1
 ).va
@@ -2084,32 +2084,33 @@
 ue == 1.5d );%0A%09%09
+%09
 assertTrue( val.
@@ -2109,24 +2109,30 @@
 ue( 
-val.get(0).get(1
+row1.colVal.index(ind2
 ).st
@@ -2160,38 +2160,90 @@
  );%0A
-%09%09assertTrue( val.get(1).get(0
+%0A%09%09%09ExpResult row2 = val.colVal.index(ind2);%0A%09%09%09assertTrue( row2.colVal.index(ind1
 ).va
@@ -2259,16 +2259,17 @@
 5d );%0A%09%09
+%09
 assertTr
@@ -2276,24 +2276,30 @@
 ue( 
-val.get(1).get(1
+row2.colVal.index(ind2
 ).st
@@ -2323,14 +2323,84 @@
 ef%22) );%0A
+%09%09%7D%0A%09%09catch (ExpError e) %7B%0A%09%09%09System.out.println(e.getMessage());%0A%09%09%7D%0A
 %09%7D%0A%0A%7D%0A

convert unit test for FileToMatrix for return of an ExpResult