react-sparklines-typescript
Version:
react-sparklines rewritten in typescript and modern react patterns
86 lines • 3.77 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
//@global describe
var dataToPoints_1 = __importDefault(require("../dataProcessing/dataToPoints"));
var mean_1 = __importDefault(require("../dataProcessing/mean"));
var median_1 = __importDefault(require("../dataProcessing/median"));
var midRange_1 = __importDefault(require("../dataProcessing/midRange"));
var stdev_1 = __importDefault(require("../dataProcessing/stdev"));
var variance_1 = __importDefault(require("../dataProcessing/variance"));
describe("dataToPoints", function () {
it("should return an array", function () {
expect(Array.isArray(dataToPoints_1.default({ data: [] }))).toEqual(true);
expect(Array.isArray(dataToPoints_1.default({ data: [1, 2, 3] }))).toEqual(true);
expect(Array.isArray(dataToPoints_1.default({ data: [1, null, undefined] }))).toEqual(true);
});
it("should return only `limit` items", function () {
expect(dataToPoints_1.default({ data: [1, 2, 3, 4, 5] }).length).toEqual(5);
expect(dataToPoints_1.default({ data: [1, 2, 3, 4, 5], limit: 2 }).length).toEqual(2);
expect(dataToPoints_1.default({ data: [1, 2, 3, 4, 5], limit: 5 }).length).toEqual(5);
expect(dataToPoints_1.default({ data: [1, 2, 3, 4, 5], limit: 10 }).length).toEqual(5);
});
it("should return proper values for 1 value", function () {
expect(dataToPoints_1.default({ data: [1] })).toEqual([{ x: 0, y: 0.5 }]);
});
it("should return proper values 2+ values", function () {
expect(dataToPoints_1.default({ data: [1, 1] })).toEqual([
{ x: 0, y: 0.5 },
{ x: 1, y: 0.5 },
]);
expect(dataToPoints_1.default({ data: [0, 1] })).toEqual([
{ x: 0, y: 1 },
{ x: 1, y: 0 },
]);
expect(dataToPoints_1.default({ data: [1, 0] })).toEqual([
{ x: 0, y: 0 },
{ x: 1, y: 1 },
]);
expect(dataToPoints_1.default({ data: [0, 1, 2] })).toEqual([
{ x: 0, y: 1 },
{ x: 0.5, y: 0.5 },
{ x: 1, y: 0 },
]);
});
it("should inerpolate values properly", function () {
expect(dataToPoints_1.default({ data: [0, 1, 2], width: 10, height: 10 })).toEqual([
{ x: 0, y: 10 },
{ x: 5, y: 5 },
{ x: 10, y: 0 },
]);
});
it("should take min and max into account", function () {
expect(dataToPoints_1.default({ data: [1, 2, 3, 4], width: 6, height: 10, max: 2, min: 3 })).toEqual([
{ x: 0, y: -10 },
{ x: 2, y: 0 },
{ x: 4, y: 10 },
{ x: 6, y: 20 },
]);
});
it("should return y == height for 0 and null values", function () {
expect(dataToPoints_1.default({ data: [0] })).toEqual([{ x: 0, y: 0.5 }]);
expect(dataToPoints_1.default({ data: [0, null, 0] })).toEqual([
{ x: 0, y: 0.5 },
{ x: 0.5, y: 0.5 },
{ x: 1, y: 0.5 },
]);
});
it("shoud test mean", function () {
expect(mean_1.default([1, 2, 3])).toEqual(2);
});
it("shoud test median", function () {
expect(median_1.default([1, 4, 7, 8, 10])).toEqual(7);
});
it("shoud test midRange", function () {
expect(midRange_1.default([50, 100])).toEqual(75);
});
it("shoud test stdev", function () {
expect(stdev_1.default([50, 100])).toEqual(25);
});
it("shoud test variance", function () {
expect(variance_1.default([1, 2, 3, 4, 5])).toEqual(2);
});
});
//# sourceMappingURL=dataProcessing.test.js.map