Skip to content

Commit 71488b4

Browse files
committed
seperate TensorFlowNET.Graph.UnitTest project.
1 parent dded90a commit 71488b4

25 files changed

Lines changed: 533 additions & 2707 deletions

TensorFlow.NET.sln

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29102.190
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31423.177
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Binding", "src\TensorFlowNET.Core\Tensorflow.Binding.csproj", "{FD682AC0-7B2D-45D3-8B0D-C6D678B04144}"
77
EndProject
@@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Native.UnitTest"
2121
EndProject
2222
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tensorflow.Keras.UnitTest", "test\TensorFlowNET.Keras.UnitTest\Tensorflow.Keras.UnitTest.csproj", "{79EB56DF-E29E-4AE2-A7D9-FE403FD919BA}"
2323
EndProject
24+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TensorFlowNET.Graph.UnitTest", "test\TensorFlowNET.Graph.UnitTest\TensorFlowNET.Graph.UnitTest.csproj", "{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}"
25+
EndProject
2426
Global
2527
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2628
Debug|Any CPU = Debug|Any CPU
@@ -139,6 +141,18 @@ Global
139141
{79EB56DF-E29E-4AE2-A7D9-FE403FD919BA}.Release|x64.Build.0 = Release|Any CPU
140142
{79EB56DF-E29E-4AE2-A7D9-FE403FD919BA}.Release|x86.ActiveCfg = Release|Any CPU
141143
{79EB56DF-E29E-4AE2-A7D9-FE403FD919BA}.Release|x86.Build.0 = Release|Any CPU
144+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
145+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
146+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Debug|x64.ActiveCfg = Debug|x64
147+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Debug|x64.Build.0 = Debug|x64
148+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Debug|x86.ActiveCfg = Debug|Any CPU
149+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Debug|x86.Build.0 = Debug|Any CPU
150+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
151+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Release|Any CPU.Build.0 = Release|Any CPU
152+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Release|x64.ActiveCfg = Release|Any CPU
153+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Release|x64.Build.0 = Release|Any CPU
154+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Release|x86.ActiveCfg = Release|Any CPU
155+
{3F5388FF-FBB4-462B-8F6F-829FFBAEB8A3}.Release|x86.Build.0 = Release|Any CPU
142156
EndGlobalSection
143157
GlobalSection(SolutionProperties) = preSolution
144158
HideSolutionNode = FALSE

test/TensorFlowNET.UnitTest/Basics/QueueTest.cs renamed to test/TensorFlowNET.Graph.UnitTest/Basics/QueueTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using System.Linq;
33
using Tensorflow;
4-
using Tensorflow.UnitTest;
54
using static Tensorflow.Binding;
65

76
namespace TensorFlowNET.UnitTest.Basics

test/TensorFlowNET.UnitTest/control_flow_ops_test/CondTestCases.cs renamed to test/TensorFlowNET.Graph.UnitTest/ControlFlowTest/CondTestCases.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using Tensorflow;
3-
using Tensorflow.UnitTest;
43
using static Tensorflow.Binding;
54

