forked from SciSharp/TensorFlow.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputTest.cs
More file actions
55 lines (49 loc) · 1.91 KB
/
OutputTest.cs
File metadata and controls
55 lines (49 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Tensorflow.Binding;
using static Tensorflow.KerasApi;
using Tensorflow.Keras;
namespace Tensorflow.Keras.UnitTest
{
[TestClass]
public class OutputTest
{
[TestMethod]
public void OutputRedirectTest()
{
using var newOutput = new System.IO.StringWriter();
tf_output_redirect = newOutput;
var model = keras.Sequential();
model.add(keras.Input(shape: 16));
model.summary();
string output = newOutput.ToString();
Assert.IsTrue(output.StartsWith("Model: sequential"));
tf_output_redirect = null; // don't forget to change it to null !!!!
}
[TestMethod]
public void SwitchOutputsTest()
{
using var newOutput = new System.IO.StringWriter();
var model = keras.Sequential();
model.add(keras.Input(shape: 16));
model.summary(); // Console.Out
tf_output_redirect = newOutput; // change to the custom one
model.summary();
string firstOutput = newOutput.ToString();
Assert.IsTrue(firstOutput.StartsWith("Model: sequential"));
// if tf_output_reditect is StringWriter, calling "set" will make the writer clear.
tf_output_redirect = null; // null means Console.Out
model.summary();
tf_output_redirect = newOutput; // again, to test whether the newOutput is clear.
model.summary();
string secondOutput = newOutput.ToString();
Assert.IsTrue(secondOutput.StartsWith("Model: sequential"));
Assert.IsTrue(firstOutput == secondOutput);
tf_output_redirect = null; // don't forget to change it to null !!!!
}
}
}