-
Notifications
You must be signed in to change notification settings - Fork 453
/
test.address.js
254 lines (215 loc) · 9.93 KB
/
test.address.js
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
define(['Chance', 'mocha', 'chai', 'underscore'], function (Chance, mocha, chai, _) {
var assert = chai.assert,
expect = chai.expect;
describe("Address", function () {
var zip, suffix, suffixes, state, address, phone, coordinates, chance = new Chance();
describe("Zip", function () {
it("returns a valid basic zip code", function () {
_(1000).times(function () {
zip = chance.zip();
expect(zip.length).to.equal(5);
expect(/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(zip)).to.be.true;
});
});
it("returns a valid zip+4 code", function () {
_(1000).times(function () {
zip = chance.zip({plusfour: true});
expect(zip.length).to.equal(10);
expect(/(^\d{5}$)|(^\d{5}-\d{4}$)/.test(zip)).to.be.true;
});
});
});
describe("Street", function () {
it("street suffixes returns the suffix array", function () {
suffixes = chance.street_suffixes();
expect(suffixes).to.be.an('array');
_.each(suffixes, function (suffix) {
expect(suffix).to.have.keys('name', 'abbreviation');
});
});
it("street suffixes are short", function () {
suffixes = chance.street_suffixes();
_.each(suffixes, function (suffix) {
expect(suffix.abbreviation).to.have.length.below(5);
});
});
it("full street suffixes are longish", function () {
suffixes = chance.street_suffixes();
_.each(suffixes, function (suffix) {
expect(suffix.name).to.have.length.above(2);
});
});
it("street suffix returns a single suffix", function () {
_(1000).times(function () {
suffix = chance.street_suffix();
expect(suffix).to.be.an('object');
expect(suffix.name).to.be.a('string');
expect(suffix.abbreviation).to.be.a('string');
});
});
});
describe("State", function () {
it("states() returns an array of states", function () {
expect(chance.states()).to.be.an('array');
});
it("state() returns a random (short) state name", function () {
_(1000).times(function () {
state = chance.state();
expect(state.length).to.be.below(3);
});
});
it("state({full: true}) returns a random (long) state name", function () {
_(1000).times(function () {
state = chance.state({full: true});
expect(state.length).to.be.above(2);
});
});
it("states() returns all 50 US States and DC", function () {
expect(chance.states()).to.have.length(51);
});
it("states({territories: true}) returns 50 US States, DC, and 7 US Territories", function () {
expect(chance.states({territories: true})).to.have.length(58);
});
it("states({armed_forces: true}) returns 50 US States, DC, and 3 Armed Forces Military States", function () {
expect(chance.states({armed_forces: true})).to.have.length(54);
});
it("states({territories: true, armed_forces: true}) returns 50 US States, DC, 7 US Territories, and 3 Armed Forces Military States", function () {
expect(chance.states({territories: true, armed_forces: true})).to.have.length(61);
});
});
describe("Province", function () {
it("provinces() returns an array of provinces", function () {
expect(chance.provinces()).to.be.an('array');
});
it("province() returns a random (short) province name", function () {
_(1000).times(function () {
expect(chance.province()).to.have.length.below(3);
});
});
it("province({full: true}) returns a random (long) province name", function () {
_(1000).times(function () {
expect(chance.province({full: true})).to.have.length.above(2);
});
});
});
describe("Address", function () {
it("address() returns a string", function () {
expect(chance.address()).to.be.an('string');
});
it("address() starts with a number", function () {
_(1000).times(function () {
expect(chance.address()).to.match(/[0-9]+.+/);
});
});
it("address() can take short_suffix arg and obey it", function () {
_(1000).times(function () {
address = chance.address({short_suffix: true});
expect(address.split(' ')[2].length).to.be.below(5);
});
});
});
describe("Phone Number", function () {
it("areacode() looks right", function () {
expect(chance.areacode()).to.be.a('string');
_(1000).times(function () {
expect(chance.areacode()).to.match(/^\(([2-9][0-8][0-9])\)$/);
});
});
it("areacode({parens: false}) looks right", function () {
_(1000).times(function () {
expect(chance.areacode({parens: false})).to.be.a('string');
expect(chance.areacode({parens: false})).to.match(/^([2-9][0-8][0-9])$/);
});
});
it("phone() returns a string", function () {
expect(chance.phone()).to.be.a('string');
});
it("phone() looks like an actual phone number", function () {
_(1000).times(function () {
expect(chance.phone()).to.match(/^\(([2-9][0-8][0-9])\)?[\-. ]?([2-9][0-9]{2,2})[\-. ]?([0-9]{4,4})$/);
});
});
it('phone({formatted: false}) looks right', function () {
_(1000).times(function () {
expect(chance.phone({formatted : false})).to.be.a('string');
expect(chance.phone({formatted : false})).to.match(/^[2-9][0-8]\d[2-9]\d{6,6}$/);
});
});
it('phone({formatted: false, parens: true}) is unformatted', function () {
_(1000).times(function () {
expect(chance.phone({formatted : false, parens: true})).to.be.a('string');
expect(chance.phone({formatted : false, parens: true})).to.match(/^[2-9][0-8]\d[2-9]\d{6,6}$/);
});
});
});
describe("City", function () {
it("city() looks right", function () {
expect(chance.city()).to.be.a('string');
});
});
describe("Latitude", function () {
it("latitude() looks right", function () {
expect(chance.latitude()).to.be.a('number');
});
it("latitude() is in the right range", function () {
_(1000).times(function () {
expect(chance.latitude()).to.be.within(-90, 90);
});
});
it("latitude() will accept a min and obey it", function () {
_(1000).times(function () {
var min = chance.floating({min: -90, max: 90});
expect(chance.latitude({min: min})).to.be.within(min, 90);
});
});
it("latitude() will accept a max and obey it", function () {
_(1000).times(function () {
var max = chance.floating({min: -90, max: 90});
expect(chance.latitude({max: max})).to.be.within(-90, max);
});
});
});
describe("Longitude", function () {
it("longitude() looks right", function () {
expect(chance.longitude()).to.be.a('number');
});
it("longitude() is in the right range", function () {
_(1000).times(function () {
expect(chance.longitude()).to.be.within(-180, 180);
});
});
it("longitude() will accept a min and obey it", function () {
_(1000).times(function () {
var min = chance.floating({min: -180, max: 180});
expect(chance.longitude({min: min})).to.be.within(min, 180);
});
});
it("longitude() will accept a max and obey it", function () {
_(1000).times(function () {
var max = chance.floating({min: -180, max: 180});
expect(chance.longitude({max: max})).to.be.within(-180, max);
});
});
});
describe("Geohash", function () {
it("geohash() looks right", function() {
expect(chance.geohash()).to.be.a('string');
expect(chance.geohash()).to.have.length(7);
});
it("geohash() will accept a length and obey it", function() {
_(1000).times(function () {
var length = chance.d10();
expect(chance.geohash({ length: length })).to.have.length(length);
});
});
});
describe("Coordinates", function () {
it("coordinates() looks about right", function () {
_(1000).times(function () {
expect(chance.coordinates()).to.be.a('string');
expect(chance.coordinates().split(',')).to.have.length(2);
});
});
});
});
});