130 lines
4.0 KiB
TypeScript
130 lines
4.0 KiB
TypeScript
import path from 'path';
|
|
import { 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.be.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.be.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.be.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.be.ordered.members(
|
|
[
|
|
LINES.ZERO
|
|
]
|
|
);
|
|
});
|
|
|
|
it('handles large numbers with many zeroes', () => {
|
|
expect(voiceLines(dummyVoice, 700000000000001)).to.be.ordered.members(
|
|
[
|
|
LINES.SEVEN, LINES.HUNDRED, LINES.TRILLION, LINES.ONE
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 1000001)).to.be.ordered.members(
|
|
[
|
|
LINES.ONE, LINES.MILLION, LINES.ONE
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 9000000001000)).to.be.ordered.members(
|
|
[
|
|
LINES.NINE, LINES.TRILLION, LINES.ONE, LINES.THOUSAND
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 60002000000000.12)).to.be.ordered.members(
|
|
[
|
|
LINES.SIXTY, LINES.TRILLION, LINES.TWO, LINES.BILLION, LINES.POINT, LINES.ONE, LINES.TWO
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 100010001)).to.be.ordered.members(
|
|
[
|
|
LINES.ONE, LINES.HUNDRED, LINES.MILLION, LINES.TEN, LINES.THOUSAND, LINES.ONE
|
|
]
|
|
);
|
|
});
|
|
|
|
it('handles irregularly named numbers', () => {
|
|
expect(voiceLines(dummyVoice, 210)).to.be.ordered.members(
|
|
[
|
|
LINES.TWO, LINES.HUNDRED, LINES.TEN
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 311)).to.be.ordered.members(
|
|
[
|
|
LINES.THREE, LINES.HUNDRED, LINES.ELEVEN
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 412)).to.be.ordered.members(
|
|
[
|
|
LINES.FOUR, LINES.HUNDRED, LINES.TWELVE
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 513)).to.be.ordered.members(
|
|
[
|
|
LINES.FIVE, LINES.HUNDRED, LINES.THIRTEEN
|
|
]
|
|
);
|
|
|
|
expect(voiceLines(dummyVoice, 615)).to.be.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;
|
|
});
|
|
|
|
it('returns the results as paths when voice configuration is provided', () => {
|
|
const directory = path.join('audio', 'voice', 'someone');
|
|
const v: Voice = {
|
|
directory,
|
|
extension: 'flac'
|
|
}
|
|
expect(voiceLines(v, 29)).to.be.ordered.members([
|
|
path.join(directory, `twenty.flac`),
|
|
path.join(directory, `nine.flac`),
|
|
]);
|
|
});
|
|
});
|