-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
Helpers.cs
213 lines (173 loc) · 6.2 KB
/
Helpers.cs
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Globalization;
namespace System.Collections.Tests
{
internal static class Helpers
{
public static string[] TestCultureNames =>
PlatformDetection.IsInvariantGlobalization ?
new string[] { "" } :
new string[]
{
"cs-CZ","da-DK","de-DE","el-GR","en-US",
"es-ES","fi-FI","fr-FR","hu-HU","it-IT",
"ja-JP","ko-KR","nb-NO","nl-NL","pl-PL",
"pt-BR","pt-PT","ru-RU","sv-SE","tr-TR",
"zh-CN","zh-HK","zh-TW"
};
public static void PerformActionOnAllHashtableWrappers(Hashtable hashtable, Action<Hashtable> action)
{
// Synchronized returns a slightly different version of Hashtable
Hashtable[] hashtableTypes =
{
(Hashtable)hashtable.Clone(),
Hashtable.Synchronized(hashtable)
};
foreach (Hashtable hashtableType in hashtableTypes)
{
action(hashtableType);
}
}
public static Hashtable CreateIntHashtable(int count, int start = 0)
{
var hashtable = new Hashtable();
for (int i = start; i < start + count; i++)
{
hashtable.Add(i, i);
}
return hashtable;
}
public static Hashtable CreateStringHashtable(int count, int start = 0)
{
var hashtable = new Hashtable();
for (int i = start; i < start + count; i++)
{
string key = "Key_" + i;
string value = "Value_" + i;
hashtable.Add(key, value);
}
return hashtable;
}
public static void PerformActionOnAllArrayListWrappers(ArrayList arrList, Action<ArrayList> action)
{
// Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of ArrayList.
// The following variable contains each one of these types of array lists
ArrayList[] arrayListTypes =
{
(ArrayList)arrList.Clone(),
(ArrayList)arrList.GetRange(0, arrList.Count).Clone(),
(ArrayList)ArrayList.Adapter(arrList).Clone(),
(ArrayList)ArrayList.FixedSize(arrList).Clone(),
(ArrayList)ArrayList.ReadOnly(arrList).Clone(),
(ArrayList)ArrayList.Synchronized(arrList).Clone()
};
foreach (ArrayList arrListType in arrayListTypes)
{
action(arrListType);
}
}
public static ArrayList CreateStringArrayList(int count, int start = 0, string optionalString = null)
{
var arrayList = new ArrayList();
for (int i = start; i < start + count; i++)
{
arrayList.Add(i.ToString() + optionalString);
}
return arrayList;
}
public static ArrayList CreateIntArrayList(int count, int start = 0)
{
var arrayList = new ArrayList();
for (int i = start; i < start + count; i++)
{
arrayList.Add(i);
}
return arrayList;
}
public static void PerformActionOnAllQueueWrappers(Queue queue, Action<Queue> action)
{
// Synchronized returns a slightly different version of Queue
Queue[] queueTypes =
{
(Queue)queue.Clone(),
Queue.Synchronized(queue)
};
foreach (Queue queueType in queueTypes)
{
action(queueType);
}
}
public static Queue CreateIntQueue(int count, int start = 0)
{
var queue = new Queue();
for (int i = start; i < start + count; i++)
{
queue.Enqueue(i);
}
return queue;
}
public static void PerformActionOnAllStackWrappers(Stack stack, Action<Stack> action)
{
// Synchronized returns a slightly different version of Stack
Stack[] stackTypes =
{
(Stack)stack.Clone(),
Stack.Synchronized(stack)
};
foreach (Stack stackType in stackTypes)
{
action(stackType);
}
}
public static Stack CreateIntStack(int count, int start = 0)
{
var stack = new Stack();
for (int i = start; i < start + count; i++)
{
stack.Push(i);
}
return stack;
}
public static void PerformActionOnAllSortedListWrappers(SortedList sortedList, Action<SortedList> action)
{
// Synchronized returns a slightly different version of Stack
SortedList[] sortedListTypes =
{
(SortedList)sortedList.Clone(),
SortedList.Synchronized(sortedList)
};
foreach (SortedList sortedListType in sortedListTypes)
{
action(sortedListType);
}
}
public static SortedList CreateIntSortedList(int count, int start = 0)
{
var sortedList = new SortedList();
for (int i = start; i < start + count; i++)
{
sortedList.Add(i, i);
}
return sortedList;
}
public static SortedList CreateStringSortedList(int count, int start = 0)
{
var sortedList = new SortedList();
for (int i = start; i < start + count; i++)
{
sortedList.Add($"Key_{i:D2}", $"Value_{i}");
}
return sortedList;
}
public static int[] CreateIntArray(int count, int start = 0)
{
var array = new int[count];
for (int i = start; i < start + count; i++)
{
array[i] = i;
}
return array;
}
}
}