enhancedmath
Version:
This package contains some enhanced mathematical operations
76 lines (75 loc) • 1.98 kB
JavaScript
import { describe, test, expect } from 'vitest';
import matrix_sum from '../Matrix/matrix_sum';
describe('Matrix: Sum', () => {
test("should return undefined if dimensions aren't the same", () => {
const A = [
[ ],
[ ],
];
const B = [[5, 6]];
const C = [[7], [8]];
let result = matrix_sum(A, B);
expect(result).toBeUndefined();
result = matrix_sum(A, C);
expect(result).toBeUndefined();
result = matrix_sum(C, B);
expect(result).toBeUndefined();
});
test('should calculate the sum of A and B for 1x1', () => {
const A = [[1]];
const B = [[2]];
const result = matrix_sum(A, B);
expect(result).toEqual([[3]]);
});
test('should calculate the sum of A and B for 2x2', () => {
const A = [
[ ],
[ ],
];
const B = [
[ ],
[ ],
];
const result = matrix_sum(A, B);
expect(result).toEqual([
[ ],
[ ],
]);
});
test('should calculate the sum of A and B for 4x3', () => {
const A = [
[ ],
[ ],
[ ],
[ ],
];
const B = [
[ ],
[ ],
[ ],
[ ],
];
const result = matrix_sum(A, B);
expect(result).toEqual([
[ ],
[ ],
[ ],
[ ],
]);
});
test('should calculate the sum of A and B for 2x3', () => {
const A = [
[ ],
[ ],
];
const B = [
[ ],
[ ],
];
const result = matrix_sum(A, B);
expect(result).toEqual([
[ ],
[ ],
]);
});
});