Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move BigInt math to core package, add sum(bigint[])
- Loading branch information
1 parent
d36dd5c
commit 41f3e03
Showing
9 changed files
with
54 additions
and
10 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,8 @@ | ||
export const BigIntMath = { | ||
abs(x: bigint): bigint { | ||
return x < 0n ? -x : x; | ||
}, | ||
sum(arr: bigint[]): bigint { | ||
return arr.reduce((result, num) => result + num, 0n); | ||
} | ||
}; |
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,7 @@ | ||
module.exports = { | ||
"extends": ["../../../test/.eslintrc.js"], | ||
"parserOptions": { | ||
"project": "./tsconfig.json", | ||
"tsconfigRootDir": __dirname | ||
} | ||
} |
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,12 @@ | ||
import { BigIntMath } from '@src/BigIntMath'; | ||
|
||
describe('BigIntMath', () => { | ||
describe('abs', () => { | ||
it('positive', () => expect(BigIntMath.abs(1n)).toBe(1n)); | ||
it('negative', () => expect(BigIntMath.abs(-1n)).toBe(1n)); | ||
}); | ||
describe('sum', () => { | ||
it('empty', () => expect(BigIntMath.sum([])).toBe(0n)); | ||
it('non-empty', () => expect(BigIntMath.sum([-1n, 5n])).toBe(4n)); | ||
}); | ||
}); |
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,11 @@ | ||
const { pathsToModuleNameMapper } = require('ts-jest/utils') | ||
const { compilerOptions } = require('./tsconfig') | ||
|
||
module.exports = { | ||
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths), | ||
preset: 'ts-jest', | ||
transform: { | ||
"^.+\\.test.ts?$": "ts-jest" | ||
}, | ||
testTimeout: 120000 | ||
} |
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,10 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"paths": { | ||
"@src/*": ["../src/*"] | ||
} | ||
}, | ||
"references": [{ "path": "../src" }] | ||
} |
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 was deleted.
Oops, something went wrong.