-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61fccfa
commit f226928
Showing
8 changed files
with
1,987 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
export default { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import inverseMatrix from "../functions/inverseMatrix"; | ||
import { roundedMatrix } from "../functions/utils"; | ||
import { toStrictEqual2Array } from "./toStrictEqualArray"; | ||
|
||
test("inverse_matrix_test-1", () => { | ||
const matrix = [ | ||
[5, -3, 7], | ||
[-1, 4, 3], | ||
[6, -2, 5], | ||
]; | ||
|
||
const inverse = [ | ||
[-0.28, -0.011, 0.398], | ||
[-0.247, 0.183, 0.237], | ||
[0.237, 0.086, -0.183], | ||
]; | ||
|
||
const result = roundedMatrix(inverseMatrix(matrix) ?? []); | ||
expect(toStrictEqual2Array(result, inverse)).toBe(true); | ||
}); | ||
|
||
test("inverse_matrix_test-2", () => { | ||
const matrix = [ | ||
[6, 2, 5], | ||
[-3, 4, -1], | ||
[1, 4, 3], | ||
]; | ||
|
||
const inverse = [ | ||
[0.5, 0.437, -0.687], | ||
[0.25, 0.406, -0.281], | ||
[-0.5, -0.687, 0.937], | ||
]; | ||
|
||
const result = roundedMatrix(inverseMatrix(matrix) ?? []); | ||
expect(toStrictEqual2Array(result, inverse)).toBe(true); | ||
}); | ||
|
||
test("inverse_matrix_test-3", () => { | ||
const matrix = [ | ||
[2, -1, 3], | ||
[-1, 2, 2], | ||
[1, 1, 1], | ||
]; | ||
|
||
const inverse = [ | ||
[0, -0.333, 0.667], | ||
[-0.25, 0.083, 0.583], | ||
[0.25, 0.25, -0.25], | ||
]; | ||
|
||
const result = roundedMatrix(inverseMatrix(matrix) ?? []); | ||
expect(toStrictEqual2Array(result, inverse)).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import calculateMatrixRank from "../functions/matrixRank"; | ||
|
||
test("matrix_rank_test-1", () => { | ||
const matrix = [ | ||
[1, 2, 3, 4], | ||
[2, 4, 6, 8], | ||
]; | ||
|
||
const rank = 1; | ||
|
||
const result = calculateMatrixRank(matrix); | ||
expect(rank).toBe(result); | ||
}); | ||
|
||
test("matrix_rank_test-2", () => { | ||
const matrix = [ | ||
[2, 5, 4], | ||
[-3, 1, -2], | ||
[-1, 6, 2] | ||
]; | ||
|
||
const rank = 2; | ||
|
||
const result = calculateMatrixRank(matrix); | ||
expect(rank).toBe(result); | ||
}); | ||
|
||
test("matrix_rank_test-3", () => { | ||
const matrix = [ | ||
[1, 2], | ||
[3, 6], | ||
[5, 10], | ||
[4, 8] | ||
]; | ||
|
||
const rank = 1; | ||
|
||
const result = calculateMatrixRank(matrix); | ||
expect(rank).toBe(result); | ||
}); | ||
|
||
test("matrix_rank_test-4", () => { | ||
const matrix = [ | ||
[6, 2, 5], | ||
[-3, 4, -1], | ||
[1, 4, 3], | ||
]; | ||
|
||
const rank = 3; | ||
|
||
const result = calculateMatrixRank(matrix); | ||
expect(rank).toBe(result); | ||
}); | ||
|
||
test("matrix_rank_test-5", () => { | ||
const matrix = [ | ||
[-1, 5, 4], | ||
[-2, 7, 5], | ||
[3, 4, 1], | ||
]; | ||
|
||
const rank = 3; | ||
|
||
const result = calculateMatrixRank(matrix); | ||
expect(rank).toBe(result); | ||
}); | ||
|
||
test("matrix_rank_test-6", () => { | ||
const matrix = [ | ||
[1, 2, 3, 4], | ||
[-2, 5, -1, 3], | ||
[2, 4, 6, 8], | ||
[-1, 7, 2, 7] | ||
]; | ||
|
||
const rank = 2; | ||
|
||
const result = calculateMatrixRank(matrix); | ||
expect(rank).toBe(result); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import solveLinearSystem from "../functions/solveLinearSystem"; | ||
import { toStrictEqual1Array } from "./toStrictEqualArray"; | ||
|
||
test("solve_linear_system_test-1", () => { | ||
const matrix = [ | ||
[5, -3, 7], | ||
[-1, 4, 3], | ||
[6, -2, 5], | ||
]; | ||
|
||
const constants = [13, 13, 12]; | ||
|
||
const output = [1, 2, 2]; | ||
|
||
const result = solveLinearSystem(matrix, constants); | ||
expect(toStrictEqual1Array(output, result ?? [])).toBe(true); | ||
}); | ||
|
||
test("solve_linear_system_test-2", () => { | ||
const matrix = [ | ||
[6, 2, 5], | ||
[-3, 4, -1], | ||
[1, 4, 3], | ||
]; | ||
|
||
const constants = [1, 6, 6]; | ||
|
||
const output = [-1, 1, 1]; | ||
|
||
const result = solveLinearSystem(matrix, constants); | ||
expect(toStrictEqual1Array(output, result ?? [])).toBe(true); | ||
}); | ||
|
||
test("solve_linear_system_test-3", () => { | ||
const matrix = [ | ||
[-2, -1, -2], | ||
[4, -2, 1], | ||
[1, 3, -5], | ||
]; | ||
|
||
const constants = [1, 5, 3]; | ||
|
||
const output = [1, -1, -1]; | ||
|
||
const result = solveLinearSystem(matrix, constants); | ||
expect(toStrictEqual1Array(output, result ?? [])).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// export function toStrictEqual2Array(value: number[][], correct: number[][]) { | ||
// expect(value.length).toBe(correct.length); | ||
// for (let index = 0; index < correct.length; index++) | ||
// expect(value[index].length).toBe(correct[index].length); | ||
|
||
// for (let i = 0; i < correct.length; i++) | ||
// for (let j = 0; j < correct[i].length; j++) | ||
// expect(correct[i][j]).toBeCloseTo(correct[i][j]); | ||
// } | ||
|
||
export function toStrictEqual1Array( | ||
value: number[], | ||
correct: number[], | ||
): boolean { | ||
if (value.length != correct.length) return false; | ||
|
||
for (let i = 0; i < correct.length; i++) | ||
if (!areEqual(value[i], correct[i])) return false; | ||
|
||
return true; | ||
} | ||
|
||
export function toStrictEqual2Array( | ||
value: number[][], | ||
correct: number[][], | ||
): boolean { | ||
if (value.length != correct.length) return false; | ||
for (let index = 0; index < correct.length; index++) | ||
if (value[index].length != correct[index].length) return false; | ||
|
||
for (let i = 0; i < correct.length; i++) | ||
for (let j = 0; j < correct[i].length; j++) | ||
if (!areEqual(value[i][j], correct[i][j])) return false; | ||
|
||
return true; | ||
} | ||
|
||
function areEqual(number1: number, number2: number): boolean { | ||
return Math.abs(number1 - number2) < 0.002; | ||
} |
Oops, something went wrong.