浏览代码

Low hanging fruit tests for coverage. (#5170)

/check-for-ModelOverriders
GitHub 4 年前
当前提交
3041cf63
共有 3 个文件被更改,包括 142 次插入4 次删除
  1. 2
      com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
  2. 103
      com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs
  3. 41
      com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs

2
com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs


/// Trivial implementation of the IList interface that does nothing.
/// This is only used for "writing" observations that we will discard.
/// </summary>
class NullList : IList<float>
internal class NullList : IList<float>
{
public IEnumerator<float> GetEnumerator()
{

103
com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs


using System;
using System.Text.RegularExpressions;
using Google.Protobuf;
using Google.Protobuf.Collections;
using NUnit.Framework;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Demonstrations;

using Unity.MLAgents.Analytics;
using Unity.MLAgents.CommunicatorObjects;
using UnityEngine;
using UnityEngine.TestTools;
namespace Unity.MLAgents.Tests
{

[SetUp]
public void SetUp()
{
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities();
}
[Test]
public void TestDefaultBrainParametersToProto()
{

Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
HybridActions = false
};
brain.ToProto("foo", false);
}
[Test]

var actionSpec = new ActionSpec();
actionSpec.ToBrainParametersProto("foo", false);
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
HybridActions = false
};
actionSpec.ToBrainParametersProto("foo", false);
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities();
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
HybridActions = false
};
actionSpec.ToBrainParametersProto("foo", false);
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities();
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
HybridActions = false
};
actionSpec.ToBrainParametersProto("foo", false);
}
[Test]
public void ToBrainParameters()
{
// Should be able to convert a default instance to proto.
var actionSpec = new ActionSpec();
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters();
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
HybridActions = false
};
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters();
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities();
// Continuous
actionSpec = ActionSpec.MakeContinuous(3);
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters();
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
HybridActions = false
};
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters();
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities();
// Discrete
actionSpec = ActionSpec.MakeDiscrete(1, 2, 3);
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters();
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
HybridActions = false
};
actionSpec.ToBrainParametersProto("foo", false).ToBrainParameters();
}
[Test]

var agentInfo = new AgentInfo();
agentInfo.ToInfoActionPairProto();
var pairProto = agentInfo.ToInfoActionPairProto();
pairProto.AgentInfo.Observations.Add(new ObservationProto
{
CompressedData = ByteString.Empty,
CompressionType = CompressionTypeProto.None,
FloatData = new ObservationProto.Types.FloatData(),
ObservationType = ObservationTypeProto.Default,
Name = "Sensor"
});
pairProto.AgentInfo.Observations[0].Shape.Add(0);
pairProto.GetObservationSummaries();
agentInfo.ToAgentInfoProto();
agentInfo.groupId = 1;
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
MultiAgentGroups = false
};
agentInfo.ToAgentInfoProto();
LogAssert.Expect(LogType.Warning, new Regex(".+"));
Academy.Instance.TrainerCapabilities = new UnityRLCapabilities
{
BaseRLCapabilities = true,
MultiAgentGroups = true
};
agentInfo.ToAgentInfoProto();
}

Assert.AreEqual(obsProto.CompressedData.Length, 0);
}
}
}
[Test]

41
com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NUnit.Framework;
using System.Reflection;

namespace Unity.MLAgents.Tests
{
[TestFixture]
public class EditModeTestGeneration
{

agent1.collectObservationsCallsForEpisode,
agent1.GetStoredActionBuffers().ContinuousActions[0]
);
}
[Test]
public void TestNullList()
{
var nullList = new HeuristicPolicy.NullList();
Assert.Throws<NotImplementedException>(() =>
{
_ = ((IEnumerable<float>)nullList).GetEnumerator();
});
Assert.Throws<NotImplementedException>(() =>
{
_ = ((IEnumerable)nullList).GetEnumerator();
});
Assert.Throws<NotImplementedException>(() =>
{
nullList.CopyTo(new[] { 0f }, 0);
});
nullList.Add(0);
Assert.IsTrue(nullList.Count == 0);
nullList.Clear();
Assert.IsTrue(nullList.Count == 0);
nullList.Add(0);
Assert.IsFalse(nullList.Contains(0));
Assert.IsFalse(nullList.Remove(0));
Assert.IsFalse(nullList.IsReadOnly);
Assert.IsTrue(nullList.IndexOf(0) == -1);
nullList.Insert(0, 0);
Assert.IsFalse(nullList.Count > 0);
nullList.RemoveAt(0);
Assert.IsTrue(nullList.Count == 0);
Assert.IsTrue(Mathf.Approximately(0f, nullList[0]));
Assert.IsTrue(Mathf.Approximately(0f, nullList[1]));
}
}

正在加载...
取消
保存