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 }
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); }
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)); }
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); }