-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
All tests done other than Runtime tests
- Loading branch information
Showing
11 changed files
with
644 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using NUnit.Framework; | ||
using PicNetML.Tests.TestUtils; | ||
|
||
namespace PicNetML.Tests | ||
{ | ||
[TestFixture] | ||
public class AttributeExtensionsTests | ||
{ | ||
[Test] public void test_attribute_to_enumerable_gives_all_distinct_nominal_vals() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow>("titanic_train.csv", 0, 10); | ||
var pcclass = rt.Impl.attribute(1); | ||
var values = pcclass.ToEnumerable(); | ||
Assert.AreEqual(new [] {"1", "2", "3"}, values); | ||
} | ||
|
||
[Test] public void test_attribute_to_enumerable_gives_nothing_on_numerics() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow2>("titanic_train.csv", 0, 10); | ||
var age = rt.Impl.attribute(4); | ||
var values = age.ToEnumerable(); | ||
Assert.AreEqual(new string [0], values); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using PicNetML.Tests.TestUtils; | ||
|
||
namespace PicNetML.Tests | ||
{ | ||
[TestFixture] | ||
public class InstanceExtensionsTests | ||
{ | ||
[Test] public void test_ToStrings_gets_the_string_representation_of_the_instance() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow2>("titanic_train.csv", 0, 3); | ||
var instance = rt[0].Impl; | ||
var strs = instance.ToStrings(); | ||
Assert.AreEqual(new [] {"0", "3", "Braund, Mr. Owen Harris", "male", "22", "1", "0", "A/5 21171", "7.25", "?", "S"}, strs); | ||
} | ||
|
||
[Test] public void test_ToEnumerableAttributes() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow>("titanic_train.csv", 0, 3); | ||
var atts = rt[0].Impl.ToEnumerableAttributes(); | ||
var names = atts.Select(a => a.Name).ToArray(); | ||
Assert.AreEqual(new [] {"survived", "pclass", "sex", "embarked"}, names); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using PicNetML.Tests.TestUtils; | ||
|
||
namespace PicNetML.Tests | ||
{ | ||
[TestFixture] public class InstancesExtensionsTests | ||
{ | ||
[Test] public void test_GetAttrStrings() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow>("titanic_train.csv", 0, 5); | ||
var vals = rt.Impl.GetAttrStrings(1); | ||
CollectionAssert.AreEqual(new [] {"3","1","3","1","3"}, vals); | ||
} | ||
|
||
[Test] public void test_GetAttrDoubles() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow>("titanic_train.csv", 0, 5); | ||
var vals = rt.Impl.GetAttrDoubles(1); | ||
CollectionAssert.AreEqual(new [] {2.0,0.0,2.0,0.0,2.0}, vals); | ||
} | ||
|
||
[Test] public void test_ToEnumerableAttributes() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow>("titanic_train.csv", 0, 5); | ||
var atts = rt.Impl.ToEnumerableAttributes(); | ||
var names = atts.Select(a => a.Name).ToArray(); | ||
CollectionAssert.AreEqual(new [] {"survived", "pclass", "sex", "embarked"}, names); | ||
} | ||
|
||
[Test] public void test_ToEnumerable() | ||
{ | ||
var rt = TestingHelpers.LoadSmallRuntime<TitanicDataRow>("titanic_train.csv", 0, 5); | ||
var instances = rt.Impl.ToEnumerable(); | ||
Assert.AreEqual(5, instances.Count()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace PicNetML.Tests { | ||
namespace PicNetML.Tests.TestUtils { | ||
public static class TestingHelpers { | ||
public static string ReadResourceFile(string filename) { | ||
return File.ReadAllText(GetResourceFileName(filename)); | ||
} | ||
|
||
public static string GetResourceFileName(string filename) { | ||
return @"..\..\resources\" + filename; | ||
} | ||
|
||
public static Runtime LoadSmallRuntime<T>(string filename, int classidx, int count) where T : new() { | ||
var file = GetResourceFileName(filename); | ||
using (var fs = File.OpenText(file)) { | ||
string[] lines = Enumerable.Range(0, count + 1). | ||
Select(i => fs.ReadLine()). | ||
Skip(1). | ||
ToArray(); | ||
var rows = Runtime.LoadRowsFromLines<T>(lines); | ||
return Runtime.LoadFromRows(classidx, rows); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.