public void ManipulatingList() { var sameTags = new NbtTag[] { new NbtInt(0), new NbtInt(1), new NbtInt(2) }; var list = new NbtList("Test1", sameTags); // testing enumerator, indexer, Contains, and IndexOf int j = 0; foreach (NbtTag tag in list) { Assert.IsTrue(list.Contains(sameTags[j])); Assert.AreEqual(sameTags[j], tag); Assert.AreEqual(j, list.IndexOf(tag)); j++; } // adding an item of correct type list.Add(new NbtInt(3)); list.Insert(3, new NbtInt(4)); // adding an item of wrong type Assert.Throws <ArgumentException>(() => list.Add(new NbtString())); Assert.Throws <ArgumentException>(() => list.Insert(3, new NbtString())); Assert.Throws <ArgumentNullException>(() => list.Insert(3, null)); // testing array contents for (int i = 0; i < sameTags.Length; i++) { Assert.AreSame(sameTags[i], list[i]); Assert.AreEqual(i, ((NbtInt)list[i]).Value); } // test removal Assert.IsFalse(list.Remove(new NbtInt(5))); Assert.IsTrue(list.Remove(sameTags[0])); Assert.Throws <ArgumentNullException>(() => list.Remove(null)); list.RemoveAt(0); Assert.Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(10)); // Test some failure scenarios for Add: // adding a list to itself var loopList = new NbtList(); Assert.AreEqual(NbtTagType.Unknown, loopList.ListType); Assert.Throws <ArgumentException>(() => loopList.Add(loopList)); // adding same tag to multiple lists Assert.Throws <ArgumentException>(() => loopList.Add(list[0])); Assert.Throws <ArgumentException>(() => loopList.Insert(0, list[0])); // adding null tag Assert.Throws <ArgumentNullException>(() => loopList.Add(null)); // make sure that all those failed adds didn't affect the tag Assert.AreEqual(0, loopList.Count); Assert.AreEqual(NbtTagType.Unknown, loopList.ListType); // try creating a list with invalid tag type Assert.Throws <ArgumentOutOfRangeException>(() => new NbtList((NbtTagType)200)); }
public void ManipulatingList() { var sameTags = new NbtTag[] { new NbtInt(0), new NbtInt(1), new NbtInt(2) }; var list = new NbtList("Test1", sameTags); // testing enumerator, indexer, Contains, and IndexOf int j = 0; foreach (NbtTag tag in list) { Assert.IsTrue(list.Contains(sameTags[j])); Assert.AreEqual(sameTags[j], tag); Assert.AreEqual(j, list.IndexOf(tag)); j++; } // adding an item of correct type list.Add(new NbtInt(3)); list.Insert(3, new NbtInt(4)); // adding an item of wrong type Assert.Throws<ArgumentException>(() => list.Add(new NbtString())); Assert.Throws<ArgumentException>(() => list.Insert(3, new NbtString())); Assert.Throws<ArgumentNullException>(() => list.Insert(3, null)); // testing array contents for (int i = 0; i < sameTags.Length; i++) { Assert.AreSame(sameTags[i], list[i]); Assert.AreEqual(i, ((NbtInt)list[i]).Value); } // test removal Assert.IsFalse(list.Remove(new NbtInt(5))); Assert.IsTrue(list.Remove(sameTags[0])); Assert.Throws<ArgumentNullException>(() => list.Remove(null)); list.RemoveAt(0); Assert.Throws<ArgumentOutOfRangeException>(() => list.RemoveAt(10)); // Test some failure scenarios for Add: // adding a list to itself var loopList = new NbtList(); Assert.AreEqual(NbtTagType.Unknown, loopList.ListType); Assert.Throws<ArgumentException>(() => loopList.Add(loopList)); // adding same tag to multiple lists Assert.Throws<ArgumentException>(() => loopList.Add(list[0])); Assert.Throws<ArgumentException>(() => loopList.Insert(0, list[0])); // adding null tag Assert.Throws<ArgumentNullException>(() => loopList.Add(null)); // make sure that all those failed adds didn't affect the tag Assert.AreEqual(0, loopList.Count); Assert.AreEqual(NbtTagType.Unknown, loopList.ListType); // try creating a list with invalid tag type Assert.Throws<ArgumentOutOfRangeException>(() => new NbtList((NbtTagType)200)); }