Skip to content

Commit

Permalink
renaming array_rand to array_element
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanDonovan committed Jan 7, 2013
1 parent f19d2ab commit e483b72
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions lib/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var definitions = require('../lib/definitions');

var address = {
zipCode: function () {
return Helpers.replaceSymbolWithNumber(Faker.random.array_rand(["#####", '#####-####']));
return Helpers.replaceSymbolWithNumber(Faker.random.array_element(["#####", '#####-####']));
},

zipCodeFormat: function (format) {
Expand Down Expand Up @@ -54,7 +54,7 @@ var address = {
},

secondaryAddress: function () {
return Helpers.replaceSymbolWithNumber(Faker.random.array_rand(
return Helpers.replaceSymbolWithNumber(Faker.random.array_element(
[
'Apt. ###',
'Suite ###'
Expand Down
2 changes: 1 addition & 1 deletion lib/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var company = {
},

companySuffix: function () {
return Faker.random.array_rand(this.suffixes());
return Faker.random.array_element(this.suffixes());
},

catchPhrase: function () {
Expand Down
2 changes: 1 addition & 1 deletion lib/internet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var internet = {
case 0:
return Faker.random.first_name();
case 1:
return Faker.random.first_name() + Faker.random.array_rand([".", "_"]) + Faker.random.last_name();
return Faker.random.first_name() + Faker.random.array_element([".", "_"]) + Faker.random.last_name();
}
},

Expand Down
44 changes: 22 additions & 22 deletions lib/random.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,93 @@ var random = {
},

// takes an array and returns the array randomly sorted
array_rand: function (array) {
array_element: function (array) {
var r = Math.floor(Math.random() * array.length);
return array[r];
},

city_prefix: function () {
return this.array_rand(definitions.city_prefix());
return this.array_element(definitions.city_prefix());
},

city_suffix: function () {
return this.array_rand(definitions.city_suffix());
return this.array_element(definitions.city_suffix());
},

street_suffix: function () {
return this.array_rand(definitions.street_suffix());
return this.array_element(definitions.street_suffix());
},

br_state: function () {
return this.array_rand(definitions.br_state());
return this.array_element(definitions.br_state());
},

br_state_abbr: function () {
return this.array_rand(definitions.br_state_abbr());
return this.array_element(definitions.br_state_abbr());
},

us_state: function () {
return this.array_rand(definitions.us_state());
return this.array_element(definitions.us_state());
},

us_state_abbr: function () {
return this.array_rand(definitions.us_state_abbr());
return this.array_element(definitions.us_state_abbr());
},

uk_county: function () {
return this.array_rand(definitions.uk_county());
return this.array_element(definitions.uk_county());
},

uk_country: function () {
return this.array_rand(definitions.uk_country());
return this.array_element(definitions.uk_country());
},

first_name: function () {
return this.array_rand(definitions.first_name());
return this.array_element(definitions.first_name());
},

last_name: function () {
return this.array_rand(definitions.last_name());
return this.array_element(definitions.last_name());
},

name_prefix: function () {
return this.array_rand(definitions.name_prefix());
return this.array_element(definitions.name_prefix());
},

name_suffix: function () {
return this.array_rand(definitions.name_suffix());
return this.array_element(definitions.name_suffix());
},

catch_phrase_adjective: function () {
return this.array_rand(definitions.catch_phrase_adjective());
return this.array_element(definitions.catch_phrase_adjective());
},

catch_phrase_descriptor: function () {
return this.array_rand(definitions.catch_phrase_descriptor());
return this.array_element(definitions.catch_phrase_descriptor());
},

catch_phrase_noun: function () {
return this.array_rand(definitions.catch_phrase_noun());
return this.array_element(definitions.catch_phrase_noun());
},

bs_adjective: function () {
return this.array_rand(definitions.bs_adjective());
return this.array_element(definitions.bs_adjective());
},

bs_buzz: function () {
return this.array_rand(definitions.bs_buzz());
return this.array_element(definitions.bs_buzz());
},

bs_noun: function () {
return this.array_rand(definitions.bs_noun());
return this.array_element(definitions.bs_noun());
},

phone_formats: function () {
return this.array_rand(definitions.phone_formats());
return this.array_element(definitions.phone_formats());
},

domain_suffix: function () {
return this.array_rand(definitions.domain_suffix());
return this.array_element(definitions.domain_suffix());
}

};
Expand Down
6 changes: 3 additions & 3 deletions test/address.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe("address.js", function () {

describe("secondaryAddress()", function () {
it("randomly chooses an Apt or Suite number", function () {
sinon.spy(Faker.random, 'array_rand');
sinon.spy(Faker.random, 'array_element');

var address = Faker.Address.secondaryAddress();

Expand All @@ -170,8 +170,8 @@ describe("address.js", function () {
];

assert.ok(address);
assert.ok(Faker.random.array_rand.calledWith(expected_array));
Faker.random.array_rand.restore();
assert.ok(Faker.random.array_element.calledWith(expected_array));
Faker.random.array_element.restore();
});
});

Expand Down
12 changes: 6 additions & 6 deletions test/company.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ describe("company.js", function () {

describe("catchPhrase()", function () {
it("returns phrase comprising of a catch phrase adjective, descriptor, and noun", function () {
sinon.spy(Faker.random, 'array_rand');
sinon.spy(Faker.random, 'array_element');
sinon.spy(Faker.random, 'catch_phrase_adjective');
sinon.spy(Faker.random, 'catch_phrase_descriptor');
sinon.spy(Faker.random, 'catch_phrase_noun');
var phrase = Faker.Company.catchPhrase();

assert.ok(phrase.split(' ').length >= 3);
assert.ok(Faker.random.array_rand.calledThrice);
assert.ok(Faker.random.array_element.calledThrice);
assert.ok(Faker.random.catch_phrase_adjective.calledOnce);
assert.ok(Faker.random.catch_phrase_descriptor.calledOnce);
assert.ok(Faker.random.catch_phrase_noun.calledOnce);

Faker.random.array_rand.restore();
Faker.random.array_element.restore();
Faker.random.catch_phrase_adjective.restore();
Faker.random.catch_phrase_descriptor.restore();
Faker.random.catch_phrase_noun.restore();
Expand All @@ -88,19 +88,19 @@ describe("company.js", function () {

describe("bs()", function () {
it("returns phrase comprising of a BS adjective, buzz, and noun", function () {
sinon.spy(Faker.random, 'array_rand');
sinon.spy(Faker.random, 'array_element');
sinon.spy(Faker.random, 'bs_adjective');
sinon.spy(Faker.random, 'bs_buzz');
sinon.spy(Faker.random, 'bs_noun');
var bs = Faker.Company.bs();

assert.ok(typeof bs === 'string');
assert.ok(Faker.random.array_rand.calledThrice);
assert.ok(Faker.random.array_element.calledThrice);
assert.ok(Faker.random.bs_adjective.calledOnce);
assert.ok(Faker.random.bs_buzz.calledOnce);
assert.ok(Faker.random.bs_noun.calledOnce);

Faker.random.array_rand.restore();
Faker.random.array_element.restore();
Faker.random.bs_adjective.restore();
Faker.random.bs_buzz.restore();
Faker.random.bs_noun.restore();
Expand Down
4 changes: 2 additions & 2 deletions test/internet.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ describe("internet.js", function () {
sinon.stub(Faker.random, 'number').returns(1);
sinon.spy(Faker.random, 'first_name');
sinon.spy(Faker.random, 'last_name');
sinon.spy(Faker.random, 'array_rand');
sinon.spy(Faker.random, 'array_element');
var username = Faker.Internet.userName();

assert.ok(username);
assert.ok(Faker.random.first_name.called);
assert.ok(Faker.random.last_name.called);
assert.ok(Faker.random.array_rand.calledWith(['.', '_']));
assert.ok(Faker.random.array_element.calledWith(['.', '_']));

Faker.random.number.restore();
Faker.random.first_name.restore();
Expand Down

0 comments on commit e483b72

Please sign in to comment.