Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUlist-test.js josecelano #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions josecelano
Original file line number Diff line number Diff line change
@@ -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);
});


});