Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Converted test_distribution.js to use expresso and should.js. Added M…

…akefile for doing make test.
  • Loading branch information...
commit 75571ea58d4e86e543156b5f2ceae61fac9a3d77 1 parent 25a001d
@bnoguchi authored
Showing with 42 additions and 20 deletions.
  1. +7 −0 Makefile
  2. +19 −15 package.json
  3. +16 −5 test/test_distribution.js
View
7 Makefile
@@ -0,0 +1,7 @@
+TESTS = 'test/test_distribution.js'
+
+test:
+ @NODE_ENV=test expresso \
+ $(TESTS)
+
+.PHONY: test
View
34 package.json
@@ -1,18 +1,22 @@
{
- "name" : "hash_ring"
-, "version" : "0.1.1"
-, "description" : "Consistent hashing C++ Add-on for node.js"
-, "keywords": [ "node", "hash ring", "consistent hashing", "sharding", "distributed" ]
-, "author": "Brian Noguchi <brian.noguchi@gmail.com>"
-, "contributors": [
+ "name" : "hash_ring",
+ "version" : "0.1.1",
+ "description" : "Consistent hashing C++ Add-on for node.js",
+ "keywords": [ "node", "hash ring", "consistent hashing", "sharding", "distributed" ],
+ "author": "Brian Noguchi <brian.noguchi@gmail.com>",
+ "contributors": [
{ "name": "Brian Noguchi", "web": "http://ngchi.wordpress.com" }
- ]
-, "licenses": [ "MIT" ]
-, "main": "./index.js"
-, "repository": {
- "type": "git"
- , "url": "https://github.com/bnoguchi/node-hash-ring"
- }
-, "bugs": { "web": "http://github.com/bnoguchi/node-hash-ring/issues" }
-, "engines": { "node": ">=0.2.0" }
+ ],
+ "licenses": [ "MIT" ],
+ "main": "./index.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/bnoguchi/node-hash-ring.git"
+ },
+ "devDependencies": {
+ "expresso": ">=0.7.6",
+ "should": ">=0.2.0"
+ },
+ "bugs": { "web": "https://github.com/bnoguchi/node-hash-ring/issues" },
+ "engines": { "node": "0.4.x" }
}
View
21 test/test_distribution.js
@@ -1,6 +1,6 @@
-var sys = require("sys");
+var should = require('should');
-var HashRing = require("../lib/hash_ring");
+var HashRing = require("../index");
var nodes = {
"127.0.0.1:8080": 1,
@@ -24,6 +24,12 @@ var genCode = function (length) {
};
var randomDistribution = function () {
+};
+
+randomDistribution();
+
+module.exports = {
+ 'should be randomly distributed': function () {
var counts = {},
node, i, len, word;
for (i = 0, len = nodes.length; i < len; i++) {
@@ -36,9 +42,14 @@ var randomDistribution = function () {
counts[node] = counts[node] || 0;
counts[node]++;
}
+ var total = Object.keys(counts).reduce( function (sum, node) {
+ return sum += counts[node];
+ }, 0.0);
+ var delta = 0.05
+ , lower = 1.0 / 3 - 0.05
+ , upper = 1.0 / 3 + 0.05;
for (node in counts) {
- sys.log(node + ": " + counts[node]);
+ (counts[node] / total).should.be.within(lower, upper);
}
+ }
};
-
-randomDistribution();
Please sign in to comment.
Something went wrong with that request. Please try again.