From f214b4b7f8683db57d53ca12dde40650473d2b90 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Sat, 11 Jul 2015 12:57:49 +0100 Subject: [PATCH] Create josecelano --- josecelano | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 josecelano 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); + }); + + +});