Procedurally generates a radio weather report
1import path from 'path';
2import { describe, expect, it } from 'vitest';
3import { voiceLines, LINES } from '../src/voice.js';
4import type { Voice } from '../src/voice.js';
5
6const dummyVoice: Voice = {
7 'directory': '',
8 'extension': ''
9};
10
11describe('voiceLines', () => {
12 it('handles integers', () => {
13 expect(voiceLines(dummyVoice, 16549872)).to.be.ordered.members(
14 [
15 LINES.SIX, LINES.TEEN, LINES.MILLION, LINES.FIVE, LINES.HUNDRED, LINES.FORTY,
16 LINES.NINE, LINES.THOUSAND, LINES.EIGHT, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO
17 ]
18 );
19 });
20
21 it('handles floating point', () => {
22 expect(voiceLines(dummyVoice, 672.09435)).to.be.ordered.members(
23 [
24 LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
25 LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
26 ]
27 );
28 });
29
30 it('handles the negative', () => {
31 expect(voiceLines(dummyVoice, -672.09435)).to.be.ordered.members(
32 [
33 LINES.NEGATIVE, LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
34 LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
35 ]
36 );
37 });
38
39 it('handles zero', () => {
40 expect(voiceLines(dummyVoice, 0)).to.be.ordered.members(
41 [
42 LINES.ZERO
43 ]
44 );
45 });
46
47 it('handles large numbers with many zeroes', () => {
48 expect(voiceLines(dummyVoice, 700000000000001)).to.be.ordered.members(
49 [
50 LINES.SEVEN, LINES.HUNDRED, LINES.TRILLION, LINES.ONE
51 ]
52 );
53
54 expect(voiceLines(dummyVoice, 1000001)).to.be.ordered.members(
55 [
56 LINES.ONE, LINES.MILLION, LINES.ONE
57 ]
58 );
59
60 expect(voiceLines(dummyVoice, 9000000001000)).to.be.ordered.members(
61 [
62 LINES.NINE, LINES.TRILLION, LINES.ONE, LINES.THOUSAND
63 ]
64 );
65
66 expect(voiceLines(dummyVoice, 60002000000000.12)).to.be.ordered.members(
67 [
68 LINES.SIXTY, LINES.TRILLION, LINES.TWO, LINES.BILLION, LINES.POINT, LINES.ONE, LINES.TWO
69 ]
70 );
71
72 expect(voiceLines(dummyVoice, 100010001)).to.be.ordered.members(
73 [
74 LINES.ONE, LINES.HUNDRED, LINES.MILLION, LINES.TEN, LINES.THOUSAND, LINES.ONE
75 ]
76 );
77 });
78
79 it('handles irregularly named numbers', () => {
80 expect(voiceLines(dummyVoice, 210)).to.be.ordered.members(
81 [
82 LINES.TWO, LINES.HUNDRED, LINES.TEN
83 ]
84 );
85
86 expect(voiceLines(dummyVoice, 311)).to.be.ordered.members(
87 [
88 LINES.THREE, LINES.HUNDRED, LINES.ELEVEN
89 ]
90 );
91
92 expect(voiceLines(dummyVoice, 412)).to.be.ordered.members(
93 [
94 LINES.FOUR, LINES.HUNDRED, LINES.TWELVE
95 ]
96 );
97
98 expect(voiceLines(dummyVoice, 513)).to.be.ordered.members(
99 [
100 LINES.FIVE, LINES.HUNDRED, LINES.THIRTEEN
101 ]
102 );
103
104 expect(voiceLines(dummyVoice, 615)).to.be.ordered.members(
105 [
106 LINES.SIX, LINES.HUNDRED, LINES.FIFTEEN
107 ]
108 );
109 });
110
111 it('returns empty array if value is unsupported', () => {
112 expect(voiceLines(dummyVoice, Infinity)).length.to.be.empty;
113 expect(voiceLines(dummyVoice, -Infinity)).length.to.be.empty;
114 expect(voiceLines(dummyVoice, NaN)).length.to.be.empty;
115 expect(voiceLines(dummyVoice, 1e21)).length.to.be.empty;
116 });
117
118 it('returns the results as paths when voice configuration is provided', () => {
119 const directory = path.join('audio', 'voice', 'someone');
120 const v: Voice = {
121 directory,
122 extension: 'flac'
123 }
124 expect(voiceLines(v, 29)).to.be.ordered.members([
125 path.join(directory, `twenty.flac`),
126 path.join(directory, `nine.flac`),
127 ]);
128 });
129});