Skip to content

Commit

Permalink
feat(randomcounty, randomconstituency): Added Constituencies to the p…
Browse files Browse the repository at this point in the history
…roject, link to eact respective

closes #2
  • Loading branch information
gaithoben committed Dec 29, 2017
1 parent ca1e9f4 commit b326090
Show file tree
Hide file tree
Showing 5 changed files with 3,568 additions and 3 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"mocha": "4.0.1",
"semantic-release": "^11.0.2"
},
"czConfig": {
"path": "cz-conventional-changelog"
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
}
}
31 changes: 30 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
var counties = require('./json/counties.json');
var constituencies = require('./json/constituencies.json');
var uniqueRandomArray = require('unique-random-array');

module.exports = {
counties: counties,
randomcounty: uniqueRandomArray(counties),
randomcounty: randomcounty,
constituencies: constituencies,
randomconstituency: randomconstituency,
};

function randomcounty(number) {
var arr = uniqueRandomArray(counties);
if (number === undefined) {
return arr();
} else {
var randomitems = [];
for (var i = 0; i < number; i++) {
randomitems.push(arr());
}
return randomitems;
}
}

function randomconstituency(number) {
var arr = uniqueRandomArray(constituencies);
if (number === undefined) {
return arr();
} else {
var randomitems = [];
for (var i = 0; i < number; i++) {
randomitems.push(arr());
}
return randomitems;
}
}
36 changes: 36 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,41 @@ describe('Counties List', function() {
var randomcounty = kenya.randomcounty();
expect(kenya.counties).to.include(randomcounty);
});

it('Should return an array of random Counties if passed a number', function() {
var randomcounties = kenya.randomcounty(3);
expect(randomcounties).to.have.length(3);
randomcounties.forEach(function(item) {
expect(kenya.counties).to.include(item);
});
});
});
});

describe('Constituencies List', function() {
describe('constituencies', function() {
it('Should be an array of objects', function() {
expect(kenya.constituencies).to.satisfy(arraOfObjects);

function arraOfObjects(args) {
return typeof args === 'object';
}
});
});

describe('Random constituency', function() {
it('Should return a random constituency from the list of all constituencies', function() {
var randomconstituency = kenya.randomconstituency();
console.log('CONSTITUENCY', randomconstituency);
expect(kenya.constituencies).to.include(randomconstituency);
});

it('Should return an array of random items if passed a number', function() {
var randomconstituencies = kenya.randomconstituency(3);
expect(randomconstituencies).to.have.length(3);
randomconstituencies.forEach(function(item) {
expect(kenya.constituencies).to.include(item);
});
});
});
});
Loading

0 comments on commit b326090

Please sign in to comment.