Download com.unity.ml-agents.tests/Tests/Editor/BehaviorParameterTests.cs from ashish2244/ppo-SnowballTarget: direct link, hf CLI and curl.
- Browser
- Download file 2.67 kB
-
https://huggingface.co/ashish2244/ppo-SnowballTarget/resolve/main/com.unity.ml-agents.tests/Tests/Editor/BehaviorParameterTests.cs
- Command line
-
hf download hf://ashish2244/ppo-SnowballTarget/com.unity.ml-agents.tests/Tests/Editor/BehaviorParameterTests.cs
-
curl -L -o BehaviorParameterTests.cs https://huggingface.co/ashish2244/ppo-SnowballTarget/resolve/main/com.unity.ml-agents.tests/Tests/Editor/BehaviorParameterTests.cs
2.67 kB
| using NUnit.Framework; | |
| using Unity.InferenceEngine; | |
| using Unity.MLAgents.Actuators; | |
| using UnityEngine; | |
| using Unity.MLAgents.Policies; | |
| using UnityEditor; | |
| using UnityEngine.TestTools; | |
| namespace Unity.MLAgents.Tests | |
| { | |
| [] | |
| public class BehaviorParameterTests : IHeuristicProvider | |
| { | |
| const string k_continuousONNXPath = "Packages/com.unity.ml-agents.tests/Tests/Editor/TestModels/continuous2vis8vec2action_v1_0.onnx"; | |
| public void Heuristic(in ActionBuffers actionsOut) | |
| { | |
| // No-op | |
| } | |
| [] | |
| public void TestNoModelInferenceOnlyThrows() | |
| { | |
| var gameObj = new GameObject(); | |
| var bp = gameObj.AddComponent<BehaviorParameters>(); | |
| bp.BehaviorType = BehaviorType.InferenceOnly; | |
| var actionSpec = new ActionSpec(); | |
| Assert.Throws<UnityAgentsException>(() => | |
| { | |
| bp.GeneratePolicy(actionSpec, new ActuatorManager()); | |
| }); | |
| } | |
| [] | |
| public void TestIsInHeuristicMode() | |
| { | |
| var gameObj = new GameObject(); | |
| var bp = gameObj.AddComponent<BehaviorParameters>(); | |
| bp.Model = null; | |
| gameObj.AddComponent<Agent>(); | |
| bp.BehaviorType = BehaviorType.HeuristicOnly; | |
| Assert.IsTrue(bp.IsInHeuristicMode()); | |
| bp.BehaviorType = BehaviorType.Default; | |
| Assert.IsTrue(bp.IsInHeuristicMode()); | |
| bp.Model = ScriptableObject.CreateInstance<ModelAsset>(); | |
| Assert.IsFalse(bp.IsInHeuristicMode()); | |
| } | |
| [] | |
| public void TestPolicyUpdateEventFired() | |
| { | |
| var gameObj = new GameObject(); | |
| var bp = gameObj.AddComponent<BehaviorParameters>(); | |
| gameObj.AddComponent<Agent>().LazyInitialize(); | |
| bp.OnPolicyUpdated += delegate (bool isInHeuristicMode) { Debug.Log($"OnPolicyChanged:{isInHeuristicMode}"); }; | |
| bp.BehaviorType = BehaviorType.HeuristicOnly; | |
| LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{true}"); | |
| bp.BehaviorType = BehaviorType.Default; | |
| LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{true}"); | |
| Assert.Throws<UnityAgentsException>(() => | |
| { | |
| bp.BehaviorType = BehaviorType.InferenceOnly; | |
| }); | |
| bp.Model = AssetDatabase.LoadAssetAtPath<ModelAsset>(k_continuousONNXPath); | |
| LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{false}"); | |
| bp.BehaviorType = BehaviorType.HeuristicOnly; | |
| LogAssert.Expect(LogType.Log, $"OnPolicyChanged:{true}"); | |
| } | |
| } | |
| } | |