File: test/1-crud.js

Recommend this page to a friend!
  Classes of ryan silalahi   Encyclopedia   test/1-crud.js   Download  
File: test/1-crud.js
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: Encyclopedia
Store large objects in many smaller ones
Author: By
Last change: Update of test/1-crud.js
Date: 3 years ago
Size: 1,092 bytes
 

Contents

Class file image Download
var enc = require('./..'); var k = 'foo', v = 'bar'; exports["set & get"] = function(test){ var data = enc(); data.set(k, v); test.equal(data.get(k), v); data.set(k, v + 'make it invalid'); test.notEqual(data.get(k), v); test.done(); } exports["has & unset"] = function(test){ var data = enc(); data.set(k, v); test.ok(data.has(k)); data.unset(k); test.notEqual(data.get(k), v); test.ok(! data.has(k)); test.done(); } exports["walk"] = function(test){ var data = enc(); var max = 10; for(var i = 0; i < max; i++){ data.set(i, i); } var all_good = true; var i = 0; data.walk(function(k, v){ i++; // we put k = v, lets check it if(k != v){ all_good = false; } }); test.ok(all_good); test.equal(i, max); test.done(); } exports["walk interupt"] = function(test){ var data = enc(); var max = 10; for(var i = 0; i < max; i++){ data.set(i, i); } var interupt_on = 5; var i = 0; data.walk(function(k, v){ i++; if (i == interupt_on){ return false; } }); test.equal(i, interupt_on); test.done(); }