vtm/source/model/tasks/test.ts
Christian Fraß 95ff0c95b3 restructuring
2018-03-29 01:13:39 +02:00

133 lines
3.2 KiB
TypeScript

/*
* Verrückte Turing-Maschinen — A turing complete game
* Copyright (C) 2016-2018 Christian Fraß <vidofnir@folksprak.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
module mod_vtm
{
export module mod_model
{
export module mod_test
{
/**
* @author kcf <vidofnir@folksprak.org>
*/
export type type_test = lib_call.type_complex<Object>;
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function input
(
test : type_test
)
: Array<mod_vtm.mod_model.mod_symbol.type_symbol>
{
return (
lib_call.distinguish<Array<mod_vtm.mod_model.mod_symbol.type_symbol>>
(
test,
{
"acceptortest": (data) => mod_acceptortest.input(data),
"transducertest": (data) => mod_transducertest.input(data),
}
)
);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function pruefen
(
test : type_test,
accepted : boolean,
ausgabe : Array<mod_vtm.mod_model.mod_symbol.type_symbol>
)
: boolean
{
return (
lib_call.distinguish<boolean>
(
test,
{
"acceptortest": (data) => mod_acceptortest.pruefen(data, accepted, ausgabe),
"transducertest": (data) => mod_transducertest.pruefen(data, accepted, ausgabe),
}
)
);
}
/**
* @author kcf <vidofnir@folksprak.org>
*/
export function import_
(
test_raw : any
)
: type_test
{
switch (test_raw["kind"])
{
case "acceptortest":
{
return {
"kind": "acceptortest",
"data": (
mod_acceptortest.create
(
test_raw["data"]["input"],
test_raw["data"]["accept"]
)
),
};
break;
}
case "transducertest":
{
return {
"kind": "transducertest",
"data": (
mod_transducertest.create
(
test_raw["data"]["input"],
test_raw["data"]["output"]
)
),
};
break;
}
default:
{
throw (new Error("unbehandelt"));
break;
}
}
}
}
}
}