statsmodels-js
Version:
basic statistics library.
159 lines (143 loc) • 2.73 kB
JavaScript
import {
dot,
transpose,
hasEverySameArray,
unitMatrix,
matrixAdd,
} from "./util";
describe("dot function", () => {
test("one dimensional array", () => {
const actual = dot([1, 2], [3, 4]);
const expected = 11;
expect(actual).toEqual(expected);
});
test("one dimensional array", () => {
const actual = dot(
[
[],
[],
[],
],
[]
);
const expected = [3, 34, 37];
expect(actual).toEqual(expected);
});
test("two dimensional array", () => {
const actual = dot(
[
[],
[],
],
[
[],
[],
]
);
const expected = [
[],
[],
];
expect(actual).toEqual(expected);
});
});
describe("transpose function", () => {
test("", () => {
const a = [[1, 2, 3]];
const expected = [[1], [2], [3]];
expect(transpose(a)).toEqual(expected);
});
test("", () => {
const a = [
[],
[],
];
const expected = [
[],
[],
[],
];
expect(transpose(a)).toEqual(expected);
});
});
describe("hasEverySameArray function", () => {
test("same", () => {
const a = [
[],
[],
];
const expected = true;
expect(hasEverySameArray(a)).toEqual(expected);
});
test("same 2", () => {
const a = [
[],
[],
[],
[],
[],
];
const expected = true;
expect(hasEverySameArray(a)).toEqual(expected);
});
test("not same", () => {
const a = [
[],
[],
];
const expected = false;
expect(hasEverySameArray(a)).toEqual(expected);
});
test("not same", () => {
const a = [
[],
[],
[],
[],
];
const expected = false;
expect(hasEverySameArray(a)).toEqual(expected);
});
});
describe("unitMatrix", () => {
test("", () => {
const expected = [
[],
[],
];
expect(unitMatrix(2)).toEqual(expected);
});
test("", () => {
const expected = [
[],
[],
];
expect(unitMatrix(2, 3)).toEqual(expected);
});
test("", () => {
const expected = [
[],
[],
[],
[],
];
expect(unitMatrix(4)).toEqual(expected);
});
});
describe("matrixAdd", () => {
test("", () => {
const a = [
[],
[],
];
const b = [
[],
[],
];
const expected = [
[],
[],
];
expect(matrixAdd(a, b)).toEqual(expected);
});
});