Skip to content

Commit

Permalink
Merge branch 'refs/heads/allow-zero-speed-fix-106'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelshmitty committed Nov 25, 2014
2 parents f1b48cd + d57b40a commit 795ad23
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ var pcmdOptions = [

pcmdOptions.forEach(function(pair) {
Client.prototype[pair[0]] = function(speed) {
if (!speed) {
if (isNaN(speed)) {
return;
}
speed = parseFloat(speed);
Expand All @@ -281,7 +281,7 @@ pcmdOptions.forEach(function(pair) {
};

Client.prototype[pair[1]] = function(speed) {
if (!speed) {
if (isNaN(speed)) {
return;
}

Expand Down
36 changes: 35 additions & 1 deletion test/unit/test-Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,48 @@ test('Client', {
assert.equal(this.client._pcmd.clockwise, undefined);
},

'pcmd methods conver strings to floats': function() {
'pcmd methods convert strings to floats': function() {
this.client.up('-0.5');
assert.strictEqual(this.client._pcmd.up, -0.5);

this.client.down('-0.5');
assert.strictEqual(this.client._pcmd.down, -0.5);
},

'pcmd methods accept 0 as speed': function() {
this.client.up(0);
assert.equal(this.client._pcmd.up, 0);
assert.equal(this.client._pcmd.down, undefined);

this.client.down(0);
assert.equal(this.client._pcmd.down, 0);
assert.equal(this.client._pcmd.up, undefined);

this.client.left(0);
assert.equal(this.client._pcmd.left, 0);
assert.equal(this.client._pcmd.right, undefined);

this.client.right(0);
assert.equal(this.client._pcmd.right, 0);
assert.equal(this.client._pcmd.left, undefined);

this.client.front(0);
assert.equal(this.client._pcmd.front, 0);
assert.equal(this.client._pcmd.back, undefined);

this.client.back(0);
assert.equal(this.client._pcmd.back, 0);
assert.equal(this.client._pcmd.front, undefined);

this.client.clockwise(0);
assert.equal(this.client._pcmd.clockwise, 0);
assert.equal(this.client._pcmd.counterClockwise, undefined);

this.client.counterClockwise(0);
assert.equal(this.client._pcmd.counterClockwise, 0);
assert.equal(this.client._pcmd.clockwise, undefined);
},

'pcmd checks if argument exists': function() {
// check that running without commands does not modify _pcmd state
this.client.up(0.5);
Expand Down

0 comments on commit 795ad23

Please sign in to comment.