Skip to content

Commit

Permalink
Tests: minor corrections to float values (for Float32 improvements)
Browse files Browse the repository at this point in the history
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information
rwaldron committed Jul 21, 2016
1 parent 71ac3aa commit a4faac1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions lib/esc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var Pins = Board.Pins;
var Emitter = require("events").EventEmitter;
var util = require("util");
var Collection = require("./mixins/collection");
var __ = require("./fn");
var Fn = require("./fn");

var priv = new Map();

Expand Down Expand Up @@ -88,9 +88,9 @@ var Devices = {
dir: {
value: function(speed, dir) {
if (dir.name === "forward") {
return this.speed(__.fscale(speed, 0, 100, this.neutral, this.range[1]));
return this.speed(Fn.fscale(speed, 0, 100, this.neutral, this.range[1]));
} else {
return this.speed(__.fscale(speed, 0, 100, this.neutral, this.range[0]));
return this.speed(Fn.fscale(speed, 0, 100, this.neutral, this.range[0]));
}
}
}
Expand All @@ -114,9 +114,9 @@ var Devices = {
*/

if (dir.name === "forward") {
this.speed(__.fscale(speed, 0, 100, this.neutral, this.range[1]));
this.speed(Fn.fscale(speed, 0, 100, this.neutral, this.range[1]));
} else {
this.speed(__.fscale(speed, 0, 100, this.neutral, this.range[0]));
this.speed(Fn.fscale(speed, 0, 100, this.neutral, this.range[0]));
}
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ ESC.prototype.speed = function(speed) {
var steps = 0;
var lspeed, hspeed;

speed = __.constrain(speed, this.range[0], this.range[1]);
speed = Fn.constrain(speed, this.range[0], this.range[1]);

if (this.interval) {
// Bail out if speed is the same as whatever was
Expand Down Expand Up @@ -296,7 +296,7 @@ ESC.prototype.speed = function(speed) {
}

if (noInterval) {
this.write(this.pin, __.fscale(speed, 0, 100, 0, 180));
this.write(this.pin, Fn.fscale(speed, 0, 100, 0, 180));

history.push({
timestamp: Date.now(),
Expand Down Expand Up @@ -398,7 +398,7 @@ ESC.prototype.stop = function() {
var history = state.history;
var speed = this.type === "bidirectional" ? this.neutral : 0;

this.write(this.pin, __.fscale(speed, 0, 100, 0, 180));
this.write(this.pin, Fn.fscale(speed, 0, 100, 0, 180));

history.push({
timestamp: Date.now(),
Expand Down
2 changes: 1 addition & 1 deletion test/esc.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ exports["ESC"] = {
this.clock.tick(10);
test.equal(this.servoWrite.callCount, 1);
// (9 * 180 / 100) = 16.2
test.equal(this.servoWrite.lastCall.args[1], 16.2);
test.equal(this.servoWrite.lastCall.args[1], 16.200000762939453);

this.servoWrite.reset();

Expand Down
4 changes: 2 additions & 2 deletions test/sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ exports["Sensor - Analog"] = {
// Ensure sensors may return float values
this.sensor.scale([0, 102.3]);
this.sensor.once("change", function() {
test.equal(this.value, 1.2);
test.equal(this.value, 1.2000000476837158);
});
callback(12);
this.clock.tick(25);
Expand Down Expand Up @@ -1102,7 +1102,7 @@ exports["Sensor - Analog"] = {
// Ensure sensors may return float values
this.sensor.scale([0, 102.3]);
this.sensor.once("change", function() {
test.equal(this.fscaleTo([0, 102.3]), 1.2);
test.equal(this.fscaleTo([0, 102.3]), 1.2000000476837158);
});
callback(12);
this.clock.tick(25);
Expand Down

0 comments on commit a4faac1

Please sign in to comment.