You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

OutputTest.cs 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using static Tensorflow.Binding;
  3. using static Tensorflow.KerasApi;
  4. namespace Tensorflow.Keras.UnitTest
  5. {
  6. [TestClass]
  7. public class OutputTest
  8. {
  9. [TestMethod]
  10. public void OutputRedirectTest()
  11. {
  12. using var newOutput = new System.IO.StringWriter();
  13. tf_output_redirect = newOutput;
  14. var model = keras.Sequential();
  15. model.add(keras.Input(shape: 16));
  16. model.summary();
  17. string output = newOutput.ToString();
  18. Assert.IsTrue(output.StartsWith("Model: sequential"));
  19. tf_output_redirect = null; // don't forget to change it to null !!!!
  20. }
  21. [TestMethod]
  22. public void SwitchOutputsTest()
  23. {
  24. using var newOutput = new System.IO.StringWriter();
  25. var model = keras.Sequential();
  26. model.add(keras.Input(shape: 16));
  27. model.summary(); // Console.Out
  28. tf_output_redirect = newOutput; // change to the custom one
  29. model.summary();
  30. string firstOutput = newOutput.ToString();
  31. Assert.IsTrue(firstOutput.StartsWith("Model: sequential"));
  32. // if tf_output_reditect is StringWriter, calling "set" will make the writer clear.
  33. tf_output_redirect = null; // null means Console.Out
  34. model.summary();
  35. tf_output_redirect = newOutput; // again, to test whether the newOutput is clear.
  36. model.summary();
  37. string secondOutput = newOutput.ToString();
  38. Assert.IsTrue(secondOutput.StartsWith("Model: sequential"));
  39. Assert.IsTrue(firstOutput == secondOutput);
  40. tf_output_redirect = null; // don't forget to change it to null !!!!
  41. }
  42. }
  43. }