diff --git a/josecelano b/josecelano new file mode 100644 index 0000000..e9b74b3 --- /dev/null +++ b/josecelano @@ -0,0 +1,59 @@ +/*global describe, it, before */ + +"use strict"; + +var buster = require("buster"); +var RUList = require("../lib/RUList"); + +buster.spec.expose(); +var expect = buster.expect; + +describe("Recently-Used List", function() { + before(function() { + this.list = new RUList(); + }); + + it("is initially empty", function() { + expect(this.list.length).toEqual(0); + }); + + it("adds items in reverse order", function() { + this.list.add('one'); + this.list.add('two'); + + expect(this.list.get(0)).toEqual('two'); + }); + + it("an item exists only once", function() { + this.list.add('one'); + this.list.add('one'); + + expect(this.list.length).toEqual(1); + }); + + it("items count always less than eleven", function() { + for(var i = 1; i < 12; i++) { + this.list.add(i); + } + + expect(this.list.length).toEqual(10); + }); + + it("new element replaces last when list is full", function() { + for(var i = 1; i <= 11; i++) { + this.list.add(i); + } + + expect(this.list.get(0)).toEqual(11); + }); + + it("last element disappears when list is full", function() { + for(var i = 1; i <= 11; i++) { + this.list.add(i); + } + + expect(this.list.get(9)).toEqual(2); + }); + + +});