Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffheaton committed Mar 26, 2014
1 parent 34b29a1 commit ced01ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion encog-core-cs.sln.DotSettings.user

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions encog-core-cs/Util/Normalize/DataNormalization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,12 @@ public void Process()
FirstPass();
}
SecondPass();

// clean up
foreach (var csv in _readCSV)
{
csv.Close();
}
}
/// <summary>
/// Call this method to begin the normalization process. Any status
Expand Down
29 changes: 15 additions & 14 deletions encog-core-test/Util/Normalize/TestNormCSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public class TestNormCSV
};

public static TempDir TEMP_DIR = new TempDir();
public static FileInfo FILENAME = TEMP_DIR.CreateFile("norm.csv");
public static FileInfo FILENAME1 = TEMP_DIR.CreateFile("norm1.csv");
public static FileInfo FILENAME2 = TEMP_DIR.CreateFile("norm2.csv");

private void Generate()
private void Generate(string filename)
{
IInputField a;
IInputField b;
Expand All @@ -59,11 +60,11 @@ private void Generate()
norm.AddOutputField(new OutputFieldDirect(c));
norm.AddOutputField(new OutputFieldDirect(d));
norm.AddOutputField(new OutputFieldDirect(e));
norm.Storage = new NormalizationStorageCSV(FILENAME.ToString());
norm.Storage = new NormalizationStorageCSV(filename.ToString());
norm.Process();
}

public DataNormalization Create(double[][] outputArray)
public DataNormalization Create(string filename, double[][] outputArray)
{
IInputField a;
IInputField b;
Expand All @@ -73,12 +74,12 @@ public DataNormalization Create(double[][] outputArray)

var norm = new DataNormalization();
norm.Report = new NullStatusReportable();
norm.Storage = new NormalizationStorageCSV(FILENAME.ToString());
norm.AddInputField(a = new InputFieldCSV(false, FILENAME.ToString(), 0));
norm.AddInputField(b = new InputFieldCSV(false, FILENAME.ToString(), 1));
norm.AddInputField(c = new InputFieldCSV(false, FILENAME.ToString(), 2));
norm.AddInputField(d = new InputFieldCSV(false, FILENAME.ToString(), 3));
norm.AddInputField(e = new InputFieldCSV(false, FILENAME.ToString(), 4));
norm.Storage = new NormalizationStorageCSV(filename.ToString());
norm.AddInputField(a = new InputFieldCSV(false, filename.ToString(), 0));
norm.AddInputField(b = new InputFieldCSV(false, filename.ToString(), 1));
norm.AddInputField(c = new InputFieldCSV(false, filename.ToString(), 2));
norm.AddInputField(d = new InputFieldCSV(false, filename.ToString(), 3));
norm.AddInputField(e = new InputFieldCSV(false, filename.ToString(), 4));
norm.AddOutputField(new OutputFieldRangeMapped(a, 0.1, 0.9));
norm.AddOutputField(new OutputFieldRangeMapped(b, 0.1, 0.9));
norm.AddOutputField(new OutputFieldRangeMapped(c, 0.1, 0.9));
Expand All @@ -92,8 +93,8 @@ public DataNormalization Create(double[][] outputArray)
public void TestGenerateAndLoad()
{
var outputArray = EngineArray.AllocateDouble2D(2, 5);
Generate();
DataNormalization norm = Create(outputArray);
Generate(FILENAME1.ToString());
DataNormalization norm = Create(FILENAME1.ToString(),outputArray);
norm.Process();
Check(norm);
}
Expand All @@ -102,8 +103,8 @@ public void TestGenerateAndLoad()
public void TestGenerateAndLoadSerial()
{
double[][] outputArray = EngineArray.AllocateDouble2D(2, 5);
Generate();
DataNormalization norm = Create(outputArray);
Generate(FILENAME2.ToString());
DataNormalization norm = Create(FILENAME2.ToString(),outputArray);
norm = (DataNormalization) SerializeRoundTrip.RoundTrip(norm);
norm.Process();
Check(norm);
Expand Down

0 comments on commit ced01ad

Please sign in to comment.