151 lines
3.3 KiB
TypeScript
151 lines
3.3 KiB
TypeScript
/*
|
|
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
|
|
{
|
|
|
|
/**
|
|
*/
|
|
async function reminder_due(
|
|
) : Promise<void>
|
|
{
|
|
type type_input = {
|
|
reminder : {
|
|
frequency : string;
|
|
offset : int;
|
|
from : int;
|
|
to : int;
|
|
};
|
|
datetime : lib_plankton.pit.type_datetime;
|
|
interval : int;
|
|
};
|
|
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",
|
|
{
|
|
}
|
|
);
|
|
for (const testcase of testcases)
|
|
{
|
|
_munin.helpers.test.start(testcase.name);
|
|
|
|
// execution
|
|
const result : boolean = _munin.logic.reminder_due(
|
|
{
|
|
"frequency": _munin.logic.frequency_decode(testcase.input.reminder.frequency),
|
|
"offset": testcase.input.reminder.offset,
|
|
"from": testcase.input.reminder.from,
|
|
"to": testcase.input.reminder.to,
|
|
},
|
|
{
|
|
"pit": lib_plankton.pit.from_datetime(testcase.input.datetime),
|
|
"interval": testcase.input.interval,
|
|
}
|
|
);
|
|
|
|
// assertions
|
|
if (result !== testcase.output)
|
|
{
|
|
_munin.helpers.test.fail(testcase.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
async function reminder_covers_event(
|
|
) : Promise<void>
|
|
{
|
|
type type_input = {
|
|
reminder : {
|
|
frequency : string;
|
|
offset : int;
|
|
from : int;
|
|
to : int;
|
|
};
|
|
event : {
|
|
begin : lib_plankton.pit.type_datetime;
|
|
};
|
|
datetime : lib_plankton.pit.type_datetime;
|
|
interval : int;
|
|
};
|
|
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",
|
|
{
|
|
}
|
|
);
|
|
|
|
for (const testcase of testcases)
|
|
{
|
|
_munin.helpers.test.start(testcase.name);
|
|
|
|
// execution
|
|
const result : boolean = _munin.logic.reminder_covers_event(
|
|
{
|
|
"frequency": _munin.logic.frequency_decode(testcase.input.reminder.frequency),
|
|
"offset": testcase.input.reminder.offset,
|
|
"from": testcase.input.reminder.from,
|
|
"to": testcase.input.reminder.to,
|
|
},
|
|
{
|
|
"title": "test",
|
|
"begin": testcase.input.event.begin,
|
|
"end": null,
|
|
"description": null,
|
|
"location": null,
|
|
"tags": null,
|
|
},
|
|
{
|
|
"pit": lib_plankton.pit.from_datetime(testcase.input.datetime),
|
|
}
|
|
);
|
|
|
|
// assertions
|
|
if (result !== testcase.output)
|
|
{
|
|
_munin.helpers.test.fail(testcase.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
export async function all(
|
|
) : Promise<void>
|
|
{
|
|
await reminder_due();
|
|
await reminder_covers_event();
|
|
}
|
|
|
|
}
|