Skip to content

Commit 2b40aa3

Browse files
committed
add expresso test; fix bugs in trueOrFalse, stringOfNumbers
1 parent d73a7ab commit 2b40aa3

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

Cakefile

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ task 'build', 'Build JS files', ->
1010
task 'spec', 'Run Jasmine specs', ->
1111
exec 'jasmine-node spec', show_output
1212

13+
task 'test', 'Run Jasmine specs', ->
14+
exec 'expresso test', show_output
15+
1316
task 'clean', 'Removes .js files created from build task', ->
1417
exec 'rm -rf lib', show_output
1518

src/RandomData.coffee

+5-3
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ random.element = (array) ->
6969

7070
# Randomly returns `true` or `false`.
7171
random.trueOrFalse = ->
72-
random.number(2) is 1 ? true : false
73-
72+
if random.number(2) is 1
73+
true
74+
else
75+
false
7476

7577
##### Strings
7678

@@ -80,7 +82,7 @@ random.string = (length = 16) ->
8082

8183
# Generates a random string of digits of given length.
8284
random.stringOfNumbers = (n) ->
83-
(i for i in [1..n]).join("") # TODO: use util.format in node.js 0.5.x
85+
(random.number(i) for i in [1..n]).join("")
8486

8587

8688
##### Names

test/RandomData.test.coffee

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
random = require '../lib/RandomData'
2+
assert = require 'assert'
3+
4+
# Mock out random number function to make tests deterministic:
5+
random.number = (n) -> 1
6+
7+
module.exports =
8+
'generates boolean values': ->
9+
assert.equal true, random.trueOrFalse()
10+
11+
'generates random strings of specified lengths': ->
12+
assert.equal '', random.string(0)
13+
assert.equal 'B', random.string(1)
14+
assert.equal 'BB', random.string(2)
15+
assert.equal 'BBB', random.string(3)
16+
17+
'generates random string with default length of 16': ->
18+
assert.equal 'BBBBBBBBBBBBBBBB', random.string()
19+
20+
# Person names
21+
'generates random female first names': ->
22+
assert.equal 'Ann', random.femaleFirstName()
23+
24+
'genrates random male first names': ->
25+
assert.equal 'Anthony', random.maleFirstName()
26+
27+
'genrates random first names': ->
28+
assert.equal 'Ann', random.firstName()
29+
30+
'generates random last names': ->
31+
assert.equal 'Anderson', random.lastName()
32+
33+
'generates random middle initials': ->
34+
assert.equal 'B', random.middleInitial()
35+
36+
# Locations
37+
'generates random address line 1 values': ->
38+
assert.equal '2 Beech Ave', random.addressLine1()
39+
40+
'generates random address line 2 values': ->
41+
assert.equal 'Bsmt 2', random.addressLine2()
42+
43+
'generates random cities': ->
44+
assert.equal 'Mount Pleasant', random.city()
45+
46+
'should generate random US state abbreviation': ->
47+
assert.equal 'AL', random.usStateAbbreviation()
48+
49+
'generates random US state full name': ->
50+
assert.equal 'Alabama', random.usStateName()
51+
52+
'generates random US 5 digit zip codes': ->
53+
assert.equal '11111', random.usZipShort()
54+
55+
'generates random US 9 digit zip codes': ->
56+
assert.equal '11111-1111', random.usZipLong()
57+
58+
'generates random countries': ->
59+
assert.equal 'Albania', random.country()
60+
61+
'generates random international phone numbers': ->
62+
assert.equal '011-2-11-1001', random.internationalPhone()
63+
64+
65+

0 commit comments

Comments
 (0)