Skip to content

Commit

Permalink
Adding better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bahamas10 committed Jun 22, 2012
1 parent f69db1f commit 43bbaeb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
5 changes: 1 addition & 4 deletions package.json
Expand Up @@ -8,14 +8,11 @@
"url": "git://github.com/bahamas10/node-random-mac.git"
},
"scripts": {
"test": "tap tests/*.js"
"test": "node tests/random-mac.js"
},
"main": "index.js",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"tap": "~0.2.5"
},
"bin": {
"random-mac": "./bin/random-mac.js"
},
Expand Down
25 changes: 19 additions & 6 deletions tests/random-mac.js
@@ -1,9 +1,22 @@
#!/usr/bin/env node
var randomMac = require('../index'),
test = require('tap').test;
assert = require('assert'),
mac_regex = /^([a-fA-F0-9]{2}:){5}[0-9a-fA-F]{2}$/,
mac_length = 17,
mac1 = randomMac(),
mac2 = randomMac('00:11:22'),
mac3 = randomMac('wrong');

test('Ensure Length', function(t) {
var mac = randomMac();
t.equal(mac.length, 17, 'Mac Address is 17 Characters');
t.end();
});
console.log('Testing correct length');
assert.equal(mac1.length, mac_length);
assert.equal(mac2.length, mac_length);

console.log('Testing correct regex');
assert.ok(mac1.match(mac_regex));
assert.ok(mac2.match(mac_regex));

console.log('Testing incorrect length');
assert.notEqual(mac3.length, mac_length);

console.log('Testing incorrect regex');
assert.equal(mac3.match(mac_regex), null);

0 comments on commit 43bbaeb

Please sign in to comment.