public IEnumerator ProperReset() { string[] tags = { k_Tag1 }; int[] depths = { 5, 1, 3 }; dummyData.Data = new[] { 3f, .6f, 2.2f }; Color[] colors = { Color.red, Color.magenta }; gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); gridSensor.Start(); yield return(null); float[] output = gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 3, output.Length); int[] subarrayIndicies = new int[] { 77, 78, 87, 88 }; float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 3f / 5f, .6f, 2.2f / 3f }, 4); float[] expectedDefault = new float[] { 0, 0, 0 }; GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault); Object.DestroyImmediate(boxGo); yield return(null); output = gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 3, output.Length); subarrayIndicies = new int[0]; expectedSubarrays = new float[0][]; GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault); }
public IEnumerator ProperReset() { string[] tags = { k_Tag1 }; int[] depths = { 5, 1, 3 }; dummyData.Data = new[] { 3f, .6f, 2.2f }; Color[] colors = { Color.red, Color.magenta }; GridObsTestUtils.SetComponentParameters(gridSensorComponent, tags, depths, GridDepthType.ChannelHot, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); var gridSensor = (GridSensor)gridSensorComponent.CreateSensors()[0]; yield return(null); gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 9, gridSensor.m_PerceptionBuffer.Length); int[] subarrayIndicies = new int[] { 77, 78, 87, 88 }; float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 0, 0, 0, 1, 0, .6f, 0, 0, 1 }, 4); float[] expectedDefault = new float[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; GridObsTestUtils.AssertSubarraysAtIndex(gridSensor.m_PerceptionBuffer, subarrayIndicies, expectedSubarrays, expectedDefault); Object.DestroyImmediate(boxGo); yield return(null); gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 9, gridSensor.m_PerceptionBuffer.Length); subarrayIndicies = new int[0]; expectedSubarrays = new float[0][]; GridObsTestUtils.AssertSubarraysAtIndex(gridSensor.m_PerceptionBuffer, subarrayIndicies, expectedSubarrays, expectedDefault); }
public void OneTagMoreDepthError() { string[] tags = { "block" }; int[] depths = { 1, 1 }; Color[] colors = { Color.magenta }; GridObsTestUtils.SetComponentParameters(gridSensorComponent, tags, depths, GridDepthType.Counting, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); Assert.Throws <UnityAgentsException>(() => { gridSensorComponent.CreateSensors(); }); }
public void SevenChannel() { string[] tags = { "Box", "Ball" }; int[] depths = { 1, 1, 1, 1, 1, 1, 1 }; Color[] colors = { Color.magenta }; gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); gridSensor.Start(); int[] expectedShape = { 10, 10, 7 }; GridObsTestUtils.AssertArraysAreEqual(expectedShape, gridSensor.GetFloatObservationShape()); }
public void TwoChannelsDepthThreeThree() { string[] tags = { "Box", "Ball" }; int[] depths = { 3, 3 }; Color[] colors = { Color.magenta }; GridObsTestUtils.SetComponentParameters(gridSensorComponent, tags, depths, GridDepthType.ChannelHot, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); var gridSensor = (GridSensor)gridSensorComponent.CreateSensors()[0]; var expectedShape = new InplaceArray<int>(10, 10, 6); Assert.AreEqual(expectedShape, gridSensor.GetObservationSpec().Shape); }
public IEnumerator OneChannelDepthOneAboveDepthException() { string[] tags = { k_Tag1 }; int[] depths = { 1 }; dummyData.Data = new[] { 1.1f }; Color[] colors = { Color.red, Color.magenta }; GridObsTestUtils.SetComponentParameters(gridSensorComponent, tags, depths, GridDepthType.ChannelHot, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); var gridSensor = (GridSensor)gridSensorComponent.CreateSensors()[0]; yield return(null); Assert.Throws <UnityAgentsException>(() => { gridSensor.Perceive(); }); }
public IEnumerator OneChannelDepthOneCount() { string[] tags = { k_Tag1 }; int[] depths = { 1 }; Color[] colors = { Color.red, Color.magenta }; gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); gridSensor.Start(); yield return(null); float[] output = gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 1, output.Length); int[] subarrayIndicies = new int[] { 77, 78, 87, 88 }; float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 1f }, 4); float[] expectedDefault = new float[] { 0 }; GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault); }
public IEnumerator OneChannelDepthOneCount() { string[] tags = { k_Tag1 }; int[] depths = { 1 }; Color[] colors = { Color.red, Color.magenta }; GridObsTestUtils.SetComponentParameters(gridSensorComponent, tags, depths, GridDepthType.Counting, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); var gridSensor = (GridSensor)gridSensorComponent.CreateSensors()[0]; yield return(null); gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 1, gridSensor.m_PerceptionBuffer.Length); int[] subarrayIndicies = new int[] { 77, 78, 87, 88 }; float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 1f }, 4); float[] expectedDefault = new float[] { 0 }; GridObsTestUtils.AssertSubarraysAtIndex(gridSensor.m_PerceptionBuffer, subarrayIndicies, expectedSubarrays, expectedDefault); }
public IEnumerator ThreeChannelDepthFiveOneThreeGoodValues() { string[] tags = { k_Tag1 }; int[] depths = { 5, 1, 3 }; dummyData.Data = new[] { 3f, .6f, 2.2f }; Color[] colors = { Color.red, Color.magenta }; gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); gridSensor.Start(); yield return(null); float[] output = gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 9, output.Length); int[] subarrayIndicies = new int[] { 77, 78, 87, 88 }; float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 0, 0, 0, 1, 0, .6f, 0, 0, 1 }, 4); float[] expectedDefault = new float[] { 1, 0, 0, 0, 0, 0, 1, 0, 0 }; GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault); }
public IEnumerator TwoChannelDepthFourCount() { string[] tags = { k_Tag1, k_Tag2 }; int[] depths = { 4, 1 }; Color[] colors = { Color.red, Color.magenta }; gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel, 1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors); gridSensor.Start(); boxGoTwo = CreateBlock(new Vector3(3.1f, 0f, 3.1f), k_Tag1, "box2"); boxGoThree = CreateBlock(new Vector3(2.9f, 0f, 2.9f), k_Tag2, "box2"); yield return(null); float[] output = gridSensor.Perceive(); Assert.AreEqual(10 * 10 * 2, output.Length); int[] subarrayIndicies = new int[] { 77, 78, 87, 88 }; float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .5f, 1 }, 4); float[] expectedDefault = new float[] { 0, 0 }; GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault); }