public void TestStackingReset() { VectorSensor wrapped = new VectorSensor(2); ISensor sensor = new StackingSensor(wrapped, 3); wrapped.AddObservation(new[] { 1f, 2f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 0f, 1f, 2f }); sensor.Update(); wrapped.AddObservation(new[] { 3f, 4f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 2f, 3f, 4f }); sensor.Reset(); wrapped.AddObservation(new[] { 5f, 6f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 0f, 5f, 6f }); }
public void Test3DStacking() { var wrapped = new Dummy3DSensor(); wrapped.ObservationSpec = ObservationSpec.Visual(2, 1, 2); var sensor = new StackingSensor(wrapped, 2); // Check the stacking is on the last dimension wrapped.CurrentObservation = new[, , ] { { { 1f, 2f } }, { { 3f, 4f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 0f, 0f, 1f, 2f } }, { { 0f, 0f, 3f, 4f } } }); sensor.Update(); wrapped.CurrentObservation = new[, , ] { { { 5f, 6f } }, { { 7f, 8f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 1f, 2f, 5f, 6f } }, { { 3f, 4f, 7f, 8f } } }); sensor.Update(); wrapped.CurrentObservation = new[, , ] { { { 9f, 10f } }, { { 11f, 12f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 5f, 6f, 9f, 10f } }, { { 7f, 8f, 11f, 12f } } }); // Check that if we don't call Update(), the same observations are produced SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 5f, 6f, 9f, 10f } }, { { 7f, 8f, 11f, 12f } } }); // Test reset sensor.Reset(); wrapped.CurrentObservation = new[, , ] { { { 13f, 14f } }, { { 15f, 16f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 0f, 0f, 13f, 14f } }, { { 0f, 0f, 15f, 16f } } }); }
public void TestStackedGetCompressedObservation() { var wrapped = new Dummy3DSensor(); wrapped.ObservationSpec = ObservationSpec.Visual(1, 1, 3); var sensor = new StackingSensor(wrapped, 2); wrapped.CurrentObservation = new[, , ] { { { 1f, 2f, 3f } } }; var expected1 = sensor.CreateEmptyPNG(); expected1 = expected1.Concat(Array.ConvertAll(new[] { 1f, 2f, 3f }, (z) => (byte)z)).ToArray(); Assert.AreEqual(sensor.GetCompressedObservation(), expected1); sensor.Update(); wrapped.CurrentObservation = new[, , ] { { { 4f, 5f, 6f } } }; var expected2 = Array.ConvertAll(new[] { 1f, 2f, 3f, 4f, 5f, 6f }, (z) => (byte)z); Assert.AreEqual(sensor.GetCompressedObservation(), expected2); sensor.Update(); wrapped.CurrentObservation = new[, , ] { { { 7f, 8f, 9f } } }; var expected3 = Array.ConvertAll(new[] { 4f, 5f, 6f, 7f, 8f, 9f }, (z) => (byte)z); Assert.AreEqual(sensor.GetCompressedObservation(), expected3); // Test reset sensor.Reset(); wrapped.CurrentObservation = new[, , ] { { { 10f, 11f, 12f } } }; var expected4 = sensor.CreateEmptyPNG(); expected4 = expected4.Concat(Array.ConvertAll(new[] { 10f, 11f, 12f }, (z) => (byte)z)).ToArray(); Assert.AreEqual(sensor.GetCompressedObservation(), expected4); }