6-
namespace TensorFlowNET.UnitTest.control_flow_ops_test
5+
namespace TensorFlowNET.UnitTest.ControlFlowTest
76
{
87
/// <summary>
98
/// excerpt of tensorflow/python/framework/ops/control_flow_ops_test.py

test/TensorFlowNET.UnitTest/control_flow_ops_test/ShapeTestCase.cs renamed to test/TensorFlowNET.Graph.UnitTest/ControlFlowTest/ShapeTestCase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using Tensorflow;
3-
using Tensorflow.UnitTest;
43

5-
namespace TensorFlowNET.UnitTest.control_flow_ops_test
4+
namespace TensorFlowNET.UnitTest.ControlFlowTest
65
{
76
/// <summary>
87
/// excerpt of tensorflow/python/framework/ops/control_flow_ops_test.py

test/TensorFlowNET.UnitTest/control_flow_ops_test/WhileContextTestCase.cs renamed to test/TensorFlowNET.Graph.UnitTest/ControlFlowTest/WhileContextTestCase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using System;
33
using Tensorflow;
4-
using Tensorflow.UnitTest;
54
using static Tensorflow.Binding;
65

7-
namespace TensorFlowNET.UnitTest.control_flow_ops_test
6+
namespace TensorFlowNET.UnitTest.ControlFlowTest
87
{
98
[TestClass]
109
public class WhileContextTestCase : GraphModeTestBase

test/TensorFlowNET.UnitTest/functional_ops_test/ScanTestCase.cs renamed to test/TensorFlowNET.Graph.UnitTest/FunctionalOpsTest/ScanTestCase.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
using Tensorflow.NumPy;
33
using System;
44
using Tensorflow;
5-
using Tensorflow.UnitTest;
65
using static Tensorflow.Binding;
76

8-
namespace TensorFlowNET.UnitTest.functional_ops_test
7+
namespace TensorFlowNET.UnitTest.FunctionalOpsTest
98
{
109
/// <summary>
1110
/// https://www.tensorflow.org/api_docs/python/tf/scan
@@ -22,7 +21,8 @@ public void ScanForward()
2221

2322
var input = tf.placeholder(TF_DataType.TF_INT32, new TensorShape(6));
2423
var scan = functional_ops.scan(fn, input);
25-
sess.run(scan, (input, np.array(1, 2, 3, 4, 5, 6))).Should().Be(np.array(1, 3, 6, 10, 15, 21));
24+
var result = sess.run(scan, (input, np.array(1, 2, 3, 4, 5, 6)));
25+
Assert.AreEqual(result, np.array(1, 3, 6, 10, 15, 21));
2626
}
2727

2828
[TestMethod, Ignore("need UpdateEdge API")]
@@ -34,7 +34,8 @@ public void ScanReverse()
3434

3535
var input = tf.placeholder(TF_DataType.TF_INT32, new TensorShape(6));
3636
var scan = functional_ops.scan(fn, input, reverse: true);
37-
sess.run(scan, (input, np.array(1, 2, 3, 4, 5, 6))).Should().Be(np.array(21, 20, 18, 15, 11, 6));
37+
var result = sess.run(scan, (input, np.array(1, 2, 3, 4, 5, 6)));
38+
Assert.AreEqual(result, np.array(21, 20, 18, 15, 11, 6));
3839
}
3940
}
4041
}

test/TensorFlowNET.UnitTest/GradientTest/GradientTest.cs renamed to test/TensorFlowNET.Graph.UnitTest/GradientTest/GradientTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using Tensorflow;
7-
using Tensorflow.UnitTest;
87
using static Tensorflow.Binding;
98

109
namespace TensorFlowNET.UnitTest.Gradient

test/TensorFlowNET.UnitTest/GraphModeTestBase.cs renamed to test/TensorFlowNET.Graph.UnitTest/GraphModeTestBase.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
2-
using TensorFlowNET.UnitTest;
32
using static Tensorflow.Binding;
4-
using static Tensorflow.KerasApi;
53

