1 // System.Collections.Specialized.StringCollection.cs
4 // John Barnette (jbarn@httcb.net)
5 // Martin Willemoes Hansen (mwh@sysrq.dk)
7 // (C) Copyright 2001 John Barnette
8 // (C) Copyright 2003 Martin Willemoes Hansen
11 using NUnit
.Framework
;
12 using System
.Collections
.Specialized
;
14 namespace MonoTests
.System
.Collections
.Specialized
{
17 public class StringCollectionTest
{
19 private StringCollection sc
;
31 public void GetReady()
33 sc
= new StringCollection();
39 public void SimpleCount()
41 Assertion
.Assert(sc
.Count
== 7);
45 public void SimpleIsReadOnly()
47 Assertion
.Assert(!sc
.IsReadOnly
);
51 public void SimpleIsSynchronized()
53 Assertion
.Assert(!sc
.IsSynchronized
);
57 public void SimpleItemGet()
59 for(int i
= 0; i
< strings
.Length
; i
++) {
60 Assertion
.Assert(strings
[i
].Equals(sc
[i
]));
65 public void SimpleItemSet()
68 Assertion
.Assert(sc
[0].Equals("bob"));
72 public void SimpleSyncRoot()
74 Assertion
.Assert(sc
.Equals(sc
.SyncRoot
));
78 public void SimpleAdd()
80 int index
= sc
.Add("chuck");
81 Assertion
.Assert(index
== strings
.Length
);
82 Assertion
.Assert(sc
[strings
.Length
].Equals("chuck"));
87 public void SimpleAddRange()
89 string[] newStrings
= {
96 sc
.AddRange(newStrings
);
98 Assertion
.Assert(sc
.Count
== index
+ newStrings
.Length
);
100 for (int i
= 0; i
+index
<= sc
.Count
-1; i
++) {
101 Assertion
.Assert(newStrings
[i
].Equals(sc
[i
+index
]));
106 public void SimpleClear()
109 Assertion
.Assert(sc
.Count
== 0);
113 public void SimpleContains()
115 Assertion
.Assert(sc
.Contains(strings
[0]));
116 Assertion
.Assert(!sc
.Contains("NOT CONTAINED"));
120 public void SimpleCopyTo()
122 string[] copyArray
= new string[sc
.Count
];
123 sc
.CopyTo(copyArray
, 0);
124 for (int i
= 0; i
< copyArray
.Length
; i
++) {
125 Assertion
.Assert(copyArray
[i
] == sc
[i
]);
130 public void SimpleGetEnumerator()
133 foreach(string s
in sc
) {
134 Assertion
.Assert(s
.Equals(strings
[index
]));
140 public void SimpleIndexOf()
142 Assertion
.Assert(sc
.IndexOf(strings
[0]) == 0);
146 public void SimpleInsert()
149 int oldCount
= sc
.Count
;
150 string before
= sc
[index
- 1];
151 string current
= sc
[index
];
152 string after
= sc
[index
+ 1];
153 string newStr
= "paco";
155 sc
.Insert(index
, newStr
);
157 Assertion
.Assert(sc
.Count
== oldCount
+ 1);
158 Assertion
.Assert(sc
[index
].Equals(newStr
));
159 Assertion
.Assert(sc
[index
-1].Equals(before
));
160 Assertion
.Assert(sc
[index
+1].Equals(current
));
161 Assertion
.Assert(sc
[index
+2].Equals(after
));
165 public void SimpleRemove()
167 int oldCount
= sc
.Count
;
168 sc
.Remove(strings
[0]);
169 Assertion
.Assert(oldCount
== sc
.Count
+ 1);
170 Assertion
.Assert(!sc
.Contains(strings
[0]));
174 public void SimpleRemoveAt()
177 int oldCount
= sc
.Count
;
178 string after
= sc
[index
+1];
181 Assertion
.Assert(oldCount
== sc
.Count
+ 1);
182 Assertion
.Assert(sc
[index
].Equals(after
));