tests for voice
All checks were successful
NPM Audit Check / Check NPM audit (push) Successful in -1m32s
All checks were successful
NPM Audit Check / Check NPM audit (push) Successful in -1m32s
This commit is contained in:
33
.github/workflows/test.yml
vendored
Normal file
33
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: NPM Audit Check
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
schedule:
|
||||
- cron: '15 16 * * 5'
|
||||
|
||||
jobs:
|
||||
|
||||
npm_audit:
|
||||
name: Check NPM audit
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 20
|
||||
strategy:
|
||||
fail-fast: true
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Setup nodejs
|
||||
uses: https://github.com/actions/setup-node@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- run: npm test
|
||||
name: Run tests
|
1
.gitignore
vendored
1
.gitignore
vendored
@@ -102,3 +102,4 @@ public
|
||||
config/config.json5
|
||||
distribution/
|
||||
.env
|
||||
test/*.js*
|
||||
|
1497
package-lock.json
generated
1497
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,8 +20,9 @@
|
||||
"type": "module",
|
||||
"main": "distribution/index.js",
|
||||
"scripts": {
|
||||
"build": "npx tsc",
|
||||
"start": "node distribution/index.js"
|
||||
"build": "tsc",
|
||||
"start": "node distribution/index.js",
|
||||
"test": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"json5": "2.2.3",
|
||||
@@ -29,6 +30,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "5.9.2",
|
||||
"@types/node": "24.3.0"
|
||||
"@types/node": "24.3.0",
|
||||
"vitest": "3.2.4"
|
||||
}
|
||||
}
|
@@ -165,9 +165,9 @@ function voiceLines(voice: Voice, num: number): string[] {
|
||||
tokens.push(LINES.POINT);
|
||||
tokens.push(...digitByDigit(parts[1]));
|
||||
}
|
||||
return tokens.map(l => path.join(voice.directory, `${l}.${voice.extension}`));
|
||||
return tokens.map(l => path.join(voice.directory, `${l}${voice.extension.length > 0 && voice.extension.charAt(0) !== '.' ? '.' : ''}${voice.extension}`));
|
||||
}
|
||||
|
||||
export default voiceLines;
|
||||
export { voiceLines };
|
||||
export { voiceLines, LINES };
|
||||
export type { Voice, Voices };
|
||||
|
116
test/voice.test.ts
Normal file
116
test/voice.test.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import { assert, describe, expect, it } from 'vitest'
|
||||
import { voiceLines, LINES } from '../src/voice.js';
|
||||
import type { Voice } from '../src/voice.js';
|
||||
|
||||
const dummyVoice: Voice = {
|
||||
'directory': '',
|
||||
'extension': ''
|
||||
};
|
||||
|
||||
describe('voiceLines', () => {
|
||||
it('handles integers', () => {
|
||||
expect(voiceLines(dummyVoice, 16549872)).to.include.ordered.members(
|
||||
[
|
||||
LINES.SIX, LINES.TEEN, LINES.MILLION, LINES.FIVE, LINES.HUNDRED, LINES.FORTY,
|
||||
LINES.NINE, LINES.THOUSAND, LINES.EIGHT, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('handles floating point', () => {
|
||||
expect(voiceLines(dummyVoice, 672.09435)).to.include.ordered.members(
|
||||
[
|
||||
LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
|
||||
LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('handles the negative', () => {
|
||||
expect(voiceLines(dummyVoice, -672.09435)).to.include.ordered.members(
|
||||
[
|
||||
LINES.NEGATIVE, LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
|
||||
LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('handles zero', () => {
|
||||
expect(voiceLines(dummyVoice, 0)).to.include.ordered.members(
|
||||
[
|
||||
LINES.ZERO
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('handles large numbers with many zeroes', () => {
|
||||
expect(voiceLines(dummyVoice, 700000000000001)).to.include.ordered.members(
|
||||
[
|
||||
LINES.SEVEN, LINES.HUNDRED, LINES.TRILLION, LINES.ONE
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 1000001)).to.include.ordered.members(
|
||||
[
|
||||
LINES.ONE, LINES.MILLION, LINES.ONE
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 9000000001000)).to.include.ordered.members(
|
||||
[
|
||||
LINES.NINE, LINES.TRILLION, LINES.ONE, LINES.THOUSAND
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 60002000000000.12)).to.include.ordered.members(
|
||||
[
|
||||
LINES.SIXTY, LINES.TRILLION, LINES.TWO, LINES.BILLION, LINES.POINT, LINES.ONE, LINES.TWO
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 100010001)).to.include.ordered.members(
|
||||
[
|
||||
LINES.ONE, LINES.HUNDRED, LINES.MILLION, LINES.TEN, LINES.THOUSAND, LINES.ONE
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('handles irregularly named numbers', () => {
|
||||
expect(voiceLines(dummyVoice, 210)).to.include.ordered.members(
|
||||
[
|
||||
LINES.TWO, LINES.HUNDRED, LINES.TEN
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 311)).to.include.ordered.members(
|
||||
[
|
||||
LINES.THREE, LINES.HUNDRED, LINES.ELEVEN
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 412)).to.include.ordered.members(
|
||||
[
|
||||
LINES.FOUR, LINES.HUNDRED, LINES.TWELVE
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 513)).to.include.ordered.members(
|
||||
[
|
||||
LINES.FIVE, LINES.HUNDRED, LINES.THIRTEEN
|
||||
]
|
||||
);
|
||||
|
||||
expect(voiceLines(dummyVoice, 615)).to.include.ordered.members(
|
||||
[
|
||||
LINES.SIX, LINES.HUNDRED, LINES.FIFTEEN
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
it('returns empty array if value is unsupported', () => {
|
||||
expect(voiceLines(dummyVoice, Infinity)).length.to.be.empty;
|
||||
expect(voiceLines(dummyVoice, -Infinity)).length.to.be.empty;
|
||||
expect(voiceLines(dummyVoice, NaN)).length.to.be.empty;
|
||||
expect(voiceLines(dummyVoice, 1e21)).length.to.be.empty;
|
||||
});
|
||||
});
|
@@ -9,9 +9,9 @@
|
||||
"moduleResolution": "node16",
|
||||
"sourceMap": true,
|
||||
"inlineSources": true,
|
||||
"rootDir": "./src",
|
||||
"rootDir": "./",
|
||||
"outDir": "./distribution"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"include": ["src/**/*", "test/**/*"],
|
||||
"exclude": ["**/*.spec.ts"]
|
||||
}
|
||||
|
Reference in New Issue
Block a user