|
| 1 | +/* |
| 2 | +This file is part of the iText (R) project. |
| 3 | +Copyright (c) 1998-2024 Apryse Group NV |
| 4 | +Authors: Apryse Software. |
| 5 | +
|
| 6 | +This program is offered under a commercial and under the AGPL license. |
| 7 | +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. |
| 8 | +
|
| 9 | +AGPL licensing: |
| 10 | +This program is free software: you can redistribute it and/or modify |
| 11 | +it under the terms of the GNU Affero General Public License as published by |
| 12 | +the Free Software Foundation, either version 3 of the License, or |
| 13 | +(at your option) any later version. |
| 14 | +
|
| 15 | +This program is distributed in the hope that it will be useful, |
| 16 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | +GNU Affero General Public License for more details. |
| 19 | +
|
| 20 | +You should have received a copy of the GNU Affero General Public License |
| 21 | +along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 22 | +*/ |
| 23 | +using System; |
| 24 | +using System.Collections.Generic; |
| 25 | +using iText.Commons.Datastructures; |
| 26 | +using iText.Test; |
| 27 | + |
| 28 | +namespace iText.Commons.Datastructures.Portable { |
| 29 | + [NUnit.Framework.Category("UnitTest")] |
| 30 | + public class NullUnlimitedListTest : ExtendedITextTest { |
| 31 | + [NUnit.Framework.Test] |
| 32 | + public virtual void NullUnlimitedListAddTest() { |
| 33 | + NullUnlimitedList<String> list = new NullUnlimitedList<String>(); |
| 34 | + list.Add("hey"); |
| 35 | + list.Add("bye"); |
| 36 | + NUnit.Framework.Assert.AreEqual(2, list.Size()); |
| 37 | + list.Add(-1, "hello"); |
| 38 | + list.Add(3, "goodbye"); |
| 39 | + NUnit.Framework.Assert.AreEqual(2, list.Size()); |
| 40 | + } |
| 41 | + |
| 42 | + [NUnit.Framework.Test] |
| 43 | + public virtual void NullUnlimitedListIndexOfTest() { |
| 44 | + NullUnlimitedList<String> list = new NullUnlimitedList<String>(); |
| 45 | + list.Add("hey"); |
| 46 | + list.Add(null); |
| 47 | + list.Add("bye"); |
| 48 | + list.Add(null); |
| 49 | + NUnit.Framework.Assert.AreEqual(4, list.Size()); |
| 50 | + NUnit.Framework.Assert.AreEqual(1, list.IndexOf(null)); |
| 51 | + } |
| 52 | + |
| 53 | + [NUnit.Framework.Test] |
| 54 | + public virtual void NullUnlimitedListRemoveTest() { |
| 55 | + NullUnlimitedList<String> list = new NullUnlimitedList<String>(); |
| 56 | + list.Add("hey"); |
| 57 | + list.Add("bye"); |
| 58 | + NUnit.Framework.Assert.AreEqual(2, list.Size()); |
| 59 | + list.Remove(-1); |
| 60 | + list.Remove(2); |
| 61 | + NUnit.Framework.Assert.AreEqual(2, list.Size()); |
| 62 | + } |
| 63 | + |
| 64 | + [NUnit.Framework.Test] |
| 65 | + public virtual void TestIsEmpty() { |
| 66 | + NullUnlimitedList<String> list = new NullUnlimitedList<String>(); |
| 67 | + NUnit.Framework.Assert.IsTrue(list.IsEmpty()); |
| 68 | + list.Add("hey"); |
| 69 | + NUnit.Framework.Assert.IsFalse(list.IsEmpty()); |
| 70 | + } |
| 71 | + |
| 72 | + [NUnit.Framework.Test] |
| 73 | + public virtual void TestSameBehaviour01() { |
| 74 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 75 | + actionList.Add((list) => list.Add("1")); |
| 76 | + actionList.Add((list) => list.Add(null)); |
| 77 | + actionList.Add((list) => list.Add("1")); |
| 78 | + actionList.Add((list) => list.Add("1")); |
| 79 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(1, list.IndexOf(null))); |
| 80 | + ExecuteActions(actionList); |
| 81 | + } |
| 82 | + |
| 83 | + [NUnit.Framework.Test] |
| 84 | + public virtual void TestSameBehaviour02() { |
| 85 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 86 | + actionList.Add((list) => list.Add("1")); |
| 87 | + actionList.Add((list) => list.Add(null)); |
| 88 | + actionList.Add((list) => list.Add("1")); |
| 89 | + actionList.Add((list) => list.Add("1")); |
| 90 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(4, list.Size())); |
| 91 | + ExecuteActions(actionList); |
| 92 | + } |
| 93 | + |
| 94 | + [NUnit.Framework.Test] |
| 95 | + public virtual void TestSameBehaviour03() { |
| 96 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 97 | + actionList.Add((list) => list.Add("1")); |
| 98 | + actionList.Add((list) => list.Add(null)); |
| 99 | + actionList.Add((list) => list.Add("1")); |
| 100 | + actionList.Add((list) => list.Add("1")); |
| 101 | + actionList.Add((list) => list.Add(null)); |
| 102 | + actionList.Add((list) => list.Set(1, "4")); |
| 103 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(list.Get(1), "4")); |
| 104 | + ExecuteActions(actionList); |
| 105 | + } |
| 106 | + |
| 107 | + [NUnit.Framework.Test] |
| 108 | + public virtual void TestSameBehaviour04() { |
| 109 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 110 | + actionList.Add((list) => list.Add("1")); |
| 111 | + actionList.Add((list) => list.Add(null)); |
| 112 | + actionList.Add((list) => list.Add("1")); |
| 113 | + actionList.Add((list) => list.Add("1")); |
| 114 | + actionList.Add((list) => list.Add(null)); |
| 115 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(1, list.IndexOf(null))); |
| 116 | + ExecuteActions(actionList); |
| 117 | + } |
| 118 | + |
| 119 | + [NUnit.Framework.Test] |
| 120 | + public virtual void TestSameBehaviour05() { |
| 121 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 122 | + actionList.Add((list) => list.Add("1")); |
| 123 | + actionList.Add((list) => list.Add("1")); |
| 124 | + actionList.Add((list) => list.Add("1")); |
| 125 | + actionList.Add((list) => list.Add("1")); |
| 126 | + actionList.Add((list) => list.Add("1")); |
| 127 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(-1, list.IndexOf(null))); |
| 128 | + ExecuteActions(actionList); |
| 129 | + } |
| 130 | + |
| 131 | + [NUnit.Framework.Test] |
| 132 | + public virtual void TestSameBehaviour06() { |
| 133 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 134 | + actionList.Add((list) => list.Add("1")); |
| 135 | + actionList.Add((list) => list.Add("2")); |
| 136 | + actionList.Add((list) => list.Add("3")); |
| 137 | + actionList.Add((list) => list.Add("4")); |
| 138 | + actionList.Add((list) => list.Add("5")); |
| 139 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(4, list.IndexOf("5"))); |
| 140 | + ExecuteActions(actionList); |
| 141 | + } |
| 142 | + |
| 143 | + [NUnit.Framework.Test] |
| 144 | + public virtual void TestSameBehaviour07() { |
| 145 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 146 | + actionList.Add((list) => list.Add("1")); |
| 147 | + actionList.Add((list) => list.Add("2")); |
| 148 | + actionList.Add((list) => list.Add("3")); |
| 149 | + actionList.Add((list) => list.Add("4")); |
| 150 | + actionList.Add((list) => list.Add("5")); |
| 151 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(-1, list.IndexOf("6"))); |
| 152 | + ExecuteActions(actionList); |
| 153 | + } |
| 154 | + |
| 155 | + [NUnit.Framework.Test] |
| 156 | + public virtual void TestSameBehaviour08() { |
| 157 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 158 | + actionList.Add((list) => list.Add("1")); |
| 159 | + actionList.Add((list) => list.Add("2")); |
| 160 | + actionList.Add((list) => list.Add("3")); |
| 161 | + actionList.Add((list) => list.Add("4")); |
| 162 | + actionList.Add((list) => list.Add(2, "5")); |
| 163 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(5, list.Size())); |
| 164 | + ExecuteActions(actionList); |
| 165 | + } |
| 166 | + |
| 167 | + [NUnit.Framework.Test] |
| 168 | + public virtual void TestSameBehaviour09() { |
| 169 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 170 | + actionList.Add((list) => list.Add("1")); |
| 171 | + actionList.Add((list) => list.Add("2")); |
| 172 | + actionList.Add((list) => list.Add("3")); |
| 173 | + actionList.Add((list) => list.Add("4")); |
| 174 | + actionList.Add((list) => list.Set(2, null)); |
| 175 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(4, list.Size())); |
| 176 | + ExecuteActions(actionList); |
| 177 | + } |
| 178 | + |
| 179 | + [NUnit.Framework.Test] |
| 180 | + public virtual void TestSameBehaviour10() { |
| 181 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 182 | + actionList.Add((list) => list.Add("1")); |
| 183 | + actionList.Add((list) => list.Add("2")); |
| 184 | + actionList.Add((list) => list.Add("3")); |
| 185 | + actionList.Add((list) => list.Add("4")); |
| 186 | + actionList.Add((list) => list.Remove(2)); |
| 187 | + actionList.Add((list) => NUnit.Framework.Assert.AreEqual(3, list.Size())); |
| 188 | + ExecuteActions(actionList); |
| 189 | + } |
| 190 | + |
| 191 | + [NUnit.Framework.Test] |
| 192 | + public virtual void TestSameBehaviour11() { |
| 193 | + IList<Action<ISimpleList<String>>> actionList = new List<Action<ISimpleList<String>>>(); |
| 194 | + actionList.Add((list) => NUnit.Framework.Assert.IsTrue(list.IsEmpty())); |
| 195 | + actionList.Add((list) => list.Add("1")); |
| 196 | + actionList.Add((list) => NUnit.Framework.Assert.IsFalse(list.IsEmpty())); |
| 197 | + actionList.Add((list) => list.Add("2")); |
| 198 | + actionList.Add((list) => list.Add("3")); |
| 199 | + actionList.Add((list) => list.Add("4")); |
| 200 | + actionList.Add((list) => NUnit.Framework.Assert.IsFalse(list.IsEmpty())); |
| 201 | + ExecuteActions(actionList); |
| 202 | + } |
| 203 | + |
| 204 | + public virtual void ExecuteActions(IList<Action<ISimpleList<String>>> actionList) { |
| 205 | + NullUnlimitedList<String> list = new NullUnlimitedList<String>(); |
| 206 | + SimpleArrayList<String> list2 = new SimpleArrayList<String>(); |
| 207 | + foreach (Action<ISimpleList<String>> action in actionList) { |
| 208 | + action(list); |
| 209 | + action(list2); |
| 210 | + } |
| 211 | + } |
| 212 | + } |
| 213 | +} |
0 commit comments