test for conditions
This commit is contained in:
@@ -41,6 +41,8 @@ function conditionIsMet(condition: string | undefined, currentWeather: CurrentWe
|
|||||||
case '=':
|
case '=':
|
||||||
case '==':
|
case '==':
|
||||||
return lhsResolved == rhsResolved;
|
return lhsResolved == rhsResolved;
|
||||||
|
case '!=':
|
||||||
|
return lhsResolved != rhsResolved;
|
||||||
case '<':
|
case '<':
|
||||||
return lhsResolved < rhsResolved;
|
return lhsResolved < rhsResolved;
|
||||||
case '<=':
|
case '<=':
|
||||||
@@ -88,6 +90,7 @@ async function Sequencer(conf: Config): Promise<string[]> {
|
|||||||
config = conf;
|
config = conf;
|
||||||
const weather = new OpenWeatherAPI(conf.weather);
|
const weather = new OpenWeatherAPI(conf.weather);
|
||||||
const currentWeather = await weather.getCurrent();
|
const currentWeather = await weather.getCurrent();
|
||||||
|
console.log(JSON.stringify(currentWeather));
|
||||||
const sequence: string[] = [];
|
const sequence: string[] = [];
|
||||||
const program: SegmentName[] = selectOne(conf.programs);
|
const program: SegmentName[] = selectOne(conf.programs);
|
||||||
for (let i = 0; i < program.length; i++) {
|
for (let i = 0; i < program.length; i++) {
|
||||||
|
@@ -9,7 +9,48 @@ vi.mock('openweather-api-node', () => {
|
|||||||
return {
|
return {
|
||||||
OpenWeatherAPI: vi.fn().mockImplementation((_) => {
|
OpenWeatherAPI: vi.fn().mockImplementation((_) => {
|
||||||
return {
|
return {
|
||||||
getCurrent: vi.fn(() => {})
|
getCurrent: vi.fn(() => {
|
||||||
|
return {
|
||||||
|
"lat": 43.0748,
|
||||||
|
"lon": -89.3838,
|
||||||
|
"dt": "2025-08-29T06:31:05.000Z",
|
||||||
|
"dtRaw": 1756449065,
|
||||||
|
"timezoneOffset": -18000,
|
||||||
|
"astronomical": {
|
||||||
|
"sunrise": "2025-08-29T11:19:05.000Z",
|
||||||
|
"sunriseRaw": 1756466345,
|
||||||
|
"sunset": "2025-08-30T00:38:08.000Z",
|
||||||
|
"sunsetRaw": 1756514288
|
||||||
|
},
|
||||||
|
"weather": {
|
||||||
|
"temp": {
|
||||||
|
"cur": 55.85,
|
||||||
|
"min": 52.99,
|
||||||
|
"max": 58.01
|
||||||
|
},
|
||||||
|
"feelsLike": {
|
||||||
|
"cur": 55.31
|
||||||
|
},
|
||||||
|
"pressure": 1022,
|
||||||
|
"humidity": 89,
|
||||||
|
"clouds": 0,
|
||||||
|
"visibility": 10000,
|
||||||
|
"wind": {
|
||||||
|
"deg": 140,
|
||||||
|
"speed": 5.75
|
||||||
|
},
|
||||||
|
"rain": 0,
|
||||||
|
"snow": 0,
|
||||||
|
"conditionId": 800,
|
||||||
|
"main": "Clear",
|
||||||
|
"description": "clear sky",
|
||||||
|
"icon": {
|
||||||
|
"url": "http://openweathermap.org/img/wn/01n@2x.png",
|
||||||
|
"raw": "01n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -39,5 +80,31 @@ describe('sequencer', () => {
|
|||||||
weather: dummyWeather
|
weather: dummyWeather
|
||||||
})).to.include.ordered.members(['seq1.flac', 'seq1.flac', 'seq2.flac']);
|
})).to.include.ordered.members(['seq1.flac', 'seq1.flac', 'seq2.flac']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can include tracks conditionally', async () => {
|
||||||
|
expect(await Sequencer({
|
||||||
|
programs: [['segment 1', 'segment 2']],
|
||||||
|
segments: {
|
||||||
|
'segment 1': ['sequence 1'],
|
||||||
|
'segment 2': ['sequence 2']
|
||||||
|
},
|
||||||
|
sequences: {
|
||||||
|
'sequence 1': {
|
||||||
|
'conditions': ['1 = 1', '1.1 > 1', '2 >= 1', '1 < 2', '1 <= 1', '-1 != 0', undefined],
|
||||||
|
'tracks': [
|
||||||
|
'seq1.flac'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'sequence 2': {
|
||||||
|
'conditions': ['weather.lat = -500'],
|
||||||
|
'tracks': [
|
||||||
|
'seq2.flac'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
voices: {},
|
||||||
|
weather: dummyWeather
|
||||||
|
})).to.be.ordered.members(['seq1.flac']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -10,7 +10,7 @@ const dummyVoice: Voice = {
|
|||||||
|
|
||||||
describe('voiceLines', () => {
|
describe('voiceLines', () => {
|
||||||
it('handles integers', () => {
|
it('handles integers', () => {
|
||||||
expect(voiceLines(dummyVoice, 16549872)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 16549872)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.SIX, LINES.TEEN, LINES.MILLION, LINES.FIVE, LINES.HUNDRED, LINES.FORTY,
|
LINES.SIX, LINES.TEEN, LINES.MILLION, LINES.FIVE, LINES.HUNDRED, LINES.FORTY,
|
||||||
LINES.NINE, LINES.THOUSAND, LINES.EIGHT, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO
|
LINES.NINE, LINES.THOUSAND, LINES.EIGHT, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO
|
||||||
@@ -19,7 +19,7 @@ describe('voiceLines', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles floating point', () => {
|
it('handles floating point', () => {
|
||||||
expect(voiceLines(dummyVoice, 672.09435)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 672.09435)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
|
LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
|
||||||
LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
|
LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
|
||||||
@@ -28,7 +28,7 @@ describe('voiceLines', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles the negative', () => {
|
it('handles the negative', () => {
|
||||||
expect(voiceLines(dummyVoice, -672.09435)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, -672.09435)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.NEGATIVE, LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
|
LINES.NEGATIVE, LINES.SIX, LINES.HUNDRED, LINES.SEVENTY, LINES.TWO, LINES.POINT, LINES.ZERO,
|
||||||
LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
|
LINES.NINE, LINES.FOUR, LINES.THREE, LINES.FIVE
|
||||||
@@ -37,7 +37,7 @@ describe('voiceLines', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles zero', () => {
|
it('handles zero', () => {
|
||||||
expect(voiceLines(dummyVoice, 0)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 0)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.ZERO
|
LINES.ZERO
|
||||||
]
|
]
|
||||||
@@ -45,31 +45,31 @@ describe('voiceLines', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles large numbers with many zeroes', () => {
|
it('handles large numbers with many zeroes', () => {
|
||||||
expect(voiceLines(dummyVoice, 700000000000001)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 700000000000001)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.SEVEN, LINES.HUNDRED, LINES.TRILLION, LINES.ONE
|
LINES.SEVEN, LINES.HUNDRED, LINES.TRILLION, LINES.ONE
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 1000001)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 1000001)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.ONE, LINES.MILLION, LINES.ONE
|
LINES.ONE, LINES.MILLION, LINES.ONE
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 9000000001000)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 9000000001000)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.NINE, LINES.TRILLION, LINES.ONE, LINES.THOUSAND
|
LINES.NINE, LINES.TRILLION, LINES.ONE, LINES.THOUSAND
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 60002000000000.12)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 60002000000000.12)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.SIXTY, LINES.TRILLION, LINES.TWO, LINES.BILLION, LINES.POINT, LINES.ONE, LINES.TWO
|
LINES.SIXTY, LINES.TRILLION, LINES.TWO, LINES.BILLION, LINES.POINT, LINES.ONE, LINES.TWO
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 100010001)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 100010001)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.ONE, LINES.HUNDRED, LINES.MILLION, LINES.TEN, LINES.THOUSAND, LINES.ONE
|
LINES.ONE, LINES.HUNDRED, LINES.MILLION, LINES.TEN, LINES.THOUSAND, LINES.ONE
|
||||||
]
|
]
|
||||||
@@ -77,31 +77,31 @@ describe('voiceLines', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles irregularly named numbers', () => {
|
it('handles irregularly named numbers', () => {
|
||||||
expect(voiceLines(dummyVoice, 210)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 210)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.TWO, LINES.HUNDRED, LINES.TEN
|
LINES.TWO, LINES.HUNDRED, LINES.TEN
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 311)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 311)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.THREE, LINES.HUNDRED, LINES.ELEVEN
|
LINES.THREE, LINES.HUNDRED, LINES.ELEVEN
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 412)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 412)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.FOUR, LINES.HUNDRED, LINES.TWELVE
|
LINES.FOUR, LINES.HUNDRED, LINES.TWELVE
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 513)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 513)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.FIVE, LINES.HUNDRED, LINES.THIRTEEN
|
LINES.FIVE, LINES.HUNDRED, LINES.THIRTEEN
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(voiceLines(dummyVoice, 615)).to.include.ordered.members(
|
expect(voiceLines(dummyVoice, 615)).to.be.ordered.members(
|
||||||
[
|
[
|
||||||
LINES.SIX, LINES.HUNDRED, LINES.FIFTEEN
|
LINES.SIX, LINES.HUNDRED, LINES.FIFTEEN
|
||||||
]
|
]
|
||||||
@@ -121,7 +121,7 @@ describe('voiceLines', () => {
|
|||||||
directory,
|
directory,
|
||||||
extension: 'flac'
|
extension: 'flac'
|
||||||
}
|
}
|
||||||
expect(voiceLines(v, 29)).to.include.ordered.members([
|
expect(voiceLines(v, 29)).to.be.ordered.members([
|
||||||
path.join(directory, `twenty.flac`),
|
path.join(directory, `twenty.flac`),
|
||||||
path.join(directory, `nine.flac`),
|
path.join(directory, `nine.flac`),
|
||||||
]);
|
]);
|
||||||
|
Reference in New Issue
Block a user