public void TestActorFloatAccessors() { string brainUid = System.Guid.NewGuid().ToString(); string agentUid = System.Guid.NewGuid().ToString(); string brainSource = @" function updateAgent(obj) { const prev = getActorFloat(12, 34); if(Math.abs(prev - 12.34) > 1e-6) throw 'ahhh'; setActorFloat(12, 34, 56.78); }"; Debug.Assert(V8InUnity.Native.ResetBrain(brainUid, brainSource)); TestAgentRequest req; req.floats = new float[0]; actorFloatValue = 12.34f; var callbacks = new Native.UpdateCallbacks(); callbacks.getActorFloat = TestActorFloatGetter; callbacks.setActorFloat = TestActorFloatSetter; var maybeResponse = V8InUnity.Native.UpdateAgent <TestAgentRequest, TestAgentResponse>(brainUid, agentUid, req, callbacks); Debug.Assert(!maybeResponse.IsEmpty()); Assert.AreEqual(56.78f, actorFloatValue, 1e-6); }
public void TestSetActorStringUndefined() { string brainUid = System.Guid.NewGuid().ToString(); string agentUid = System.Guid.NewGuid().ToString(); actorStringValue = "overwrite me"; string brainSource = @" function updateAgent(obj) { setActorString(12, 34, undefined); }"; Debug.Assert(V8InUnity.Native.ResetBrain(brainUid, brainSource)); var req = new TestAgentRequest { floats = new float[0] }; var callbacks = new Native.UpdateCallbacks { getActorString = TestActorStringGetter, setActorString = TestActorStringSetter }; var maybeResponse = V8InUnity.Native.UpdateAgent <TestAgentRequest, TestAgentResponse>(brainUid, agentUid, req, callbacks); Debug.Assert(!maybeResponse.IsEmpty()); Assert.AreEqual("", actorStringValue); }
public void TestActorBooleanAccessors() { string brainUid = System.Guid.NewGuid().ToString(); string agentUid = System.Guid.NewGuid().ToString(); string brainSource = @" function updateAgent(obj) { const prev = getActorBoolean(12, 34); if(prev != true) throw 'ahhh'; setActorBoolean(12, 34, false); }"; Debug.Assert(V8InUnity.Native.ResetBrain(brainUid, brainSource)); TestAgentRequest req; req.floats = new float[0]; actorBoolValue = true; var callbacks = new Native.UpdateCallbacks(); callbacks.getActorBoolean = TestActorBooleanGetter; callbacks.setActorBoolean = TestActorBooleanSetter; var maybeResponse = V8InUnity.Native.UpdateAgent <TestAgentRequest, TestAgentResponse>(brainUid, agentUid, req, callbacks); Debug.Assert(!maybeResponse.IsEmpty()); Assert.AreEqual(false, actorBoolValue); }
public void TestActorStringAccessors() { // Do this test several times, since there's lots of caching in this code path. for (int i = 0; i < 5; i++) { string brainUid = System.Guid.NewGuid().ToString(); string agentUid = System.Guid.NewGuid().ToString(); Debug.Log($"strting test for {brainUid}"); actorStringValue = $"€ {brainUid} €"; string brainSource = @" function updateAgent(obj) { const prev = getActorString(12, 34); sysLog(`got string: ${prev}`); if(prev != '€ " + brainUid + @" €') throw 'ahhh'; setActorString(12, 34, 'from JS € " + agentUid + @" € euros €'); }"; Debug.Assert(V8InUnity.Native.ResetBrain(brainUid, brainSource)); var req = new TestAgentRequest { floats = new float[0] }; var callbacks = new Native.UpdateCallbacks { getActorString = TestActorStringGetter, setActorString = TestActorStringSetter }; var maybeResponse = V8InUnity.Native.UpdateAgent <TestAgentRequest, TestAgentResponse>(brainUid, agentUid, req, callbacks); Debug.Assert(!maybeResponse.IsEmpty()); Assert.AreEqual("from JS € " + agentUid + " € euros €", actorStringValue); Debug.Log($"OK succeeded once"); } }
public void TestServicesBasic() { string brainUid = System.Guid.NewGuid().ToString(); string agentUid = System.Guid.NewGuid().ToString(); string brainSource = @" function updateAgent(state) { const v = callVoosService('vec123'); state.floatsOut = [v.x, v.y, v.z]; } "; Debug.Assert(V8InUnity.Native.ResetBrain(brainUid, brainSource)); TestAgentRequest req; req.floats = new float[0]; var cbs = new Native.UpdateCallbacks(); cbs.callService = TestCallServiceCallback; var maybeResponse = V8InUnity.Native.UpdateAgent <TestAgentRequest, TestAgentResponse>(brainUid, agentUid, req, cbs); Debug.Assert(!maybeResponse.IsEmpty()); TestAgentResponse res = maybeResponse.Get(); Debug.Assert(res.floatsOut[0] == 1f); Debug.Assert(res.floatsOut[1] == 2f); Debug.Assert(res.floatsOut[2] == 3f); }