public void SubGridCellSegmentPassesDataWrapper_NonStatic_SetState_Test() { // Create the main 2D array of cell pass arrays var cellPasses = new Cell_NonStatic[SubGridTreeConsts.SubGridTreeDimension, SubGridTreeConsts.SubGridTreeDimension]; // Create each sub array and add a test cell pass to it SubGridUtilities.SubGridDimensionalIterator((x, y) => { cellPasses[x, y].Passes = new TRexSpan <CellPass>(new CellPass[1], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 1, false); cellPasses[x, y].Passes.Add(TestCellPass()); }); using (var item = new SubGridCellSegmentPassesDataWrapper_NonStatic()) { // Feed the cell passes to the segment item.SetState(cellPasses); // Check the passes all match SubGridUtilities.SubGridDimensionalIterator((x, y) => { Assert.True(cellPasses[x, y].Passes.First().Equals(item.Pass(x, y, 0)), $"Pass in cell {x}:{y} does not match"); }); } }
public void SubGridCellSegmentPassesDataWrapper_NonStatic_NoMachineIDSet_Test() { var cellPasses = new Cell_NonStatic[SubGridTreeConsts.SubGridTreeDimension, SubGridTreeConsts.SubGridTreeDimension]; // Create each sub array and add a test cell pass to it SubGridUtilities.SubGridDimensionalIterator((x, y) => { cellPasses[x, y].Passes = new TRexSpan <CellPass>(new CellPass[1], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 1, false); cellPasses[x, y].Passes.Add(TestCellPass()); }); ISubGridCellSegmentPassesDataWrapper item = new SubGridCellSegmentPassesDataWrapper_StaticCompressed(); // Feed the cell passes to the segment and ask it to serialise itself which will create the machine ID set item.SetState(cellPasses); using (BinaryWriter writer = new BinaryWriter(new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION))) { item.Write(writer); } BitArray MachineIDSet = item.GetMachineIDSet(); // Check there is a machine ID set, and it contains only a single machine, being the number of the internal machine ID used to construct TestPass Assert.True(MachineIDSet != null, "Static compressed pass wrapper returned null machine ID set"); Assert.Equal(_InternalMachineID + 1, MachineIDSet.Length); Assert.True(MachineIDSet[_InternalMachineID]); for (int i = 0; i < MachineIDSet.Length - 1; i++) { Assert.False(MachineIDSet[i]); } }
public void Test_Cell_EmptyCellCreation() { Cell_NonStatic c = new Cell_NonStatic(); Assert.Equal(0, c.PassCount); Assert.True(c.IsEmpty, "Cell does not report itself as being empty of cell passes"); }
public void SubGridCellSegmentPassesDataWrapper_NonStatic_Cell_Test() { CellPass pass1 = TestCellPass(); pass1.Time = DateTime.SpecifyKind(new DateTime(2000, 1, 1, 0, 0, 0), DateTimeKind.Utc); CellPass pass2 = TestCellPass(); pass2.Time = DateTime.SpecifyKind(new DateTime(2000, 1, 2, 0, 0, 0), DateTimeKind.Utc); CellPass pass3 = TestCellPass(); pass3.Time = DateTime.SpecifyKind(new DateTime(2000, 1, 3, 0, 0, 0), DateTimeKind.Utc); CellPass[] passes = new CellPass[] { pass1, pass2, pass3 }; using (var item = new SubGridCellSegmentPassesDataWrapper_NonStatic()) { item.AddPass(1, 1, pass1); item.AddPass(1, 1, pass2); item.AddPass(1, 1, pass3); Assert.Equal(3, item.PassCount(1, 1)); Cell_NonStatic cell = item.ExtractCellPasses(1, 1); for (int i = 0; i < cell.PassCount; i++) { Assert.True(cell.Passes.GetElement(i).Equals(passes[i]), "Extracted cell does not contain the same cell passes added to it"); } } }
public void Test_Cell_CellPassAllocation() { Cell_NonStatic c = new Cell_NonStatic(); c.AllocatePasses(10); Assert.Equal(0, c.PassCount); Assert.True(c.Passes.Capacity >= 10); }
public void Test_Cell_AddCellPass_WithDuplicateTime() { Cell_NonStatic c = new Cell_NonStatic(); c.AddPass(CellPassTests.ATestCellPass()); Action act = () => c.AddPass(CellPassTests.ATestCellPass()); act.Should().Throw <TRexException>(); }
public void Test_Cell_IntegrateCells_WithEmptySource() { CellPass cp1 = CellPassTests.ATestCellPass(); Cell_NonStatic c1 = new Cell_NonStatic(); c1.AddPass(cp1); Cell_NonStatic c2 = new Cell_NonStatic(); // Test integration of cell with no cell passes c1.Integrate(c2, 0, c2.PassCount - 1, out int addedCount, out int modifiedCount); Assert.Equal(0, addedCount); Assert.Equal(0, modifiedCount); }
public void SubGridCellSegmentPassesDataWrapper_NonStatic_WriteRead_Test() { // Create the main 2D array of cell pass arrays var cellPasses = new Cell_NonStatic[SubGridTreeConsts.SubGridTreeDimension, SubGridTreeConsts.SubGridTreeDimension]; // Create each sub array and add a test cell pass to it SubGridUtilities.SubGridDimensionalIterator((x, y) => { cellPasses[x, y].Passes = new TRexSpan <CellPass>(new CellPass[1], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 1, false); cellPasses[x, y].Passes.Add(TestCellPass()); }); using (var item1 = new SubGridCellSegmentPassesDataWrapper_NonStatic()) { MemoryStream ms = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION); // Write to the stream... BinaryWriter writer = new BinaryWriter(ms, Encoding.UTF8, true); item1.SetState(cellPasses); item1.Write(writer); // Create a new segment and read it back again using (var item2 = new SubGridCellSegmentPassesDataWrapper_NonStatic()) { ms.Position = 0; BinaryReader reader = new BinaryReader(ms, Encoding.UTF8, true); item2.Read(reader); SubGridUtilities.SubGridDimensionalIterator((col, row) => { var cellPasses1 = item1.ExtractCellPasses(col, row); var cellPasses2 = item2.ExtractCellPasses(col, row); Assert.True(cellPasses1.PassCount == cellPasses2.PassCount, "Read segment does not contain the same list of cell passes written into it - counts do not match"); for (int i = 0; i < cellPasses1.PassCount; i++) { Assert.True(cellPasses1.Passes.GetElement(i).Equals(cellPasses2.Passes.GetElement(i)), "Read segment does not contain the same list of cell passes written into it"); } }); } } }
public void SubGridCellSegmentPassesDataWrapper_NonStatic_Integrate_Test() { using (var item = new SubGridCellSegmentPassesDataWrapper_NonStatic()) { CellPass pass = TestCellPass(); item.AddPass(1, 1, pass); CellPass pass2 = TestCellPass(); pass2.Time = pass2.Time.AddSeconds(60); Cell_NonStatic integrateFrom = new Cell_NonStatic(); integrateFrom.AddPass(pass2); item.Integrate(1, 1, integrateFrom, 0, 0, out int addedCount, out int modifiedCount); Assert.Equal(2, item.PassCount(1, 1)); Assert.Equal(1, addedCount); Assert.Equal(0, modifiedCount); } }
public void Test_Cell_AddCellPassUnOrdered() { Cell_NonStatic c = new Cell_NonStatic(); c.AddPass(CellPassTests.ATestCellPass2()); Assert.Equal(1, c.PassCount); CellPass cp2 = CellPassTests.ATestCellPass2(); Assert.True(c.Passes.GetElement(0).Equals(cp2), "Added cell pass not the same content as it was constructed with"); c.AddPass(CellPassTests.ATestCellPass()); Assert.Equal(2, c.PassCount); CellPass cp1 = CellPassTests.ATestCellPass(); Assert.True(c.Passes.GetElement(0).Equals(cp1), "Added cell pass not the same content as it was constructed with"); }
public void Test_Cell_TopMostHeight() { Cell_NonStatic c1 = new Cell_NonStatic(); // Add two cell passes in ascending order c1.AddPass(CellPassTests.ATestCellPass()); c1.AddPass(CellPassTests.ATestCellPass2()); Assert.Equal(2, c1.PassCount); Assert.Equal(50, c1.TopMostHeight); // Add two cell passes in descending order Cell_NonStatic c2 = new Cell_NonStatic(); c2.AddPass(CellPassTests.ATestCellPass2()); c2.AddPass(CellPassTests.ATestCellPass()); Assert.Equal(2, c2.PassCount); Assert.Equal(50, c2.TopMostHeight); }
public void Test_Cell_LocateTime() { // Create a cell with two cell passes with different times Cell_NonStatic c = new Cell_NonStatic(); c.Passes = new TRexSpan <CellPass>(new CellPass[2], TRexSpan <CellPass> .NO_SLAB_INDEX, 0, 2, false); CellPass cp1 = CellPassTests.ATestCellPass(); CellPass cp2 = CellPassTests.ATestCellPass2(); c.AddPass(cp1); c.AddPass(cp2); // Check cp1 and cp2 are present in that order Assert.True(c.Passes.GetElement(0).Equals(cp1) && c.Passes.GetElement(1).Equals(cp2), "Two passes added are not in expected order"); // Locate both with the time present in each of the contributing cell passes to ensure exact time matches // at the boundaries are preserved c.LocateTime(cp1.Time, out int cellPassIndex); Assert.Equal(0, cellPassIndex); Assert.True(c.Passes.GetElement(cellPassIndex).Equals(cp1), "Select (first) cell pass does not match pass added to cell"); c.LocateTime(cp2.Time, out cellPassIndex); Assert.Equal(1, cellPassIndex); Assert.True(c.Passes.GetElement(cellPassIndex).Equals(cp2), "Select (second) cell pass does not match pass added to cell"); // Locate the cell passes with modified times to cause no exact match to text the // returned insertion position is correct c.LocateTime(cp1.Time.AddMinutes(-1), out cellPassIndex); Assert.Equal(0, cellPassIndex); c.LocateTime(cp1.Time.AddMinutes(1), out cellPassIndex); Assert.Equal(1, cellPassIndex); c.LocateTime(cp2.Time.AddMinutes(1), out cellPassIndex); Assert.Equal(2, cellPassIndex); }
public void Test_Cell_IntegrateCells_SingleCellPasses_Modified() { // Create cells with the same single cell pass in each CellPass cp1 = CellPassTests.ATestCellPass(); Cell_NonStatic c1 = new Cell_NonStatic(); c1.AddPass(cp1); Cell_NonStatic c2 = new Cell_NonStatic(); c2.AddPass(cp1); // Test integration of the identical cell passes resulting in a single cell pass, 0 added and 0 modified (as identical cell passes are not a modification) c1.Integrate(c2, 0, c2.PassCount - 1, out int addedCount, out int modifiedCount); Assert.Equal(0, addedCount); Assert.Equal(0, modifiedCount); Assert.True(c2.PassCount == 1 && c2.Passes.GetElement(0).Equals(cp1), "Integration unexpectedly modified source cell"); Assert.True(c1.PassCount == 1 && c1.Passes.GetElement(0).Equals(cp1), "Result of integration two cells with the same single passes does not contain a single pass of the expected content"); // Modify the cell pass in cell 2 to have a different machine ID, but same remaining state to determine if the modification count is set var cellPass = c2.Passes.GetElement(0); cellPass.InternalSiteModelMachineIndex = 10000; c2.Passes.SetElement(cellPass, 0); // Test integration of the identical cell passes resulting in a single cell pass, 0 added and 1 modified (as identical cell passes are not a modification) c1.Integrate(c2, 0, c2.PassCount - 1, out addedCount, out modifiedCount); Assert.Equal(0, addedCount); Assert.Equal(1, modifiedCount); Assert.Equal(1, c1.PassCount); }
public void Test_Cell_IntegrateCells_CellPasses_NoModified_WithInvertedDates() { // Create cells with a single (different) cell pass in each CellPass cp1 = CellPassTests.ATestCellPass(); CellPass cp2 = CellPassTests.ATestCellPass2(); Cell_NonStatic c1 = new Cell_NonStatic(); c1.AddPass(cp1); cp1.Time = cp1.Time.AddSeconds(1); c1.AddPass(cp1); Cell_NonStatic c2 = new Cell_NonStatic(); c2.AddPass(cp2); cp2.Time = cp2.Time.AddSeconds(1); c2.AddPass(cp2); c2.Integrate(c1, 0, c1.PassCount - 1, out int addedCount, out int modifiedCount); Assert.Equal(2, addedCount); Assert.Equal(0, modifiedCount); }
public void Test_Cell_IntegrateCells_SingleCellPasses_NoModified() { // Create cells with a single (different) cell pass in each CellPass cp1 = CellPassTests.ATestCellPass(); CellPass cp2 = CellPassTests.ATestCellPass2(); Cell_NonStatic c1 = new Cell_NonStatic(); c1.AddPass(cp1); Cell_NonStatic c2 = new Cell_NonStatic(); c2.AddPass(cp2); // Test integration of later cell pass to list with earlier cell pass resulting in 1 added and 0 modified c1.Integrate(c2, 0, c2.PassCount - 1, out int addedCount, out int modifiedCount); Assert.Equal(1, addedCount); Assert.Equal(0, modifiedCount); Assert.True(c2.PassCount == 1 && c2.Passes.GetElement(0).Equals(cp2), "Integration unexpectedly modified source cell"); Assert.True(c1.PassCount == 2 && c1.Passes.GetElement(0).Equals(cp1) && c1.Passes.GetElement(1).Equals(cp2), "Result of integration two cells with single passes does not contain two passes of the expected content"); }
public void ReplacePass(int X, int Y, Cell_NonStatic cell, int position, CellPass pass) { var passString = ShortFormOutput ? $"Time:{pass.Time:yyyy-MM-dd-HH-mm-ss.fff}" : $"{pass}"; WriteToOutput($"ReplacePass {X}:{Y}:{position}->{passString}"); }
/// <summary> /// Receives the details for a pass to be replaced and relays it to the defined action /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="cell"></param> /// <param name="pass"></param> /// <param name="position"></param> public virtual void ReplacePass(int X, int Y, Cell_NonStatic cell, int position, CellPass pass) { ReplacePassAction?.Invoke(X, Y, cell, position, pass); }
/// <summary> /// Receives the details for a pass to be added and relays it to the defined action /// </summary> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="cell"></param> /// <param name="pass"></param> /// <param name="position"></param> public virtual void AddPass(int X, int Y, Cell_NonStatic cell, CellPass pass, int position = -1) { AddPassAction?.Invoke(X, Y, cell, pass, position); }