Skip to content

Commit

Permalink
added piece creation
Browse files Browse the repository at this point in the history
  • Loading branch information
maleck13 committed Mar 18, 2012
1 parent 2e5140b commit da8e8aa
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
26 changes: 26 additions & 0 deletions server/models/king.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Created by JetBrains WebStorm.
* User: craigbrookes
* Date: 18/03/2012
* Time: 11:33
* To change this template use File | Settings | File Templates.
*/
var piece = require('./piece');
var util = require('util');

function King (opts) {
piece.Piece.apply(this,[opts]); //equiv of calling super(opts)
};

util.inherits(King,piece.Piece); //extend inherit from piece


//override of take method

King.prototype.take = function (){
console.log("king taking");
}

//add king only methods

exports.King = King;
27 changes: 27 additions & 0 deletions test/test_piece_createion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Created by JetBrains WebStorm.
* User: craigbrookes
* Date: 18/03/2012
* Time: 11:41
* To change this template use File | Settings | File Templates.
*/
var assert = require('assert');
var piece = require('../server/models/piece.js');
var king = require('../server/models/king.js');

describe("normal piece creation", function () {
it("should create a normal piece with type man", function () {
var redpiece = new piece.Piece({side:'red'});
console.log(redpiece.toString());
assert.equal("red",redpiece.side);
assert.equal('man', redpiece.type);
});
});

describe("king peice creation inherits piece", function () {
it("should create a king that inherits methods from piece", function () {
var aking = new king.King({side:'red'});
assert.equal("red",aking.side); //test inherited property
assert(true,aking.hasOwnProperty('take'));
});
});

0 comments on commit da8e8aa

Please sign in to comment.