/*
 * Verrückte Turing-Maschinen — A turing complete game
 * Copyright (C) 2016-2018 kcf <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/>.
 */

namespace mod_vtm
	{
		
		export namespace mod_model
			{
				
				export namespace 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;
											}
									}
							}
						
					}
				
			}
		
	}

