Exemple #1
0
        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");
                });
            }
        }
Exemple #2
0
        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");
                        }
                    });
                }
            }
        }