statsmodels-js
Version:
basic statistics library.
111 lines (101 loc) • 2.48 kB
JavaScript
import { ndArray } from "./ndarray";
describe("ndArray", () => {
describe("new", () => {
test("one dimention", () => {
const array = [1, 1, 1];
const a = new ndArray(array);
const expected = [3];
expect(a._shape).toEqual(expected);
});
test("two dimention", () => {
const array = [[1], [1], [1]];
const a = new ndArray(array);
const expected = [3, 1];
expect(a._shape).toEqual(expected);
});
test("invalid elements", () => {
const array = [[1, 2], [1], [1, 2]];
expect(() => {
new ndArray(array);
}).toThrowError(new Error("invalid elements"));
});
});
describe("add", () => {
describe("one dimension", () => {
test("different shape", () => {
const a = new ndArray([1, 1, 1]);
const b = new ndArray([2, 3]);
expect(() => {
a.add(b);
}).toThrowError(new Error("different shape"));
});
test("", () => {
const a = new ndArray([1, 1, 1]);
const b = new ndArray([2, 3, 4]);
const expected = [3, 4, 5];
expect(a.add(b)).toEqual(expected);
});
});
});
describe("two dimension", () => {
test("different shape", () => {
const a = new ndArray([
[],
[],
[],
]);
const b = new ndArray([
[],
[],
[],
]);
expect(() => {
a.add(b);
}).toThrowError(new Error("different shape"));
});
test("", () => {
const a = new ndArray([
[],
[],
[],
]);
const b = new ndArray([
[],
[],
[],
]);
const expected = [
[],
[],
[],
];
expect(a.add(b)).toEqual(expected);
});
});
describe("multiple", () => {
describe("one dimension", () => {
test("", () => {
const a = new ndArray([1, 1, 1]);
const b = 4;
const expected = [4, 4, 4];
expect(a.multiply(b)).toEqual(expected);
});
});
describe("two dimension", () => {
test("", () => {
const a = new ndArray([
[],
[],
[],
]);
const b = 10;
const expected = [
[],
[],
[],
];
expect(a.multiply(b)).toEqual(expected);
});
});
});
});