6-
namespace Tensorflow.UnitTest
4+
namespace TensorFlowNET.UnitTest
75
{
86
public class GraphModeTestBase : PythonTest
97
{
@@ -16,7 +14,6 @@ public void TestInit()
1614
[TestCleanup]
1715
public void TestClean()
1816
{
19-
keras.backend.clear_session();
2017
tf.enable_eager_execution();
2118
}
2219
}

test/TensorFlowNET.UnitTest/ImageTest.cs renamed to test/TensorFlowNET.Graph.UnitTest/ImageTest.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using FluentAssertions;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using Tensorflow.NumPy;
43
using System.Linq;
54
using Tensorflow;
6-
using Tensorflow.UnitTest;
75
using static Tensorflow.Binding;
86

9-
namespace TensorFlowNET.UnitTest.Basics
7+
namespace TensorFlowNET.UnitTest
108
{
119
/// <summary>
1210
/// Find more examples in https://www.programcreek.com/python/example/90444/tensorflow.read_file
@@ -84,14 +82,14 @@ public void TestCropAndResize()
8482

8583
var result = sess.run(cropped);
8684
// check if cropped to 1x1 center was succesfull
87-
result.size.Should().Be(1);
88-
result[0, 0, 0, 0].Should().Be(4f);
85+
Assert.AreEqual(result.size, 1);
86+
Assert.AreEqual(result[0, 0, 0, 0], 4f);
8987

9088
cropped = tf.image.crop_and_resize(image2, box, boxInd, cropSize2_2);
9189
result = sess.run(cropped);
9290
// check if flipped and no cropping occured
93-
result.size.Should().Be(16);
94-
result[0, 0, 0, 0].Should().Be(12f);
91+
Assert.AreEqual(result.size, 16);
92+
Assert.AreEqual(result[0, 0, 0, 0], 12f);
9593

9694
}
9795
}

test/TensorFlowNET.UnitTest/MultithreadingTests.cs renamed to test/TensorFlowNET.Graph.UnitTest/MultithreadingTests.cs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
using FluentAssertions;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
32
using Tensorflow.NumPy;
43
using System;
54
using System.IO;
65
using System.Linq;
76
using System.Runtime.InteropServices;
87
using Tensorflow;
9-
using Tensorflow.UnitTest;
108
using static Tensorflow.Binding;
119

