public void SetItemOutOfRangeTest() { const int count = 10; IPersistentList <int> list = PersistentList <int> .Of(new int[count]); Assert.Throws <IndexOutOfRangeException>(() => list.Set(-1, -1)); Assert.Throws <IndexOutOfRangeException>(() => list.Set(count, -1)); }
public void SetItemTest() { const int count = 200; IPersistentList <int> list = PersistentList <int> .Empty; for (int i = 0; i < count; i++) { list = list.Add(i); } IPersistentList <int> list2 = list; for (int i = 0; i < count; i++) { list = list.Set(i, j => j + 1, out int oldValue); Assert.Equal(i, oldValue); list2 = list2.Set(i, i + 1, out oldValue); Assert.Equal(i, oldValue); } CheckListEquality(Enumerable.Range(1, count).ToArray(), list); CheckListEquality(Enumerable.Range(1, count).ToArray(), list2); }