Skip to content

Commit 7e24e8e

Browse files
committed
fix up some stuff
1 parent ce92492 commit 7e24e8e

File tree

2 files changed

+3
-175
lines changed

2 files changed

+3
-175
lines changed

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
using Unity.MLAgents.Analytics;
1212
using Unity.MLAgents.CommunicatorObjects;
13-
using UnityEditor.VersionControl;
1413
using UnityEngine;
1514
using UnityEngine.TestTools;
1615

@@ -254,25 +253,6 @@ public void TestGetObservationProtoCapabilities()
254253
}
255254

256255
[Test]
257-
public void TestIsTrivialMapping()
258-
{
259-
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(new DummySensor()), true);
260-
261-
var sparseChannelSensor = new DummySparseChannelSensor();
262-
sparseChannelSensor.Mapping = null;
263-
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), true);
264-
sparseChannelSensor.Mapping = new[] { 0, 0, 0 };
265-
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), true);
266-
sparseChannelSensor.Mapping = new[] { 0, 1, 2, 3, 4 };
267-
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), true);
268-
sparseChannelSensor.Mapping = new[] { 1, 2, 3, 4, -1, -1 };
269-
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), false);
270-
sparseChannelSensor.Mapping = new[] { 0, 0, 0, 1, 1, 1 };
271-
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), false);
272-
}
273-
274-
[Test]
275-
>>>>>>> Low hanging fruit tests for coverage.
276256
public void TestDefaultTrainingEvents()
277257
{
278258
var trainingEnvInit = new TrainingEnvironmentInitialized

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

Lines changed: 3 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ing System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using UnityEngine;
@@ -13,159 +13,6 @@
1313

1414
namespace Unity.MLAgents.Tests
1515
{
16-
internal class TestPolicy : IPolicy
17-
{
18-
public Action OnRequestDecision;
19-
ObservationWriter m_ObsWriter = new ObservationWriter();
20-
static ActionSpec s_ActionSpec = ActionSpec.MakeContinuous(1);
21-
static ActionBuffers s_EmptyActionBuffers = new ActionBuffers(new float[1], Array.Empty<int>());
22-
public void RequestDecision(AgentInfo info, List<ISensor> sensors)
23-
{
24-
foreach (var sensor in sensors)
25-
{
26-
sensor.GetObservationProto(m_ObsWriter);
27-
}
28-
OnRequestDecision?.Invoke();
29-
}
30-
31-
public ref readonly ActionBuffers DecideAction() { return ref s_EmptyActionBuffers; }
32-
33-
public void Dispose() { }
34-
}
35-
36-
public class TestAgent : Agent
37-
{
38-
internal AgentInfo _Info
39-
{
40-
get
41-
{
42-
return (AgentInfo)typeof(Agent).GetField("m_Info", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
43-
}
44-
set
45-
{
46-
typeof(Agent).GetField("m_Info", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, value);
47-
}
48-
}
49-
50-
internal void SetPolicy(IPolicy policy)
51-
{
52-
typeof(Agent).GetField("m_Brain", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this, policy);
53-
}
54-
55-
internal IPolicy GetPolicy()
56-
{
57-
return (IPolicy)typeof(Agent).GetField("m_Brain", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
58-
}
59-
60-
public int initializeAgentCalls;
61-
public int collectObservationsCalls;
62-
public int collectObservationsCallsForEpisode;
63-
public int agentActionCalls;
64-
public int agentActionCallsForEpisode;
65-
public int agentOnEpisodeBeginCalls;
66-
public int heuristicCalls;
67-
public TestSensor sensor1;
68-
public TestSensor sensor2;
69-
70-
[Observable("observableFloat")]
71-
public float observableFloat;
72-
73-
public override void Initialize()
74-
{
75-
initializeAgentCalls += 1;
76-
77-
// Add in some custom Sensors so we can confirm they get sorted as expected.
78-
sensor1 = new TestSensor("testsensor1");
79-
sensor2 = new TestSensor("testsensor2");
80-
sensor2.compressionType = SensorCompressionType.PNG;
81-
82-
sensors.Add(sensor2);
83-
sensors.Add(sensor1);
84-
}
85-
86-
public override void CollectObservations(VectorSensor sensor)
87-
{
88-
collectObservationsCalls += 1;
89-
collectObservationsCallsForEpisode += 1;
90-
sensor.AddObservation(collectObservationsCallsForEpisode);
91-
}
92-
93-
public override void OnActionReceived(ActionBuffers buffers)
94-
{
95-
agentActionCalls += 1;
96-
agentActionCallsForEpisode += 1;
97-
AddReward(0.1f);
98-
}
99-
100-
public override void OnEpisodeBegin()
101-
{
102-
agentOnEpisodeBeginCalls += 1;
103-
collectObservationsCallsForEpisode = 0;
104-
agentActionCallsForEpisode = 0;
105-
}
106-
107-
public override void Heuristic(in ActionBuffers actionsOut)
108-
{
109-
var obs = GetObservations();
110-
var continuousActions = actionsOut.ContinuousActions;
111-
continuousActions[0] = (int)obs[0];
112-
heuristicCalls++;
113-
}
114-
}
115-
116-
public class TestSensor : ISensor
117-
{
118-
public string sensorName;
119-
public int numWriteCalls;
120-
public int numCompressedCalls;
121-
public int numResetCalls;
122-
public SensorCompressionType compressionType = SensorCompressionType.None;
123-
124-
public TestSensor(string n)
125-
{
126-
sensorName = n;
127-
}
128-
129-
public int[] GetObservationShape()
130-
{
131-
return new[] { 0 };
132-
}
133-
134-
public ObservationSpec GetObservationSpec()
135-
{
136-
return ObservationSpec.Vector(0);
137-
}
138-
139-
public int Write(ObservationWriter writer)
140-
{
141-
numWriteCalls++;
142-
// No-op
143-
return 0;
144-
}
145-
146-
public byte[] GetCompressedObservation()
147-
{
148-
numCompressedCalls++;
149-
return new byte[] { 0 };
150-
}
151-
152-
public SensorCompressionType GetCompressionType()
153-
{
154-
return compressionType;
155-
}
156-
157-
public string GetName()
158-
{
159-
return sensorName;
160-
}
161-
162-
public void Update() { }
163-
164-
public void Reset()
165-
{
166-
numResetCalls++;
167-
}
168-
}
16916

17017
[TestFixture]
17118
public class EditModeTestGeneration
@@ -175,7 +22,8 @@ public void SetUp()
17522
{
17623
if (Academy.IsInitialized)
17724
{
178-
Academy.Instance.Di se }
25+
Academy.Instance.Dispose();
26+
}
17927
}
18028

18129
[Test]

0 commit comments

Comments
 (0)