Skip to content

Commit

Permalink
Added good tests using mocha test framework. Updates on README.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidemiceli committed Aug 5, 2016
1 parent d945284 commit 62fb713
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Gender Detection

## Description
A node.js module to determine a person's gender based on his/her first name.
It works also for many languages other than english.
A node.js module to determine a person's gender based on his/her first name.
It works also for many languages other than english. It support international names.
This module is able to clean the text detecting gender from dirty or unclear names.

## Installation

Expand All @@ -26,4 +27,17 @@ g = gender.detect('Holly');

g = gender.detect('GhJGhgj')
// "unknown"

// It works also with unclean or dirty names:
g = gender.detect('BiLL$...');
// "male"

g = gender.detect('::Jenni♥fer::');
// "female"
```

### Tests

In case you want to run some tests, please install the test framework Mocha (https://mochajs.org)
After installing it, on the parent directory type: `mocha test`.
The test directory is obviously `/test`.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gender-detection",
"version": "0.0.3",
"version": "0.0.4",
"description": "Detect the gender of a person using his/her first name.",
"license": "GPL-3.0",
"main": "index.js",
Expand Down Expand Up @@ -28,6 +28,6 @@
"test": "test"
},
"scripts": {
"test": "node test/test.js"
"test": "mocha test"
}
}
33 changes: 26 additions & 7 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
/*
* If you want run tests please install the test framework Mocha (https://mochajs.org).
* Then type the command on the parent folder: mocha test
*/

// Require assert mocha
var assert = require('assert');

// Require gender detection module
var gender = require('../index.js');

// Use it to detect the gender:
g = gender.detect('Tim Johnson');
console.log(g);
describe('Simple names', function() {
it('It should return male, female, or unknown', function() {
assert.equal('male', gender.detect('John'));
assert.equal('female', gender.detect('Holly'));
});
});

g = gender.detect('Holly');
console.log(g);
describe('Double names', function() {
it('It should return male, female, or unknown', function() {
assert.equal('male', gender.detect('Tim Johnson'));
assert.equal('female', gender.detect('Francesca Rossi'));
});
});

g = gender.detect('GhJGhgj');
console.log(g);
describe('Bad formatted names', function() {
it('It should return male, female, or unknown', function() {
assert.equal('male', gender.detect('BiLL$...'));
assert.equal('female', gender.detect('::Jenni♥fer::'));
});
});

0 comments on commit 62fb713

Please sign in to comment.