munin/source/test.ts

151 lines
3.3 KiB
TypeScript
Raw Normal View History

2025-06-27 22:07:18 +02:00
/*
This file is part of »munin«.
Copyright 2025 'Fenris Wolf' <fenris@folksprak.org>
»munin« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»munin« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »munin«. If not, see <http://www.gnu.org/licenses/>.
*/
namespace _munin.test
{
2025-06-28 08:34:57 +02:00
2025-06-27 22:07:18 +02:00
/**
*/
2025-06-28 08:34:57 +02:00
async function reminder_due(
) : Promise<void>
2025-06-27 22:07:18 +02:00
{
2025-06-28 08:34:57 +02:00
type type_input = {
reminder : {
frequency : string;
offset : int;
from : int;
to : int;
2025-06-27 22:07:18 +02:00
};
2025-06-28 08:34:57 +02:00
datetime : lib_plankton.pit.type_datetime;
interval : int;
2025-06-27 22:07:18 +02:00
};
2025-06-28 08:34:57 +02:00
type type_output = boolean;
const testcases : Array<
_munin.helpers.test.type_testcase<
type_input,
type_output
>
> = await _munin.helpers.test.get_data<type_input, type_output>(
"data/reminder_due.testdata.json",
2025-06-27 22:07:18 +02:00
{
2025-06-28 08:34:57 +02:00
}
);
2025-06-27 22:07:18 +02:00
for (const testcase of testcases)
{
2025-06-28 08:34:57 +02:00
_munin.helpers.test.start(testcase.name);
2025-06-27 22:07:18 +02:00
// execution
const result : boolean = _munin.logic.reminder_due(
{
2025-06-28 08:34:57 +02:00
"frequency": _munin.logic.frequency_decode(testcase.input.reminder.frequency),
2025-06-27 22:07:18 +02:00
"offset": testcase.input.reminder.offset,
"from": testcase.input.reminder.from,
"to": testcase.input.reminder.to,
},
{
2025-06-28 08:34:57 +02:00
"pit": lib_plankton.pit.from_datetime(testcase.input.datetime),
2025-06-27 22:07:18 +02:00
"interval": testcase.input.interval,
}
);
// assertions
if (result !== testcase.output)
{
2025-06-28 08:34:57 +02:00
_munin.helpers.test.fail(testcase.name);
2025-06-27 22:07:18 +02:00
}
}
}
/**
*/
2025-06-28 08:34:57 +02:00
async function reminder_covers_event(
) : Promise<void>
2025-06-27 22:07:18 +02:00
{
2025-06-28 08:34:57 +02:00
type type_input = {
reminder : {
frequency : string;
offset : int;
from : int;
to : int;
};
event : {
begin : lib_plankton.pit.type_datetime;
2025-06-27 22:07:18 +02:00
};
2025-06-28 08:34:57 +02:00
datetime : lib_plankton.pit.type_datetime;
interval : int;
2025-06-27 22:07:18 +02:00
};
2025-06-28 08:34:57 +02:00
type type_output = boolean;
const testcases : Array<
_munin.helpers.test.type_testcase<
type_input,
type_output
>
> = await _munin.helpers.test.get_data<type_input, type_output>(
"data/reminder_covers_event.testdata.json",
2025-06-27 22:07:18 +02:00
{
2025-06-28 08:34:57 +02:00
}
);
2025-06-27 22:07:18 +02:00
for (const testcase of testcases)
{
2025-06-28 08:34:57 +02:00
_munin.helpers.test.start(testcase.name);
2025-06-27 22:07:18 +02:00
// execution
2025-06-28 08:34:57 +02:00
const result : boolean = _munin.logic.reminder_covers_event(
2025-06-27 22:07:18 +02:00
{
2025-06-28 08:34:57 +02:00
"frequency": _munin.logic.frequency_decode(testcase.input.reminder.frequency),
2025-06-27 22:07:18 +02:00
"offset": testcase.input.reminder.offset,
"from": testcase.input.reminder.from,
"to": testcase.input.reminder.to,
},
{
"title": "test",
2025-06-28 08:34:57 +02:00
"begin": testcase.input.event.begin,
2025-06-27 22:07:18 +02:00
"end": null,
"description": null,
"location": null,
"tags": null,
},
{
2025-06-28 08:34:57 +02:00
"pit": lib_plankton.pit.from_datetime(testcase.input.datetime),
2025-06-27 22:07:18 +02:00
}
);
// assertions
if (result !== testcase.output)
{
2025-06-28 08:34:57 +02:00
_munin.helpers.test.fail(testcase.name);
2025-06-27 22:07:18 +02:00
}
}
}
2025-06-28 08:34:57 +02:00
2025-06-27 22:07:18 +02:00
/**
*/
2025-06-28 08:34:57 +02:00
export async function all(
) : Promise<void>
2025-06-27 22:07:18 +02:00
{
2025-06-28 08:34:57 +02:00
await reminder_due();
await reminder_covers_event();
2025-06-27 22:07:18 +02:00
}
}