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

DemonstrationTests.cs 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections.Generic;
  2. using NUnit.Framework;
  3. using UnityEngine;
  4. using System.IO.Abstractions.TestingHelpers;
  5. namespace MLAgents.Tests
  6. {
  7. public class DemonstrationTests : MonoBehaviour
  8. {
  9. private const string DemoDirecory = "Assets/Demonstrations/";
  10. private const string ExtensionType = ".demo";
  11. private const string DemoName = "Test";
  12. [Test]
  13. public void TestSanitization()
  14. {
  15. const string dirtyString = "abc123&!@";
  16. const string knownCleanString = "abc123";
  17. var cleanString = DemonstrationRecorder.SanitizeName(dirtyString);
  18. Assert.AreNotEqual(dirtyString, cleanString);
  19. Assert.AreEqual(cleanString, knownCleanString);
  20. }
  21. [Test]
  22. public void TestStoreInitalize()
  23. {
  24. var fileSystem = new MockFileSystem();
  25. var demoStore = new DemonstrationStore(fileSystem);
  26. Assert.IsFalse(fileSystem.Directory.Exists(DemoDirecory));
  27. var brainParameters = new BrainParameters
  28. {
  29. vectorObservationSize = 3,
  30. numStackedVectorObservations = 2,
  31. cameraResolutions = new [] {new Resolution()},
  32. vectorActionDescriptions = new [] {"TestActionA", "TestActionB"},
  33. vectorActionSize = new [] {2, 2},
  34. vectorActionSpaceType = SpaceType.discrete
  35. };
  36. demoStore.Initialize(DemoName, brainParameters, "TestBrain");
  37. Assert.IsTrue(fileSystem.Directory.Exists(DemoDirecory));
  38. Assert.IsTrue(fileSystem.FileExists(DemoDirecory + DemoName + ExtensionType));
  39. var agentInfo = new AgentInfo
  40. {
  41. reward = 1f,
  42. visualObservations = new List<Texture2D>(),
  43. actionMasks = new []{false, true},
  44. done = true,
  45. id = 5,
  46. maxStepReached = true,
  47. memories = new List<float>(),
  48. stackedVectorObservation = new List<float>() {1f, 1f, 1f},
  49. storedTextActions = "TestAction",
  50. storedVectorActions = new [] {0f, 1f},
  51. textObservation = "TestAction",
  52. };
  53. demoStore.Record(agentInfo);
  54. demoStore.Close();
  55. }
  56. }
  57. }