public void TestMutabilification() { // Make a single block mutable VList <int> v = new VList <int>(1, 0); WList <int> w = v.ToWList(); ExpectList(w, 1, 0); w[1] = 2; ExpectList(w, 1, 2); ExpectList(v, 1, 0); // Make another block, make the front block mutable, then the block-of-2 v.Push(-1); w = v.ToWList(); w[2] = 3; ExpectList(w, 1, 0, 3); Assert.That(w.WithoutLast(1) == v.WithoutLast(1)); w[1] = 2; ExpectList(w, 1, 2, 3); Assert.That(w.WithoutLast(1) != v.WithoutLast(1)); // Now for a more complicated case: create a long immutable chain by // using a nasty access pattern, add a mutable block in front, then // make some of the immutable blocks mutable. This will cause several // immutable blocks to be consolidated into one mutable block, // shortening the chain. v = new VList <int>(6); v = v.Add(-1).Tail.Add(5).Add(-1).Tail.Add(4).Add(-1).Tail.Add(3); v = v.Add(-1).Tail.Add(2).Add(-1).Tail.Add(1).Add(-1).Tail.Add(0); ExpectList(v, 6, 5, 4, 3, 2, 1, 0); // At this point, every block in the chain has only one item (it's // a linked list!) and the capacity of each block is 2. Assert.AreEqual(7, v.BlockChainLength); w = v.ToWList(); w.AddRange(new int[] { 1, 2, 3, 4, 5 }); Assert.AreEqual(w.Count, 12); ExpectList(w, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5); // Indices: 0 1 2 3 4 5 6 7 8 9 10 11 // Blocks: H| G| F| E| D| C| B | block A (front of chain) Assert.AreEqual(8, w.BlockChainLength); Assert.AreEqual(4, w.LocalCount); w[3] = -3; ExpectList(w, 6, 5, 4, -3, 2, 1, 0, 1, 2, 3, 4, 5); // Indices: 0 1 2 3 4 5 6 7 8 9 10 11 // Blocks: H| G| F| block I | block A (front of chain) Assert.AreEqual(5, w.BlockChainLength); }