Tanoda
ListAndArrayExtensionTests.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using System.Collections.Generic;
11using NUnit.Framework;
12
13namespace Leap.Unity.Tests {
14
16
17 [Test]
18 public void RemoveAtMany_Random() {
19 List<int> toRemove = new List<int>().FillEach(100, i => i);
20 while (toRemove.Count != 20) {
21 toRemove.RemoveAt(Random.Range(0, toRemove.Count));
22 }
23
24 doRemoveAtManyTest(toRemove);
25 }
26
27 [Test]
28 public void RemoveAtMany_First() {
29 List<int> toRemove = new List<int>();
30 toRemove.Add(0);
31 toRemove.Add(50);
32
33 doRemoveAtManyTest(toRemove);
34 }
35
36 [Test]
37 public void RemoveAtMany_Last() {
38 List<int> toRemove = new List<int>();
39 toRemove.Add(50);
40 toRemove.Add(99);
41
42 doRemoveAtManyTest(toRemove);
43 }
44
45 [Test]
47 List<int> toRemove = new List<int>();
48 toRemove.Add(50);
49 toRemove.Add(51);
50 toRemove.Add(52);
51 toRemove.Add(53);
52
53 doRemoveAtManyTest(toRemove);
54 }
55
56 [Test]
57 public void InsertMany_Random() {
58 List<int> toInsert = new List<int>().FillEach(20, i => i * 1000 + 99);
59 List<int> indexes = new List<int>().FillEach(100, i => i);
60 while (indexes.Count != toInsert.Count) {
61 indexes.RemoveAt(Random.Range(0, indexes.Count));
62 }
63
64 doInsertManyTest(toInsert, indexes);
65 }
66
67 [Test]
68 public void InsertMany_First() {
69 List<int> toInsert = new List<int>();
70 List<int> indexes = new List<int>();
71 toInsert.Add(999);
72 toInsert.Add(888);
73 indexes.Add(0);
74 indexes.Add(50);
75 doInsertManyTest(toInsert, indexes);
76 }
77
78 [Test]
79 public void InsertMany_Last() {
80 List<int> toInsert = new List<int>();
81 List<int> indexes = new List<int>();
82 toInsert.Add(999);
83 toInsert.Add(888);
84 indexes.Add(50);
85 indexes.Add(99);
86 doInsertManyTest(toInsert, indexes);
87 }
88
89 [Test]
90 public void InsertMany_Sequential() {
91 List<int> toInsert = new List<int>();
92 List<int> indexes = new List<int>();
93 toInsert.Add(999);
94 toInsert.Add(888);
95 toInsert.Add(777);
96 toInsert.Add(666);
97 indexes.Add(50);
98 indexes.Add(51);
99 indexes.Add(52);
100 indexes.Add(53);
101 doInsertManyTest(toInsert, indexes);
102 }
103
104 private void doRemoveAtManyTest(List<int> toRemove) {
105 List<int> listA = new List<int>().FillEach(100, i => i);
106 List<int> listB = new List<int>(listA);
107
108 for (int i = toRemove.Count; i-- != 0;) {
109 listA.RemoveAt(toRemove[i]);
110 }
111
112 listB.RemoveAtMany(toRemove);
113
114 Assert.AreEqual(listA, listB);
115 }
116
117 private void doInsertManyTest(List<int> toInsert, List<int> indexes) {
118 List<int> listA = new List<int>().FillEach(100, i => i);
119 List<int> listB = new List<int>(listA);
120
121 for (int i = 0; i < toInsert.Count; i++) {
122 listA.Insert(indexes[i], toInsert[i]);
123 }
124
125 listB.InsertMany(indexes, toInsert);
126
127 Assert.AreEqual(listA, listB);
128 }
129 }
130}
UnityEngine.Random Random