1210
namespace TensorFlowNET.UnitTest
@@ -24,15 +22,15 @@ public void SessionCreation()
2422
//the core method
2523
void Core(int tid)
2624
{
27-
tf.peak_default_graph().Should().BeNull();
25+
Assert.IsNull(tf.peak_default_graph());
2826

2927
using (var sess = tf.Session())
3028
{
3129
var default_graph = tf.peak_default_graph();
32-
var sess_graph = sess.GetPrivate<Graph>("_graph");
33-
sess_graph.Should().NotBeNull();
34-
default_graph.Should().NotBeNull()
35-
.And.BeEquivalentTo(sess_graph);
30+
var sess_graph = sess.graph;
31+
Assert.IsNotNull(default_graph);
32+
Assert.IsNotNull(sess_graph);
33+
Assert.AreEqual(default_graph, sess_graph);
3634
}
3735
}
3836
}
@@ -47,15 +45,15 @@ public void SessionCreation_x2()
4745
//the core method
4846
void Core(int tid)
4947
{
50-
tf.peak_default_graph().Should().BeNull();
48+
Assert.IsNull(tf.peak_default_graph());
5149
//tf.Session created an other graph
5250
using (var sess = tf.Session())
5351
{
5452
var default_graph = tf.peak_default_graph();
55-
var sess_graph = sess.GetPrivate<Graph>("_graph");
56-
sess_graph.Should().NotBeNull();
57-
default_graph.Should().NotBeNull()
58-
.And.BeEquivalentTo(sess_graph);
53+
var sess_graph = sess.graph;
54+
Assert.IsNotNull(default_graph);
55+
Assert.IsNotNull(sess_graph);
56+
Assert.AreEqual(default_graph, sess_graph);
5957
}
6058
}
6159
}
@@ -70,19 +68,18 @@ public void GraphCreation()
7068
//the core method
7169
void Core(int tid)
7270
{
73-
tf.peak_default_graph().Should().BeNull();
71+
Assert.IsNull(tf.peak_default_graph());
7472
var beforehand = tf.get_default_graph(); //this should create default automatically.
75-
beforehand.graph_key.Should().NotContain("-0/", "Already created a graph in an other thread.");
7673
beforehand.as_default();
77-
tf.peak_default_graph().Should().NotBeNull();
74+
Assert.IsNotNull(tf.peak_default_graph());
7875

7976
using (var sess = tf.Session())
8077
{
8178
var default_graph = tf.peak_default_graph();
82-
var sess_graph = sess.GetPrivate<Graph>("_graph");
83-
sess_graph.Should().NotBeNull();
84-
default_graph.Should().NotBeNull()
85-
.And.BeEquivalentTo(sess_graph);
79+
var sess_graph = sess.graph;
80+
Assert.IsNotNull(default_graph);
81+
Assert.IsNotNull(sess_graph);
82+
Assert.AreEqual(default_graph, sess_graph);
8683

8784
Console.WriteLine($"{tid}-{default_graph.graph_key}");
8885

@@ -188,7 +185,7 @@ public void SessionRun()
188185
//the core method
189186
void Core(int tid)
190187
{
191-
tf.peak_default_graph().Should().BeNull();
188+
Assert.IsNull(tf.peak_default_graph());
192189
//graph is created automatically to perform create these operations
193190
var a1 = tf.constant(new[] { 2f }, shape: new[] { 1 });
194191
var a2 = tf.constant(new[] { 3f }, shape: new[] { 1 });
@@ -197,7 +194,8 @@ void Core(int tid)
197194
{
198195
using (var sess = tf.Session())
199196
{
200-
sess.run(math).GetAtIndex<float>(0).Should().Be(5);
197+
var result = sess.run(math);
198+
Assert.AreEqual(result.GetAtIndex<float>(0), 5f);
201199
}
202200
}
203201
}
@@ -213,14 +211,14 @@ void Core(int tid)
213211
{
214212
using (var sess = tf.Session())
215213
{
216-
tf.peak_default_graph().Should().NotBeNull();
214+
Assert.IsNotNull(tf.peak_default_graph());
217215
//graph is created automatically to perform create these operations
218216
var a1 = tf.constant(new[] { 2f }, shape: new[] { 1 });
219217
var a2 = tf.constant(new[] { 3f }, shape: new[] { 1 });
220218
var math = a1 + a2;
221219

222220
var result = sess.run(math);
223-
result.GetAtIndex<float>(0).Should().Be(5);
221+
Assert.AreEqual(result.GetAtIndex<float>(0), 5f);
224222
}
225223
}
226224
}
@@ -235,7 +233,7 @@ void Core(int tid)
235233
{
236234
using (var sess = tf.Session())
237235
{
238-
tf.peak_default_graph().Should().NotBeNull();
236+
Assert.IsNotNull(tf.peak_default_graph());
239237
//graph is created automatically to perform create these operations
240238
var a1 = tf.constant(new[] { 2f }, shape: new[] { 1 });
241239
var a2 = tf.constant(new[] { 3f }, shape: new[] { 1 });
@@ -252,7 +250,7 @@ public void SessionRun_Initialization_OutsideSession()
252250
//the core method
253251
void Core(int tid)
254252
{
255-
tf.peak_default_graph().Should().BeNull();
253+
Assert.IsNull(tf.peak_default_graph());
256254
//graph is created automatically to perform create these operations
257255
var a1 = tf.constant(new[] { 2f }, shape: new[] { 1 });
258256
var a2 = tf.constant(new[] { 3f }, shape: new[] { 1 });
@@ -268,7 +266,7 @@ public void TF_GraphOperationByName()
268266
//the core method
269267
void Core(int tid)
270268
{
271-
tf.peak_default_graph().Should().BeNull();
269+
Assert.IsNull(tf.peak_default_graph());
272270
//graph is created automatically to perform create these operations
273271
var a1 = tf.constant(new[] { 2f }, shape: new[] { 1 });
274272
var a2 = tf.constant(new[] { 3f }, shape: new[] { 1 }, name: "ConstantK");

0 commit comments

Comments
 (0)