Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StringCollectionTest.cs « System.Collections.Specialized « Test « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 839970cd7864f6789ad557d73c3e8e97e29176e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* System.Collections.Specialized.StringCollection.cs
 * Authors:
 *   John Barnette (jbarn@httcb.net)
 *
 *  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));
		}
			
	}
}