public void JsonMapBuilder_EveryTwo() { string sampleFilePath = "Map.TinyArray.json"; File.WriteAllText(sampleFilePath, Extractor.GetResourceText("Map.TinyArray.json")); // File: 300b. // Map: Root (90b) + Array (5b x 50 (Count 100 / Every 2)) = 340b JsonMapNode root = JsonMapBuilder.Build(sampleFilePath, new JsonMapSettings(350.0 / 300.0)); // 100 array elements, only 50 starts, every = 2 Assert.Equal(100, root.Count); Assert.Equal(50, root.ArrayStarts.Count); Assert.Equal(2, root.Every); // Verify we see a[0], a[2], a[4], ... Assert.Equal(1, root.ArrayStarts[0]); Assert.Equal(7, root.ArrayStarts[1]); Assert.Equal(13, root.ArrayStarts[2]); // Ask the lookup method to find the positions of every element (every 3 bytes for "#, " for (int i = 0; i < root.Count; ++i) { long position = root.FindArrayStart(i, () => File.OpenRead(sampleFilePath)); Assert.Equal(1 + 3 * i, position); } }
public void JsonMapBuilder_EveryTwo() { string sampleFilePath = "Map.TinyArray.json"; File.WriteAllText(sampleFilePath, Extractor.GetResourceText("Map.TinyArray.json")); // Allow a map 1x the size of the original file JsonMapBuilder builder = new JsonMapBuilder(1); JsonMapNode root = builder.Build(sampleFilePath); // 100 array elements, only 50 starts, every = 2 Assert.Equal(100, root.Count); Assert.Equal(50, root.ArrayStarts.Count); Assert.Equal(2, root.Every); // Verify we see a[0], a[2], a[4], ... Assert.Equal(1, root.ArrayStarts[0]); Assert.Equal(7, root.ArrayStarts[1]); Assert.Equal(13, root.ArrayStarts[2]); // Ask the lookup method to find the positions of every element (every 3 bytes for "#, " for (int i = 0; i < root.Count; ++i) { long position = root.FindArrayStart(i, () => File.OpenRead(sampleFilePath)); Assert.Equal(1 + 3 * i, position); } }