public void TestMessageReadWrites() { var boolVal = true; var intVal = 1337; var floatVal = 4.2f; var floatListVal = new float[] { 1001, 1002 }; var stringVal = "mlagents!"; IncomingMessage incomingMsg; using (var outgoingMsg = new OutgoingMessage()) { outgoingMsg.WriteBoolean(boolVal); outgoingMsg.WriteInt32(intVal); outgoingMsg.WriteFloat32(floatVal); outgoingMsg.WriteString(stringVal); outgoingMsg.WriteFloatList(floatListVal); incomingMsg = new IncomingMessage(outgoingMsg.ToByteArray()); } Assert.AreEqual(boolVal, incomingMsg.ReadBoolean()); Assert.AreEqual(intVal, incomingMsg.ReadInt32()); Assert.AreEqual(floatVal, incomingMsg.ReadFloat32()); Assert.AreEqual(stringVal, incomingMsg.ReadString()); Assert.AreEqual(floatListVal, incomingMsg.ReadFloatList()); }
public void SendInt(int value) { using (var msg = new OutgoingMessage()) { msg.WriteInt32(value); QueueMessageToSend(msg); } }
public void GaussianSamplerTest() { float mean = 3.0f; float stddev = 0.2f; string parameter = "parameter2"; using (var outgoingMsg = new OutgoingMessage()) { outgoingMsg.WriteString(parameter); // 1 indicates this meessage is a Sampler outgoingMsg.WriteInt32(1); outgoingMsg.WriteInt32(k_Seed); outgoingMsg.WriteInt32((int)SamplerType.Gaussian); outgoingMsg.WriteFloat32(mean); outgoingMsg.WriteFloat32(stddev); byte[] message = GetByteMessage(m_Channel, outgoingMsg); SideChannelManager.ProcessSideChannelData(message); } Assert.AreEqual(2.936162f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon); Assert.AreEqual(2.951348f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon); }
public void UniformSamplerTest() { float min_value = 1.0f; float max_value = 2.0f; string parameter = "parameter1"; using (var outgoingMsg = new OutgoingMessage()) { outgoingMsg.WriteString(parameter); // 1 indicates this meessage is a Sampler outgoingMsg.WriteInt32(1); outgoingMsg.WriteInt32(k_Seed); outgoingMsg.WriteInt32((int)SamplerType.Uniform); outgoingMsg.WriteFloat32(min_value); outgoingMsg.WriteFloat32(max_value); byte[] message = GetByteMessage(m_Channel, outgoingMsg); SideChannelManager.ProcessSideChannelData(message); } Assert.AreEqual(1.208888f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon); Assert.AreEqual(1.118017f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon); }
public void MultiRangeUniformSamplerTest() { float[] intervals = new float[4]; intervals[0] = 1.2f; intervals[1] = 2f; intervals[2] = 3.2f; intervals[3] = 4.1f; string parameter = "parameter3"; using (var outgoingMsg = new OutgoingMessage()) { outgoingMsg.WriteString(parameter); // 1 indicates this meessage is a Sampler outgoingMsg.WriteInt32(1); outgoingMsg.WriteInt32(k_Seed); outgoingMsg.WriteInt32((int)SamplerType.MultiRangeUniform); outgoingMsg.WriteFloatList(intervals); byte[] message = GetByteMessage(m_Channel, outgoingMsg); SideChannelManager.ProcessSideChannelData(message); } Assert.AreEqual(3.387999f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon); Assert.AreEqual(1.294413f, m_Channel.GetWithDefault(parameter, 1.0f), k_Epsilon); }
public void TestOutgoingMessageRawBytes() { // Make sure that SetRawBytes resets the buffer correctly. // Write 8 bytes (an int and float) then call SetRawBytes with 4 bytes var msg = new OutgoingMessage(); msg.WriteInt32(42); msg.WriteFloat32(1.0f); var data = new byte[] { 1, 2, 3, 4 }; msg.SetRawBytes(data); var result = msg.ToByteArray(); Assert.AreEqual(data, result); }
public void TestTimeScaleClamping() { OutgoingMessage pythonMsg = new OutgoingMessage(); pythonMsg.WriteInt32((int)EngineConfigurationChannel.ConfigurationType.TimeScale); pythonMsg.WriteFloat32(1000f); var sideChannel = new EngineConfigurationChannel(); sideChannel.ProcessMessage(pythonMsg.ToByteArray()); #if UNITY_EDITOR // Should be clamped Assert.AreEqual(100.0f, Time.timeScale); #else // Not sure we can run this test from a player, but just in case, shouldn't clamp. Assert.AreEqual(1000.0f, Time.timeScale); #endif }