Skip to content

Commit 838dab3

Browse files
committed
Added geography equivalence classes
1 parent ce89027 commit 838dab3

7 files changed

Lines changed: 372 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NTestDataBuilder.DataSources;
5+
using NTestDataBuilder.DataSources.Geography;
6+
using NTestDataBuilder.EquivalenceClasses;
7+
using Shouldly;
8+
using Xunit.Extensions;
9+
10+
namespace NTestDataBuilder.Tests.EquivalenceClasses
11+
{
12+
public class DictionaryEquivalenceClassesTests
13+
{
14+
public static AnonymousValueFixture Any { get; private set; }
15+
16+
public DictionaryEquivalenceClassesTests()
17+
{
18+
Any = new AnonymousValueFixture();
19+
}
20+
21+
[Theory]
22+
[PropertyData("TestCases")]
23+
public void WhenGettingAnyDictionaryData_ThenReturnRandomDictionaryDataWhichIsReasonablyUnique(DataSource<string> source,
24+
List<string> testCases, bool checkUniqueness = true)
25+
{
26+
foreach (var testCase in testCases)
27+
{
28+
testCase.ShouldBeOfType<string>();
29+
testCase.ShouldNotBeNullOrEmpty();
30+
source.Data.ShouldContain(testCase);
31+
}
32+
if (checkUniqueness)
33+
{
34+
var unique = testCases.Distinct().Count();
35+
unique.ShouldBeGreaterThan(5);
36+
}
37+
}
38+
39+
public static IEnumerable<object[]> TestCases
40+
{
41+
get
42+
{
43+
yield return new object[] { new GeoCountrySource(), GenerateTestCasesForSut(Any.GeoCountry) };
44+
}
45+
}
46+
47+
private static List<string> GenerateTestCasesForSut(Func<string> any)
48+
{
49+
var results = new List<string>();
50+
for (int i = 0; i < 10; i++)
51+
{
52+
results.Add(any());
53+
}
54+
return results;
55+
}
56+
}
57+
}

