Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ class House {
this.name = nameString;
this.rooms = [];
}

addRoom(room) {
this.rooms.push(room);
return this;
}

area() {
return this.rooms.reduce((acc, e) => {
return acc + e.area();
}, 0);
}

}


Expand All @@ -22,6 +24,8 @@ class Room {
// super(options);
let { width, length } = options;
if (!width || !length) { throw new Error("Missing params"); }
if (width < 0 || length < 0) { throw new Error("Dimensions outside range"); }

this.length = length;
this.width = width;
}
Expand Down Expand Up @@ -56,6 +60,13 @@ describe("House", () => {
expect( () => { new Room }).to.throw("Missing params");
});

it("throws an error if a dimension is negative", () => {

expect(() => {
let room1 = new Room({width: -7, length: 8});
}).to.throw("Dimensions outside range");
});

it("accepts width and length arguments", () => {
let room1 = new Room({ width: 7, length: 8 });
let room2 = new Room({ width: 5, length: 15 });
Expand Down Expand Up @@ -92,7 +103,8 @@ describe("House", () => {
expect(house1.area()).to.equal(131)
expect(house2.area()).to.equal(88);
});

});


});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"chai": "^3.2.0"
"chai": "^3.2.0",
"mocha": "^2.3.1"
}
}