示例#1
0
        public void AddOutOfRangePosition()
        {
            uint position     = 100;
            uint fileLocation = 100000;
            var  saIndexNode  = new SaIndexNode(position, fileLocation);

            // the node is out of range
            Assert.False(saIndexNode.TryAdd(position + uint.MaxValue, fileLocation + ushort.MaxValue - 1, false)); // location should not cause any problem
            Assert.False(saIndexNode.TryAdd(position + uint.MaxValue - 1, fileLocation + ushort.MaxValue, false)); // location should cause failure
        }
示例#2
0
        private static SaIndexNode MakeSaIndexNode(uint position)
        {
            uint fileLocation = 100000;
            var  saIndexNode  = new SaIndexNode(position, fileLocation, true);

            for (var i = 0; i < SaIndexNode.SaNodeWidth; i++)
            {
                saIndexNode.TryAdd(position + (uint)i * 3, fileLocation + (uint)i * 30, i % 3 == 0);//make every third node a ref minor
            }
            return(saIndexNode);
        }
示例#3
0
        public void NodePopulation()
        {
            uint position     = 100;
            uint fileLocation = 100000;
            var  saIndexNode  = new SaIndexNode(position, fileLocation);

            for (var i = 0; i < SaIndexNode.SaNodeWidth; i++)
            {
                Assert.True(saIndexNode.TryAdd(position + (uint)i * 3, fileLocation + (uint)i * 30, false));
            }

            //the node should be full by now
            Assert.False(saIndexNode.TryAdd(position + SaIndexNode.SaNodeWidth, fileLocation + ushort.MaxValue - 1, false));
        }
示例#4
0
        public void NodeWriteRead()
        {
            var saIndexNode = MakeSaIndexNode(100);

            var randomFilePath = GetRandomPath();

            using (var writer = new BinaryWriter(FileUtilities.GetCreateStream(randomFilePath)))
            {
                saIndexNode.Write(writer);
            }

            using (var reader = new BinaryReader(FileUtilities.GetReadStream(randomFilePath)))
            {
                var readNode = new SaIndexNode(reader);
                Assert.NotNull(readNode);

                Assert.Equal((uint)100, readNode.GetFirstPosition());
                Assert.Equal((uint)100000, readNode.GetFileLocation(100));
            }

            File.Delete(randomFilePath);
        }