| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /* System.Collections.Specialized.StringCollection.cs
- * Authors:
- * John Barnette ([email protected])
- *
- * Copyright (C) 2001 John Barnette
- */
- using NUnit.Framework;
- using System.Collections.Specialized;
- namespace MonoTests.System.Collections.Specialized {
- public class StringCollectionTest : TestCase {
- public static ITest Suite {
- get {
- return new TestSuite(typeof (StringCollectionTest));
- }
- }
- private StringCollection sc;
- string[] strings = {
- "foo",
- "bar",
- "baz",
- "john",
- "paul",
- "george",
- "ringo"
- };
-
- public StringCollectionTest() : base("MonoTests.System.Collections.Specialized.StringCollectionTest testsuite") {}
- public StringCollectionTest(string name) : base(name) {}
-
- protected override void SetUp() {
- sc = new StringCollection();
- sc.AddRange(strings);
- }
- // Simple Tests
-
- public void TestSimpleCount() {
- Assert(sc.Count == 7);
- }
-
- public void TestSimpleIsReadOnly() {
- Assert(!sc.IsReadOnly);
- }
-
- public void TestSimpleIsSynchronized() {
- Assert(!sc.IsSynchronized);
- }
-
- public void TestSimpleItemGet() {
- for(int i = 0; i < strings.Length; i++) {
- Assert(strings[i].Equals(sc[i]));
- }
- }
-
- public void TestSimpleItemSet() {
- sc[0] = "bob";
- Assert(sc[0].Equals("bob"));
- }
-
- public void TestSimpleSyncRoot() {
- Assert(sc.Equals(sc.SyncRoot));
- }
-
- public void TestSimpleAdd() {
- int index = sc.Add("chuck");
- Assert(index == strings.Length);
- Assert(sc[strings.Length].Equals("chuck"));
-
- }
-
- public void TestSimpleAddRange() {
- string[] newStrings = {
- "peter",
- "paul",
- "mary"
- };
-
- int index = sc.Count;
- sc.AddRange(newStrings);
-
- Assert(sc.Count == index + newStrings.Length);
-
- for (int i = 0; i+index <= sc.Count-1; i++) {
- Assert(newStrings[i].Equals(sc[i+index]));
- }
- }
-
- public void TestSimpleClear() {
- sc.Clear();
- Assert(sc.Count == 0);
- }
-
- public void TestSimpleContains() {
- Assert(sc.Contains(strings[0]));
- Assert(!sc.Contains("NOT CONTAINED"));
- }
-
- public void TestSimpleCopyTo() {
- string[] copyArray = new string[sc.Count];
- sc.CopyTo(copyArray, 0);
- for (int i = 0; i < copyArray.Length; i++) {
- Assert(copyArray[i] == sc[i]);
- }
- }
-
- public void TestSimpleGetEnumerator() {
- int index = 0;
- foreach(string s in sc) {
- Assert(s.Equals(strings[index]));
- index++;
- }
- }
-
- public void TestSimpleIndexOf() {
- Assert(sc.IndexOf(strings[0]) == 0);
- }
-
- public void TestSimpleInsert() {
- int index = 3;
- int oldCount = sc.Count;
- string before = sc[index - 1];
- string current = sc[index];
- string after = sc[index + 1];
- string newStr = "paco";
-
- sc.Insert(index, newStr);
-
- Assert(sc.Count == oldCount + 1);
- Assert(sc[index].Equals(newStr));
- Assert(sc[index-1].Equals(before));
- Assert(sc[index+1].Equals(current));
- Assert(sc[index+2].Equals(after));
- }
-
- public void TestSimpleRemove() {
- int oldCount = sc.Count;
- sc.Remove(strings[0]);
- Assert(oldCount == sc.Count + 1);
- Assert(!sc.Contains(strings[0]));
- }
-
- public void TestSimpleRemoveAt() {
- int index = 3;
- int oldCount = sc.Count;
- string after = sc[index+1];
-
- sc.RemoveAt(index);
- Assert(oldCount == sc.Count + 1);
- Assert(sc[index].Equals(after));
- }
-
- }
- }
|