Permalink
Browse files

added test for getInitCoordsAndDir

  • Loading branch information...
riraheta committed Apr 5, 2012
1 parent 39e329b commit d99dbffb92489fe985c14e6959cf078cb7ac2b66
Showing with 11 additions and 13 deletions.
  1. +5 −3 static/js/world/world.js
  2. +6 −10 static/js/world/world_test.js
View
@@ -151,8 +151,8 @@ var world = function () {
return getPlayerPropertyById(id, "color");
}
- function getInitCoordsAndDir(i){
- var x,y,dir,retObj;
+ var getInitCoordsAndDir = function(i){
+ var x,y,dir,dirObj,retObj;
switch (i) {
case 0:
x = 0;
@@ -176,7 +176,8 @@ var world = function () {
default:
break;
}
- retObj = {pos:{x:x,y:y},newDir:getDirObj(dir),dir:getDirObj(dir)};
+ dirObj = getDirObj(dir);
+ retObj = {pos:{x:x,y:y},newDir:dirObj,dir:dirObj};
return retObj;
}
@@ -401,6 +402,7 @@ var world = function () {
setPlayerDiedCallback: setPlayerDiedCallback,
getPlayerNameById: getPlayerNameById,
getPlayerColorById: getPlayerColorById,
+ getInitCoordsAndDir: getInitCoordsAndDir,
resetGame: resetGame,
setResetGameCallback: setResetGameCallback,
getGameState: getGameState
@@ -11,12 +11,9 @@ if (typeof module !== "undefined" && module === require.main) {
var test = function(txt, testfun){
suiteExports["test: " + txt] = testfun;
- }
-
-
+ }
}
-
suite('World', function() {
test('World starts with no players', function() {
assert.equal(world.howManyPlayers(), 0);
@@ -28,10 +25,9 @@ suite('World', function() {
test('not atomic tests', function() {
assert.equal(world.howManyPlayers(), 1);
});
-
+ test('get position test', function() {
+ world.playerSpeed = 1;
+ var dir = {x:world.playerSpeed, y:0};
+ assert.deepEqual(world.getInitCoordsAndDir(0), {pos:{x:0,y:0},newDir:dir,dir:dir});
+ });
});
-
-if (typeof module !== "undefined" && module === require.main) {
-
-}
-

0 comments on commit d99dbff

Please sign in to comment.