public void Test_SubGridCellLatestPassDataWrapper_NonStatic_Clear() { SubGridCellLatestPassDataWrapper_NonStatic wrapper = new SubGridCellLatestPassDataWrapper_NonStatic(); Assert.True(wrapper.PassDataExistenceMap.IsEmpty(), "Existence map not empty after creation"); wrapper.PassDataExistenceMap.SetBitValue(0, 0, true); }
public void Test_MutabilityConverterTests_ConvertSubgridDirectoryTest() { // Create a sub grid directory with a single segment and some cells. Create a stream from it then use the // mutability converter to convert it to the immutable form. Read this back into an immutable representation // and compare the mutable and immutable versions for consistency. // Create a leaf to contain the mutable directory IServerLeafSubGrid mutableLeaf = new ServerSubGridTreeLeaf(null, null, SubGridTreeConsts.SubGridTreeLevels, StorageMutability.Mutable); mutableLeaf.Directory.GlobalLatestCells = DIContext.Obtain <ISubGridCellLatestPassesDataWrapperFactory>().NewMutableWrapper_Global(); // Load the mutable stream of information mutableLeaf.Directory.CreateDefaultSegment(); SubGridUtilities.SubGridDimensionalIterator((x, y) => { var cellPass = (mutableLeaf.Directory.GlobalLatestCells as SubGridCellLatestPassDataWrapper_NonStatic)[x, y]; cellPass.Height = 1234.5678F; (mutableLeaf.Directory.GlobalLatestCells as SubGridCellLatestPassDataWrapper_NonStatic)[x, y] = cellPass; }); // Take a copy of the mutable cells for later reference SubGridCellLatestPassDataWrapper_NonStatic mutableCells = (mutableLeaf.Directory.GlobalLatestCells as SubGridCellLatestPassDataWrapper_NonStatic); MemoryStream mutableStream = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION); mutableLeaf.SaveDirectoryToStream(mutableStream); var mutabilityConverter = new MutabilityConverter(); /* todo also test using the mutableStream */ mutabilityConverter.ConvertToImmutable(FileSystemStreamType.SubGridDirectory, null, mutableLeaf, out MemoryStream immutableStream); IServerLeafSubGrid immutableLeaf = new ServerSubGridTreeLeaf(null, null, SubGridTreeConsts.SubGridTreeLevels, StorageMutability.Immutable); immutableLeaf.Directory.GlobalLatestCells = DIContext.Obtain <ISubGridCellLatestPassesDataWrapperFactory>().NewImmutableWrapper_Global(); immutableStream.Position = 0; immutableLeaf.LoadDirectoryFromStream(immutableStream); SubGridCellLatestPassDataWrapper_StaticCompressed immutableCells = (immutableLeaf.Directory.GlobalLatestCells as SubGridCellLatestPassDataWrapper_StaticCompressed); // Check height of the cells match to tolerance given the compressed lossiness. SubGridUtilities.SubGridDimensionalIterator((x, y) => { double mutableValue = mutableCells[x, y].Height; double immutableValue = immutableCells.ReadHeight(x, y); double diff = immutableValue - mutableValue; Assert.True(Math.Abs(diff) <= 0.001, $"Cell height at ({x}, {y}) has unexpected value: {immutableValue} vs {mutableValue}, diff = {diff}"); }); }
public void Test_SubGridCellLatestPassDataWrapper_NonStatic_Creation() { SubGridCellLatestPassDataWrapper_NonStatic wrapper = new SubGridCellLatestPassDataWrapper_NonStatic(); Assert.True(wrapper.PassDataExistenceMap != null && wrapper.PassDataExistenceMap.IsEmpty(), "Instance not created as expected"); }