public void InsertTest() { int count = 100; LxList <int> list = InitList(count); Assert.Catch <LxException>(() => { list.Insert(-1, -1); }); Assert.Catch <LxException>(() => { list.Insert(101, -1); }); list.Insert(0, -1); for (int i = 0; i < list.Count; ++i) { Assert.AreEqual(i - 1, list.Get(i)); } InsertTest(0, -1, count); InsertTest(count - 1, -1, count); InsertTest(count / 2, -1, count); }
public void BenchmarkInsertMiddle() { int count = 100; int[] array = new int[count]; List <int> list = new List <int>(count); LxList <int> lxList = new LxList <int>(count); Stopwatch watch = new Stopwatch(); watch.Start(); watch.Stop(); // assign test for (int i = 0; i < count; ++i) { array[i] = i; list.Add(i); lxList.Add(i); } int iteration = 10000; int[] newArray; // insert middle int middleIndex = count / 2; watch = MatchmakingTest.Measure(() => { lxList.Insert(middleIndex, -1); }, iteration); Debug.Log($"lxlist insert middle ticks {watch.ElapsedMilliseconds}"); watch = MatchmakingTest.Measure(() => { newArray = new int[array.Length + 1]; newArray[middleIndex] = -1; Array.Copy(array, 0, newArray, 0, middleIndex); Array.Copy(array, middleIndex, newArray, middleIndex + 1, array.Length - middleIndex); array = newArray; }, iteration); Debug.Log($"array insert middle {watch.ElapsedMilliseconds}"); watch = MatchmakingTest.Measure(() => { list.Insert(middleIndex, -1); }, iteration); Debug.Log($"list insert middle ticks {watch.ElapsedMilliseconds}"); }
public void BenchmarkInsertHead() { int count = 128; int iteration = 10000; int[] array = new int[count]; List <int> list = new List <int>(count); LxList <int> lxList = new LxList <int>(count); Stopwatch watch; // assign test for (int i = 0; i < count; ++i) { array[i] = i; list.Add(i); lxList.Add(i); } watch = MatchmakingTest.Measure(() => { int[] newArray; // insert head test newArray = new int[array.Length + 1]; newArray[0] = -1; Array.Copy(array, 0, newArray, 1, array.Length); array = newArray; }, iteration); Debug.Log($"array insert head {watch.ElapsedMilliseconds}"); watch = MatchmakingTest.Measure(() => { list.Insert(0, -1); }, iteration); Debug.Log($"list insert head {watch.ElapsedMilliseconds}"); watch = MatchmakingTest.Measure(() => { lxList.Insert(0, -1); }, iteration); Debug.Log($"lxList insert head {watch.ElapsedMilliseconds}"); }
public void SortTest() { int count = 100; LxList <SortTestData> list = new LxList <SortTestData>(); var comparer = new SortTestComparer(); for (int i = 0; i < count; ++i) { list.Add(new SortTestData { Data = i }, comparer, true); } for (int i = 0; i < count; ++i) { Assert.AreEqual(count - i - 1, list.Get(i).Data); } int[] testInput = new int[] { 9, 8, 7, 2, 33, 144, 22, 13, 44, 33 }; int[] testOuputUnique = new int[] { 144, 44, 33, 22, 13, 9, 8, 7, 2 }; int[] testOuputNoUnique = new int[] { 144, 44, 33, 33, 22, 13, 9, 8, 7, 2 }; list = new LxList <SortTestData>(); LxList <int> subList = new LxList <int>(); for (int i = 0; i < testInput.Length; ++i) { int insertIndex = list.Add(new SortTestData { Data = testInput[i] }, comparer, true); if (insertIndex >= 0) { subList.Insert(insertIndex, testInput[i]); } } Assert.AreEqual(subList.Count, list.Count); for (int i = 0; i < list.Count; ++i) { Assert.AreEqual(testOuputUnique[i], list.Get(i).Data); Assert.AreEqual(testOuputUnique[i], subList.Get(i)); } list = new LxList <SortTestData>(); subList = new LxList <int>(); for (int i = 0; i < testInput.Length; ++i) { int insertIndex = list.Add(new SortTestData { Data = testInput[i] }, comparer, false); if (insertIndex >= 0) { subList.Insert(insertIndex, testInput[i]); } } Assert.AreEqual(subList.Count, list.Count); for (int i = 0; i < list.Count; ++i) { Assert.AreEqual(testOuputNoUnique[i], list.Get(i).Data); Assert.AreEqual(testOuputNoUnique[i], subList.Get(i)); } }