public void TestAddRange() { int[] expected = { 600, 601, 602, 603, 700, 701, 702, 703, 800, 801, 802, 803 }; ImmutableSortedTreeList <int> .Builder list = ImmutableSortedTreeList.CreateBuilder <int>(); list.AddRange(expected); Assert.Equal(expected.Length, list.Count); int[] actual = list.ToArray(); Assert.Equal(expected, actual); Assert.Throws <ArgumentNullException>(() => list.AddRange(null !)); }
public void TestAddMany() { int[] expected = { 600, 601, 602, 603, 700, 701, 702, 703, 800, 801, 802, 803 }; ImmutableSortedTreeList <int> .Builder list = ImmutableSortedTreeList.CreateBuilder <int>(); foreach (var item in expected) { list.Add(item); Assert.Equal(item, list[list.Count - 1]); } Assert.Equal(expected.Length, list.Count); int[] actual = list.ToArray(); Assert.Equal(expected, actual); }
public void TestGetRange() { var list = ImmutableSortedTreeList.CreateRange(comparer: null, Enumerable.Range(0, 100)).ToBuilder(); var reference = new List <int>(Enumerable.Range(0, 100)); ImmutableSortedTreeList <int> subList = list.GetRange(10, 80); List <int> subReference = reference.GetRange(10, 80); Assert.Equal(subReference, subList); // Verify that changes to the original list do not affect previous calls to GetRange int[] values = subList.ToArray(); list.Add(list[list.Count / 2]); reference.Insert((reference.Count / 2) + 1, reference[reference.Count / 2]); Assert.Equal(reference, list); Assert.Equal(values, subList); Assert.Equal(values, subReference); }
public void TestAdd() { int value = Generator.GetInt32(); ImmutableSortedTreeList <int> .Builder list = ImmutableSortedTreeList.CreateBuilder <int>(); Assert.Empty(list); list.Add(value); Assert.Single(list); Assert.Equal(value, list[0]); int[] expected = { value }; int[] actual = list.ToArray(); Assert.Equal(expected, actual); Assert.True(list.Add(value, addIfPresent: true)); Assert.Equal(new[] { value, value }, list); Assert.False(list.Add(value, addIfPresent: false)); Assert.Equal(new[] { value, value }, list); }