Skip to content

Convert Academy to a singleton #3210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions UnitySDK/Assets/ML-Agents/Editor/Tests/DemonstrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@

namespace MLAgents.Tests
{
[TestFixture]
public class DemonstrationTests : MonoBehaviour
{
const string k_DemoDirecory = "Assets/Demonstrations/";
const string k_ExtensionType = ".demo";
const string k_DemoName = "Test";

[SetUp]
public void SetUp()
{
if (Academy.IsInitialized)
{
Academy.Instance.Dispose();
}
}

[Test]
public void TestSanitization()
{
Expand Down Expand Up @@ -90,19 +100,12 @@ public void TestAgentWrite()
demoRecorder.record = true;
demoRecorder.InitializeDemoStore(fileSystem);

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<Academy>();
var aca = acaGo.GetComponent<Academy>();

var academyInitializeMethod = typeof(Academy).GetMethod("InitializeEnvironment",
BindingFlags.Instance | BindingFlags.NonPublic);
var agentEnableMethod = typeof(Agent).GetMethod("OnEnable",
BindingFlags.Instance | BindingFlags.NonPublic);
var agentSendInfo = typeof(Agent).GetMethod("SendInfo",
BindingFlags.Instance | BindingFlags.NonPublic);

agentEnableMethod?.Invoke(agent1, new object[] { });
academyInitializeMethod?.Invoke(aca, new object[] { });

// Step the agent
agent1.RequestDecision();
Expand All @@ -125,8 +128,6 @@ public void TestAgentWrite()
Assert.AreEqual((float)i + 1, vecObs[i]);
}
}


}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@

namespace MLAgents.Tests
{
[TestFixture]
public class EditModeTestInternalBrainTensorGenerator
{
static List<Agent> GetFakeAgents()
[SetUp]
public void SetUp()
{
var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<Academy>();
var aca = acaGo.GetComponent<Academy>();
if (Academy.IsInitialized)
{
Academy.Instance.Dispose();
}
}

static List<Agent> GetFakeAgents()
{
var goA = new GameObject("goA");
var bpA = goA.AddComponent<BehaviorParameters>();
bpA.brainParameters.vectorObservationSize = 3;
Expand All @@ -33,7 +39,7 @@ static List<Agent> GetFakeAgents()
{
var agentEnableMethod = typeof(Agent).GetMethod("OnEnableHelper",
BindingFlags.Instance | BindingFlags.NonPublic);
agentEnableMethod?.Invoke(agent, new object[] { aca });
agentEnableMethod?.Invoke(agent, new object[] { });
}
agentA.collectObservationsSensor.AddObservation(new Vector3(1, 2, 3));
agentB.collectObservationsSensor.AddObservation(new Vector3(4, 5, 6));
Expand Down
Loading