2017-04-20 19:17:05 -04:00
|
|
|
const test = require('tap').test;
|
|
|
|
const math = require('../../src/util/math-util');
|
2016-10-03 16:34:57 -04:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('degToRad', t => {
|
2016-10-17 11:52:02 -04:00
|
|
|
t.strictEqual(math.degToRad(0), 0);
|
|
|
|
t.strictEqual(math.degToRad(1), 0.017453292519943295);
|
|
|
|
t.strictEqual(math.degToRad(180), Math.PI);
|
|
|
|
t.strictEqual(math.degToRad(360), 2 * Math.PI);
|
|
|
|
t.strictEqual(math.degToRad(720), 4 * Math.PI);
|
2016-10-03 16:34:57 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('radToDeg', t => {
|
2016-10-03 18:23:43 -04:00
|
|
|
t.strictEqual(math.radToDeg(0), 0);
|
|
|
|
t.strictEqual(math.radToDeg(1), 57.29577951308232);
|
|
|
|
t.strictEqual(math.radToDeg(180), 10313.240312354817);
|
|
|
|
t.strictEqual(math.radToDeg(360), 20626.480624709635);
|
|
|
|
t.strictEqual(math.radToDeg(720), 41252.96124941927);
|
2016-10-03 16:34:57 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('clamp', t => {
|
2016-10-03 18:23:43 -04:00
|
|
|
t.strictEqual(math.clamp(0, 0, 10), 0);
|
|
|
|
t.strictEqual(math.clamp(1, 0, 10), 1);
|
|
|
|
t.strictEqual(math.clamp(-10, 0, 10), 0);
|
|
|
|
t.strictEqual(math.clamp(100, 0, 10), 10);
|
2016-10-03 16:34:57 -04:00
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('wrapClamp', t => {
|
2016-10-03 18:23:43 -04:00
|
|
|
t.strictEqual(math.wrapClamp(0, 0, 10), 0);
|
|
|
|
t.strictEqual(math.wrapClamp(1, 0, 10), 1);
|
|
|
|
t.strictEqual(math.wrapClamp(-10, 0, 10), 1);
|
|
|
|
t.strictEqual(math.wrapClamp(100, 0, 10), 1);
|
2016-10-03 16:34:57 -04:00
|
|
|
t.end();
|
|
|
|
});
|
2017-01-31 19:05:54 -05:00
|
|
|
|
2017-04-20 19:17:05 -04:00
|
|
|
test('tan', t => {
|
2017-01-31 19:05:54 -05:00
|
|
|
t.strictEqual(math.tan(90), Infinity);
|
|
|
|
t.strictEqual(math.tan(180), 0);
|
|
|
|
t.strictEqual(math.tan(-90), -Infinity);
|
|
|
|
t.strictEqual(math.tan(33), 0.6494075932);
|
|
|
|
t.end();
|
|
|
|
});
|
2018-07-24 11:00:48 -04:00
|
|
|
|
|
|
|
test('reducedSortOrdering', t => {
|
|
|
|
t.deepEqual(math.reducedSortOrdering([5, 18, 6, 3]), [1, 3, 2, 0]);
|
|
|
|
t.deepEqual(math.reducedSortOrdering([5, 1, 56, 19]), [1, 0, 3, 2]);
|
|
|
|
t.end();
|
|
|
|
});
|