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 2.0 kB

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