/* This file is part of »munin«. Copyright 2025 'Fenris Wolf' »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 . */ namespace _munin.test { /** * @todo outsource? */ function lists_equal( list1 : Array, list2 : Array ) : boolean { return ( (list1.length === list2.length) && list1.every( (element, index) => (element === list2[index]) ) ); } /** */ async function reminder_check( ) : Promise { type type_input = { reminder : { frequency : string; offset : int; from : int; to : int; }; events : Array< { title : string; begin : lib_plankton.pit.type_datetime; } >; datetime : lib_plankton.pit.type_datetime; interval : int; }; type type_output = (null | Array); const testcases : Array< _munin.helpers.test.type_testcase< type_input, type_output > > = await _munin.helpers.test.get_data( "data/reminder_check.testdata.json", { } ); for (const testcase of testcases) { _munin.helpers.test.start(testcase.name); // execution const result : (null | Array<_munin.type_event>) = _munin.logic.reminder_check( { "frequency": _munin.logic.frequency_decode(testcase.input.reminder.frequency), "offset": testcase.input.reminder.offset, "from": testcase.input.reminder.from, "to": testcase.input.reminder.to, }, testcase.input.events.map( event_raw => ({ "title": event_raw.title, "begin": event_raw.begin, "end": null, "description": null, "location": null, "tags": null, }) ), { "pit": lib_plankton.pit.from_datetime(testcase.input.datetime), "interval": testcase.input.interval, } ); // assertions if ( ( (testcase.output === null) && (result === null) ) || ( (testcase.output !== null) && lists_equal( result.map(event => event.title), testcase.output ) ) ) { // success } else { _munin.helpers.test.fail(testcase.name); } } } /** */ export async function all( ) : Promise { await reminder_check(); } }