forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 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,80 @@ | ||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.ML.Auto.Test | ||
{ | ||
[TestClass] | ||
public class ConversionTests | ||
{ | ||
[TestMethod] | ||
public void ConvertFloatMissingValues() | ||
{ | ||
var missingValues = new string[] | ||
{ | ||
"?", | ||
"na", "n/a", "nan", | ||
"NA", "N/A", "NaN", "NAN" | ||
}; | ||
|
||
foreach(var missingValue in missingValues) | ||
{ | ||
float value; | ||
var success = Conversions.TryParse(missingValue.AsMemory(), out value); | ||
Assert.IsTrue(success); | ||
Assert.AreEqual(value, float.NaN); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ConvertFloatParseFailure() | ||
{ | ||
var values = new string[] | ||
{ | ||
"a", "aa", "nb", "aaa", "naa", "nba", "n/b" | ||
}; | ||
|
||
foreach (var value in values) | ||
{ | ||
var success = Conversions.TryParse(value.AsMemory(), out float _); | ||
Assert.IsFalse(success); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ConvertBoolMissingValues() | ||
{ | ||
var missingValues = new string[] | ||
{ | ||
"", | ||
"no", "NO", "+1", "-1", | ||
"yes", "YES", | ||
"true", "TRUE", | ||
"false", "FALSE" | ||
}; | ||
|
||
foreach (var missingValue in missingValues) | ||
{ | ||
var success = Conversions.TryParse(missingValue.AsMemory(), out bool _); | ||
Assert.IsTrue(success); | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void ConvertBoolParseFailure() | ||
{ | ||
var values = new string[] | ||
{ | ||
"aa", "na", "+a", "-a", | ||
"aaa", "yaa", "yea", | ||
"aaaa", "taaa", "traa", "trua", | ||
"aaaaa", "fbbbb", "faaaa", "falaa", "falsa" | ||
}; | ||
|
||
foreach (var value in values) | ||
{ | ||
var success = Conversions.TryParse(value.AsMemory(), out bool _); | ||
Assert.IsFalse(success); | ||
} | ||
} | ||
} | ||
} |