From 4bc97cd47842e842c0beffe6a88c824df92f6120 Mon Sep 17 00:00:00 2001 From: Meinrad Recheis Date: Thu, 11 Apr 2019 14:38:25 +0200 Subject: [PATCH] added all examples to the unit testing suite --- src/TensorFlowNET.Core/Python.cs | 13 ++- test/TensorFlowNET.Examples/BasicEagerApi.cs | 2 +- .../TensorFlowNET.Examples/BasicOperations.cs | 2 +- test/TensorFlowNET.Examples/HelloWorld.cs | 2 +- test/TensorFlowNET.Examples/IExample.cs | 2 +- .../ImageRecognition.cs | 2 +- .../InceptionArchGoogLeNet.cs | 2 +- .../KMeansClustering.cs | 2 +- .../LinearRegression.cs | 2 +- .../LogisticRegression.cs | 2 +- test/TensorFlowNET.Examples/MetaGraph.cs | 2 +- .../NaiveBayesClassifier.cs | 2 +- .../NamedEntityRecognition.cs | 2 +- .../TensorFlowNET.Examples/NearestNeighbor.cs | 2 +- .../TextClassificationTrain.cs | 2 +- .../TextClassificationWithMovieReviews.cs | 2 +- .../ExamplesTests/ExamplesTest.cs | 99 +++++++++++++++++++ .../TensorFlowNET.UnitTest.csproj | 1 + 18 files changed, 125 insertions(+), 18 deletions(-) create mode 100644 test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs diff --git a/src/TensorFlowNET.Core/Python.cs b/src/TensorFlowNET.Core/Python.cs index 2d8e3e8e..f6fb08c8 100644 --- a/src/TensorFlowNET.Core/Python.cs +++ b/src/TensorFlowNET.Core/Python.cs @@ -46,7 +46,10 @@ namespace Tensorflow catch (Exception ex) { Console.WriteLine(ex.ToString()); - throw ex; +#if DEBUG + Debugger.Break(); +#endif + throw; } finally { @@ -65,7 +68,10 @@ namespace Tensorflow catch (Exception ex) { Console.WriteLine(ex.ToString()); - throw ex; +#if DEBUG + Debugger.Break(); +#endif + throw; } finally { @@ -85,8 +91,9 @@ namespace Tensorflow { Console.WriteLine(ex.ToString()); #if DEBUG - Debugger.Break(); + Debugger.Break(); #endif + throw; return default(TOut); } finally diff --git a/test/TensorFlowNET.Examples/BasicEagerApi.cs b/test/TensorFlowNET.Examples/BasicEagerApi.cs index 0c4f4bbf..f0ac68d4 100644 --- a/test/TensorFlowNET.Examples/BasicEagerApi.cs +++ b/test/TensorFlowNET.Examples/BasicEagerApi.cs @@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples public class BasicEagerApi : IExample { public int Priority => 100; - public bool Enabled => false; + public bool Enabled { get; set; } = false; public string Name => "Basic Eager"; private Tensor a, b, c, d; diff --git a/test/TensorFlowNET.Examples/BasicOperations.cs b/test/TensorFlowNET.Examples/BasicOperations.cs index 5e46d8a9..21082866 100644 --- a/test/TensorFlowNET.Examples/BasicOperations.cs +++ b/test/TensorFlowNET.Examples/BasicOperations.cs @@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples /// public class BasicOperations : Python, IExample { - public bool Enabled => true; + public bool Enabled { get; set; } = true; public int Priority => 2; public string Name => "Basic Operations"; diff --git a/test/TensorFlowNET.Examples/HelloWorld.cs b/test/TensorFlowNET.Examples/HelloWorld.cs index b0ddeb34..717e4192 100644 --- a/test/TensorFlowNET.Examples/HelloWorld.cs +++ b/test/TensorFlowNET.Examples/HelloWorld.cs @@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples public class HelloWorld : Python, IExample { public int Priority => 1; - public bool Enabled => true; + public bool Enabled { get; set; } = true; public string Name => "Hello World"; public bool Run() diff --git a/test/TensorFlowNET.Examples/IExample.cs b/test/TensorFlowNET.Examples/IExample.cs index c8320810..3b31e58f 100644 --- a/test/TensorFlowNET.Examples/IExample.cs +++ b/test/TensorFlowNET.Examples/IExample.cs @@ -17,7 +17,7 @@ namespace TensorFlowNET.Examples /// /// True to run example /// - bool Enabled { get; } + bool Enabled { get; set; } string Name { get; } diff --git a/test/TensorFlowNET.Examples/ImageRecognition.cs b/test/TensorFlowNET.Examples/ImageRecognition.cs index 963fa1d7..4ff82168 100644 --- a/test/TensorFlowNET.Examples/ImageRecognition.cs +++ b/test/TensorFlowNET.Examples/ImageRecognition.cs @@ -13,7 +13,7 @@ namespace TensorFlowNET.Examples public class ImageRecognition : Python, IExample { public int Priority => 7; - public bool Enabled => true; + public bool Enabled { get; set; } = true; public string Name => "Image Recognition"; string dir = "ImageRecognition"; diff --git a/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs b/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs index fe80b95d..052cf920 100644 --- a/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs +++ b/test/TensorFlowNET.Examples/InceptionArchGoogLeNet.cs @@ -19,7 +19,7 @@ namespace TensorFlowNET.Examples /// public class InceptionArchGoogLeNet : Python, IExample { - public bool Enabled => false; + public bool Enabled { get; set; } = false; public int Priority => 100; public string Name => "Inception Arch GoogLeNet"; diff --git a/test/TensorFlowNET.Examples/KMeansClustering.cs b/test/TensorFlowNET.Examples/KMeansClustering.cs index 93fae200..bbbaad40 100644 --- a/test/TensorFlowNET.Examples/KMeansClustering.cs +++ b/test/TensorFlowNET.Examples/KMeansClustering.cs @@ -16,7 +16,7 @@ namespace TensorFlowNET.Examples public class KMeansClustering : Python, IExample { public int Priority => 8; - public bool Enabled => true; + public bool Enabled { get; set; } = true; public string Name => "K-means Clustering"; Datasets mnist; diff --git a/test/TensorFlowNET.Examples/LinearRegression.cs b/test/TensorFlowNET.Examples/LinearRegression.cs index 944874dd..15ebfc54 100644 --- a/test/TensorFlowNET.Examples/LinearRegression.cs +++ b/test/TensorFlowNET.Examples/LinearRegression.cs @@ -13,7 +13,7 @@ namespace TensorFlowNET.Examples public class LinearRegression : Python, IExample { public int Priority => 3; - public bool Enabled => true; + public bool Enabled { get; set; } = true; public string Name => "Linear Regression"; NumPyRandom rng = np.random; diff --git a/test/TensorFlowNET.Examples/LogisticRegression.cs b/test/TensorFlowNET.Examples/LogisticRegression.cs index 65025008..32133ce2 100644 --- a/test/TensorFlowNET.Examples/LogisticRegression.cs +++ b/test/TensorFlowNET.Examples/LogisticRegression.cs @@ -17,7 +17,7 @@ namespace TensorFlowNET.Examples public class LogisticRegression : Python, IExample { public int Priority => 4; - public bool Enabled => true; + public bool Enabled { get; set; } = true; public string Name => "Logistic Regression"; private float learning_rate = 0.01f; diff --git a/test/TensorFlowNET.Examples/MetaGraph.cs b/test/TensorFlowNET.Examples/MetaGraph.cs index d05386f2..eb24996d 100644 --- a/test/TensorFlowNET.Examples/MetaGraph.cs +++ b/test/TensorFlowNET.Examples/MetaGraph.cs @@ -10,7 +10,7 @@ namespace TensorFlowNET.Examples public class MetaGraph : Python, IExample { public int Priority => 100; - public bool Enabled => false; + public bool Enabled { get; set; } = false; public string Name => "Meta Graph"; public bool Run() diff --git a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs index ffa827e6..46db7793 100644 --- a/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs +++ b/test/TensorFlowNET.Examples/NaiveBayesClassifier.cs @@ -13,7 +13,7 @@ namespace TensorFlowNET.Examples public class NaiveBayesClassifier : Python, IExample { public int Priority => 6; - public bool Enabled => true; + public bool Enabled { get; set; } = true; public string Name => "Naive Bayes Classifier"; public Normal dist { get; set; } diff --git a/test/TensorFlowNET.Examples/NamedEntityRecognition.cs b/test/TensorFlowNET.Examples/NamedEntityRecognition.cs index a6c7f2f1..3826e04d 100644 --- a/test/TensorFlowNET.Examples/NamedEntityRecognition.cs +++ b/test/TensorFlowNET.Examples/NamedEntityRecognition.cs @@ -11,7 +11,7 @@ namespace TensorFlowNET.Examples public class NamedEntityRecognition : Python, IExample { public int Priority => 100; - public bool Enabled => false; + public bool Enabled { get; set; } = false; public string Name => "NER"; public bool Run() diff --git a/test/TensorFlowNET.Examples/NearestNeighbor.cs b/test/TensorFlowNET.Examples/NearestNeighbor.cs index 91e14f9e..4b236558 100644 --- a/test/TensorFlowNET.Examples/NearestNeighbor.cs +++ b/test/TensorFlowNET.Examples/NearestNeighbor.cs @@ -15,7 +15,7 @@ namespace TensorFlowNET.Examples public class NearestNeighbor : Python, IExample { public int Priority => 5; - public bool Enabled => true; + public bool Enabled { get; set; } = true; public string Name => "Nearest Neighbor"; Datasets mnist; NDArray Xtr, Ytr, Xte, Yte; diff --git a/test/TensorFlowNET.Examples/TextClassification/TextClassificationTrain.cs b/test/TensorFlowNET.Examples/TextClassification/TextClassificationTrain.cs index 1ac5ce19..e08882f1 100644 --- a/test/TensorFlowNET.Examples/TextClassification/TextClassificationTrain.cs +++ b/test/TensorFlowNET.Examples/TextClassification/TextClassificationTrain.cs @@ -15,7 +15,7 @@ namespace TensorFlowNET.Examples.CnnTextClassification public class TextClassificationTrain : Python, IExample { public int Priority => 100; - public bool Enabled => false; + public bool Enabled { get; set; }= false; public string Name => "Text Classification"; private string dataDir = "text_classification"; diff --git a/test/TensorFlowNET.Examples/TextClassification/TextClassificationWithMovieReviews.cs b/test/TensorFlowNET.Examples/TextClassification/TextClassificationWithMovieReviews.cs index c6472b95..9030daec 100644 --- a/test/TensorFlowNET.Examples/TextClassification/TextClassificationWithMovieReviews.cs +++ b/test/TensorFlowNET.Examples/TextClassification/TextClassificationWithMovieReviews.cs @@ -12,7 +12,7 @@ namespace TensorFlowNET.Examples public class TextClassificationWithMovieReviews : Python, IExample { public int Priority => 9; - public bool Enabled => false; + public bool Enabled { get; set; } = false; public string Name => "Movie Reviews"; string dir = "text_classification_with_movie_reviews"; diff --git a/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs new file mode 100644 index 00000000..beb97d48 --- /dev/null +++ b/test/TensorFlowNET.UnitTest/ExamplesTests/ExamplesTest.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TensorFlowNET.Examples; +using TensorFlowNET.Examples.CnnTextClassification; + +namespace TensorFlowNET.UnitTest.ExamplesTests +{ + [TestClass] + public class ExamplesTest + { + [TestMethod] + public void BasicOperations() + { + new BasicOperations() { Enabled = true }.Run(); + } + + [TestMethod] + public void HelloWorld() + { + new HelloWorld() { Enabled = true }.Run(); + } + + [TestMethod] + public void ImageRecognition() + { + new HelloWorld() { Enabled = true }.Run(); + } + + [Ignore] + [TestMethod] + public void InceptionArchGoogLeNet() + { + new InceptionArchGoogLeNet() { Enabled = true }.Run(); + } + + [Ignore] + [TestMethod] + public void KMeansClustering() + { + new KMeansClustering() { Enabled = true }.Run(); + } + + [TestMethod] + public void LinearRegression() + { + new LinearRegression() { Enabled = true }.Run(); + } + + [TestMethod] + public void LogisticRegression() + { + new LogisticRegression() { Enabled = true }.Run(); + } + + [Ignore] + [TestMethod] + public void MetaGraph() + { + new MetaGraph() { Enabled = true }.Run(); + } + + [Ignore] + [TestMethod] + public void NaiveBayesClassifier() + { + new NaiveBayesClassifier() { Enabled = true }.Run(); + } + + [Ignore] + [TestMethod] + public void NamedEntityRecognition() + { + new NamedEntityRecognition() { Enabled = true }.Run(); + } + + [TestMethod] + public void NearestNeighbor() + { + new NearestNeighbor() { Enabled = true }.Run(); + } + + [Ignore] + [TestMethod] + public void TextClassificationTrain() + { + new TextClassificationTrain() { Enabled = true }.Run(); + } + + [Ignore] + [TestMethod] + public void TextClassificationWithMovieReviews() + { + new TextClassificationWithMovieReviews() { Enabled = true }.Run(); + } + + } +} diff --git a/test/TensorFlowNET.UnitTest/TensorFlowNET.UnitTest.csproj b/test/TensorFlowNET.UnitTest/TensorFlowNET.UnitTest.csproj index a3dd23ec..05530031 100644 --- a/test/TensorFlowNET.UnitTest/TensorFlowNET.UnitTest.csproj +++ b/test/TensorFlowNET.UnitTest/TensorFlowNET.UnitTest.csproj @@ -23,6 +23,7 @@ +