NTestDataBuilder.Tests/NTestDataBuilder.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Compile Include="DataSources\Generators\RandomGeneratorTests.cs" />
5959
<Compile Include="DataSources\Generators\SequentiaGeneratorTests.cs" />
6060
<Compile Include="DataSources\PersonSourceTests.cs" />
61+
<Compile Include="EquivalenceClasses\DictionaryEquivalenceClassesTests.cs" />
6162
<Compile Include="EquivalenceClasses\PersonEquivalenceClassesTests.cs" />
6263
<Compile Include="EquivalenceClasses\StringEquivalenceClassesTests.cs" />
6364
<Compile Include="AsProxyTests.cs" />
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
Afghanistan
2+
Åland
3+
Albania
4+
Algeria
5+
American Samoa
6+
Andorra
7+
Angola
8+
Anguilla
9+
Antarctica
10+
Antigua and Barbuda
11+
Argentina
12+
Armenia
13+
Aruba
14+
Ascension Island
15+
Australia
16+
Austria
17+
Azerbaijan
18+
Bahamas
19+
Bahrain
20+
Bangladesh
21+
Barbados
22+
Belarus
23+
Belgium
24+
Belize
25+
Benin
26+
Bermuda
27+
Bhutan
28+
Bolivia
29+
Bosnia and Herzegovina
30+
Botswana
31+
Bouvet Island
32+
Brazil
33+
British Virgin Islands
34+
British Indian Ocean Territory
35+
Brunei Darussalam
36+
Bulgaria
37+
Burkina Faso
38+
Burundi
39+
Cambodia
40+
Cameroon
41+
Canada
42+
Cape Verde
43+
Cayman Islands
44+
Central African Republic
45+
Chad
46+
Chile
47+
China
48+
Christmas Island
49+
Cocos (Keeling) Island
50+
Colombia
51+
Comoros
52+
Congo, Republic of
53+
Congo, Democratic Republic of
54+
Cook Islands
55+
Costa Rica
56+
Cote d'Ivoire
57+
Croatia
58+
Cuba
59+
Cyprus
60+
Czech Republic
61+
Denmark
62+
Djibouti
63+
Dominica
64+
Dominican Republic
65+
Ecuador
66+
Egypt
67+
El Salvador
68+
Equatorial Guinea
69+
Eritrea
70+
Estonia
71+
Ethiopia
72+
Falkland Islands (Malvinas)
73+
Faroe Islands
74+
Fiji
75+
Finland
76+
France
77+
French Guiana
78+
French Polynesia
79+
French Southern Territories
80+
Gabon
81+
Gambia
82+
Georgia
83+
Germany
84+
Ghana
85+
Gibraltar
86+
Greece
87+
Greenland
88+
Grenada
89+
Guadeloupe
90+
Guam
91+
Guatemala
92+
Guernsey
93+
Guinea
94+
Guinea-Bissau
95+
Guyana
96+
Haiti
97+
Heard and McDonald Islands
98+
Honduras
99+
Hong Kong
100+
Hungary
101+
Iceland
102+
India
103+
Indonesia
104+
Iran
105+
Iraq
106+
Ireland
107+
Isle of Man
108+
Israel
109+
Italy
110+
Jamaica
111+
Japan
112+
Jersey
113+
Jordan
114+
Kazakhstan
115+
Kenya
116+
Kiribati
117+
Korea, North
118+
Korea, South
119+
Kuwait
120+
Kyrgyzstan
121+
Laos
122+
Latvia
123+
Lebanon
124+
Lesotho
125+
Liberia
126+
Libya
127+
Liechtenstein
128+
Lithuania
129+
Luxembourg
130+
Macau
131+
Macedonia
132+
Madagascar
133+
Malawi
134+
Malaysia
135+
Maldives
136+
Mali
137+
Malta
138+
Marshall Islands
139+
Martinique
140+
Mauritania
141+
Mauritius
142+
Mayotte
143+
Mexico
144+
Micronesia
145+
Moldova
146+
Monaco
147+
Mongolia
148+
Montenegro
149+
Montserrat
150+
Morocco
151+
Mozambique
152+
Myanmar
153+
Namibia
154+
Nauru
155+
Nepal
156+
Netherlands
157+
Netherlands Antilles
158+
New Caledonia
159+
New Zealand
160+
Nicaragua
161+
Niue
162+
Niger
163+
Nigeria
164+
Norfolk Island
165+
Northern Mariana Islands
166+
Norway
167+
Oman
168+
Pakistan
169+
Palau
170+
Palestinian Territory, Occupied
171+
Panama
172+
Papua New Guinea
173+
Paraguay
174+
Peru
175+
Philippines
176+
Pitcairn Island
177+
Poland
178+
Portugal
179+
Puerto Rico
180+
Qatar
181+
Reunion
182+
Romania
183+
Russia
184+
Rwanda
185+
Saint Barthelemy
186+
Saint Helena
187+
Saint Kitts and Nevis
188+
Saint Lucia
189+
Saint Martin
190+
Saint Pierre and Miquelon
191+
Saint Vincent and the Grenadines
192+
Samoa
193+
San Marino
194+
Sao Tome and Principe
195+
Saudia Arabia
196+
Senegal
197+
Serbia
198+
Seychelles
199+
Sierra Leone
200+
Singapore
201+
Slovakia
202+
Slovenia
203+
Solomon Islands
204+
Somalia
205+
South Africa
206+
South Georgia and the South Sandwich Islands
207+
Spain
208+
Sri Lanka
209+
Sudan
210+
Suriname
211+
Svalbard and Jan Mayen Islands
212+
Swaziland
213+
Sweden
214+
Switzerland
215+
Syria
216+
Taiwan
217+
Tajikistan
218+
Tanzania
219+
Thailand
220+
Timor-Leste
221+
Togo
222+
Tokelau
223+
Tonga
224+
Trinidad and Tobago
225+
Tunisia
226+
Turkey
227+
Turkmenistan
228+
Turks and Caicos Islands
229+
Tuvalu
230+
Uganda
231+
Ukraine
232+
United Arab Emirates
233+
United Kingdom
234+
United States of America
235+
United States Virgin Islands
236+
Uruguay
237+
US Minor Outlying Islands
238+
USSR
239+
Uzbekistan
240+
Vanuatu
241+
Vatican City State (Holy See)
242+
Venezuela
243+
Vietnam
244+
Wallis and Futuna Islands
245+
Western Sahara
246+
Yemen
247+
Yugoslavia
248+
Zambia
249+
Zimbabwe
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using NTestDataBuilder.DataSources.Dictionaries;
2+
3+
namespace NTestDataBuilder.DataSources.Geography
4+
{
5+
/// <summary>
6+
/// Dictionary of continent names
7+
/// </summary>
8+
public class GeoContinentSource : FileDictionarySource
9+
{
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using NTestDataBuilder.DataSources.Dictionaries;
2+
3+
namespace NTestDataBuilder.DataSources.Geography
4+
{
5+
/// <summary>
6+
/// Dictionary of country names
7+
/// </summary>
8+
public class GeoCountrySource : FileDictionarySource
9+
{
10+
}
11+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using NTestDataBuilder.DataSources.Geography;
2+
3+
namespace NTestDataBuilder.EquivalenceClasses
4+
{
5+
/// <summary>
6+
/// Extension methods that describe equivalence classes for generating anonymous geography-related values.
7+
/// </summary>
8+
public static class GeographyEquivalenceClassescs
9+
{
10+
private static GeoContinentSource _geoContinentSource;
11+
12+
/// <summary>
13+
/// Generate and return a continent name.
14+
/// </summary>
15+
/// <param name="fixture">The fixture to generate a string for</param>
16+
/// <returns>The generated string</returns>
17+
public static string GeoContinent(this AnonymousValueFixture fixture)
18+
{
19+
if (_geoContinentSource == null) _geoContinentSource = new GeoContinentSource();
20+
return _geoContinentSource.Next();
21+
}
22+
23+
private static GeoCountrySource _geoCountrySource;
24+
25+
/// <summary>
26+
/// Generate and return a country name.
27+
/// </summary>
28+
/// <param name="fixture">The fixture to generate a string for</param>
29+
/// <returns>The generated string</returns>
30+
public static string GeoCountry(this AnonymousValueFixture fixture)
31+
{
32+
if (_geoCountrySource == null) _geoCountrySource = new GeoCountrySource();
33+
return _geoCountrySource.Next();
34+
}
35+
36+
}
37+
}

0 commit comments

Comments
 (0)