From cb79de367413b5294c2d1694f688ab6187c6e420 Mon Sep 17 00:00:00 2001 From: Alexey Fedoseev Date: Thu, 25 Apr 2024 13:51:19 +0300 Subject: [PATCH] add legacy YED format tests --- tests/17-autoborder-legacy.cpp | 40 ++ tests/17-autoborder-legacy.test-input.graphml | 166 +++++ tests/17-output.graphml | 143 +++++ tests/17-output.txt | 1 + tests/18-orbita.cpp | 40 ++ tests/18-orbita.test-input.graphml | 588 ++++++++++++++++++ tests/18-output.graphml | 337 ++++++++++ tests/18-output.txt | 5 + 8 files changed, 1320 insertions(+) create mode 100644 tests/17-autoborder-legacy.cpp create mode 100644 tests/17-autoborder-legacy.test-input.graphml create mode 100644 tests/17-output.graphml create mode 100644 tests/17-output.txt create mode 100644 tests/18-orbita.cpp create mode 100644 tests/18-orbita.test-input.graphml create mode 100644 tests/18-output.graphml create mode 100644 tests/18-output.txt diff --git a/tests/17-autoborder-legacy.cpp b/tests/17-autoborder-legacy.cpp new file mode 100644 index 0000000..db16c73 --- /dev/null +++ b/tests/17-autoborder-legacy.cpp @@ -0,0 +1,40 @@ +/* ----------------------------------------------------------------------------- + * The Cyberiada GraphML C++ library implemention + * + * The test + * + * Copyright (C) 2024 Alexey Fedoseev + * + * 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/ + * ----------------------------------------------------------------------------- */ + +#include +#include "cyberiadamlpp.h" + +using namespace Cyberiada; +using namespace std; + +int main(int argc, char** argv) +{ + Document d; + try { + d.load(string(argv[0]) + "-input.graphml", formatLegacyYED); + cout << d << endl; + d.save(string(argv[0]) + ".graphml", formatCyberiada10); + } catch (const Cyberiada::Exception& e) { + cerr << e.str() << endl; + return 1; + } + return 0; +} diff --git a/tests/17-autoborder-legacy.test-input.graphml b/tests/17-autoborder-legacy.test-input.graphml new file mode 100644 index 0000000..6492ce8 --- /dev/null +++ b/tests/17-autoborder-legacy.test-input.graphml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Бой + entry/ + +exit/ + + + + + + + + + + + + + + + + + + Сближение + entry/ +МодульДвижения.ДвигатьсяКЦели() + +exit/ + + + + + + + + + + + Атака + entry/ +ОружиеЦелевое.АтаковатьЦель() + +exit/ + + + + + + + + + + + + + Скан + entry/ +Сенсор.ПоискВрагаПоДистанции(мин) + +exit/ +Сенсор.ОстановкаПоиска() + + + + + + + + + + + АнализаторЦели.ЦельПотеряна/ + + + + + + + + + + + АнализаторЦели.ЦельУничтожена/ + + + + + + + + + + + Сенсор.ЦельПолучена/ + + + + + + + + + + + ОружиеЦелевое.ЦельВошлаВЗонуАтаки/ + + + + + + + + + + + ОружиеЦелевое.ЦельВышлаИзЗоныАтаки/ + + + + + + + + + + + + + + + + + + diff --git a/tests/17-output.graphml b/tests/17-output.graphml new file mode 100644 index 0000000..086441f --- /dev/null +++ b/tests/17-output.graphml @@ -0,0 +1,143 @@ + + + Cyberiada-GraphML-1.0 + + + + + + + + + + + + + + + + + + + + + + Автобортник + + formal + CGML_META + standardVersion/ 1.0 + +name/ Автобортник + +transitionOrder/ transitionFirst + +eventPropagation/ block + + + + + initial + + + + + + + Бой + entry/ + +exit/ + + + + + + Сближение + entry/ +МодульДвижения.ДвигатьсяКЦели() + +exit/ + + + + + + Атака + entry/ +ОружиеЦелевое.АтаковатьЦель() + +exit/ + + + + + + + + Скан + entry/ +Сенсор.ПоискВрагаПоДистанции(мин) + +exit/ +Сенсор.ОстановкаПоиска() + + + + + + + АнализаторЦели.ЦельПотеряна/ + + + + + + + + + АнализаторЦели.ЦельУничтожена/ + + + + + + + + + Сенсор.ЦельПолучена/ + + + + + + + + + ОружиеЦелевое.ЦельВошлаВЗонуАтаки/ + + + + + + + + + ОружиеЦелевое.ЦельВышлаИзЗоныАтаки/ + + + + + + + + + + + + + + + + + diff --git a/tests/17-output.txt b/tests/17-output.txt new file mode 100644 index 0000000..32e3a81 --- /dev/null +++ b/tests/17-output.txt @@ -0,0 +1 @@ +Document: {id: '', name: 'Автобортник', format: 'yEd Berloga', meta: {standard version: '1.0', name: 'Автобортник', transition order: transition first, event propagation: block events}, elements: {State Machine: {id: 'G', name: 'Автобортник', elements: {Initial: {id: 'n1', name: '', geometry: (-1623; 753)}, Composite State: {id: 'n0', name: 'Бой', actions: {a {entry}, a {exit}}, geometry: (-786; 492; 517; 770), elements: {Simple State: {id: 'n0::n1', name: 'Сближение', actions: {a {entry, behavior: 'МодульДвижения.ДвигатьсяКЦели()'}, a {exit}}, geometry: (-788; 645; 413; 208)}, Simple State: {id: 'n0::n2', name: 'Атака', actions: {a {entry, behavior: 'ОружиеЦелевое.АтаковатьЦель()'}, a {exit}}, geometry: (-784; 311; 413; 208)}}}, Simple State: {id: 'n3', name: 'Скан', actions: {a {entry, behavior: 'Сенсор.ПоискВрагаПоДистанции(мин)'}, a {exit, behavior: 'Сенсор.ОстановкаПоиска()'}}, geometry: (-1573; 738; 413; 288)}, Transition: {id: 'n0-n3', source: 'n0', target: 'n3', action: {trigger: 'АнализаторЦели.ЦельПотеряна'}, sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0-n3#0', source: 'n0', target: 'n3', action: {trigger: 'АнализаторЦели.ЦельУничтожена'}, sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n3-n0::n1', source: 'n3', target: 'n0::n1', action: {trigger: 'Сенсор.ЦельПолучена'}, sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0::n1-n0::n2', source: 'n0::n1', target: 'n0::n2', action: {trigger: 'ОружиеЦелевое.ЦельВошлаВЗонуАтаки'}, sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0::n2-n0::n1', source: 'n0::n2', target: 'n0::n1', action: {trigger: 'ОружиеЦелевое.ЦельВышлаИзЗоныАтаки'}, sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n1-n3', source: 'n1', target: 'n3', sp: (0; 0), tp: (0; 0)}}}} diff --git a/tests/18-orbita.cpp b/tests/18-orbita.cpp new file mode 100644 index 0000000..db16c73 --- /dev/null +++ b/tests/18-orbita.cpp @@ -0,0 +1,40 @@ +/* ----------------------------------------------------------------------------- + * The Cyberiada GraphML C++ library implemention + * + * The test + * + * Copyright (C) 2024 Alexey Fedoseev + * + * 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/ + * ----------------------------------------------------------------------------- */ + +#include +#include "cyberiadamlpp.h" + +using namespace Cyberiada; +using namespace std; + +int main(int argc, char** argv) +{ + Document d; + try { + d.load(string(argv[0]) + "-input.graphml", formatLegacyYED); + cout << d << endl; + d.save(string(argv[0]) + ".graphml", formatCyberiada10); + } catch (const Cyberiada::Exception& e) { + cerr << e.str() << endl; + return 1; + } + return 0; +} diff --git a/tests/18-orbita.test-input.graphml b/tests/18-orbita.test-input.graphml new file mode 100644 index 0000000..6974524 --- /dev/null +++ b/tests/18-orbita.test-input.graphml @@ -0,0 +1,588 @@ + + + + + + + + + + + + + + + + + + + + + + + + + orientation + + +entry/ + + + + + + + + + + + get_shot + + + + + + + + + + + + + + + + + + + turn + + +entry/ +orientation.start_motor(AXIS_Z) + +exit/ +orientation.stop_motor(AXIS_Z) + + + + + + + + + + + get_shot + + + + + + + + + + + + + + + + + + slow_down + + +entry/ +reduce_speed() + + + + + + + + + + + + + + + start_turn + + +entry/ +calculate_turn() + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + finish_turn + + +entry/ +complete_turn() + + + + + + + + + + + + + + + + + idle + + +entry/ + + + + + + + + + + + + + + + + + wait + + +entry/ + + + + + + + + + + + + get_shot + + + + + + + + + + + + + + + + + + + maintain + + +entry/ +orientation.start_motor(AXIS_Z) + +exit/ +orientation.stop_motor(AXIS_Z) + + + + + + + + + + + get_shot + + + + + + + + + + + + + + + + + + correct_cw + + +entry/ +orientation.set_motor_moment(AXIS_Z, -M) + + + + + + + + + + + + + + + correct_ccw + + +entry/ +orientation.set_motor_moment(AXIS_Z, M) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + static + + +entry/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Init scripts: + +test3sm_constants.py +test3sm_orient.py + + + + + + + + + + + + + + + + + + + + + + + STOP + + + + + + + + + + + + + TANGENT(target_a) / +update_turn_parameters(target_a, 0.0) + + + + + + + + + + + + + BACK(target_a) / +update_turn_parameters(target_a, 180.0) + + + + + + + + + + + + + + + + + + + + + [completed()] + + + + + + + + + + + [completed()] + + + + + + + + + + + + + TIME_TICK [orientation_completed()] / +DISPATCH(cpu, 'ORIENTED') +DISPATCH(navigation, 'ORIENTED') + + + + + + + + + + + [orientation.get_angular_velocity(AXIS_Z) < DW] + + + + + + + + + + + [orientation.get_angular_velocity(AXIS_Z) > DW] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [completed()] + + + + + + + + + + + [is_target_dw()] + + + + + + + + + + + [not is_target_dw()] + + + + + + + + + diff --git a/tests/18-output.graphml b/tests/18-output.graphml new file mode 100644 index 0000000..87df41a --- /dev/null +++ b/tests/18-output.graphml @@ -0,0 +1,337 @@ + + + Cyberiada-GraphML-1.0 + + + + + + + + + + + + + + + + + + + + + + orientation + + formal + CGML_META + standardVersion/ 1.0 + +name/ orientation + +transitionOrder/ transitionFirst + +eventPropagation/ block + + + + + orientation + entry/ + + + + + + turn + entry/ +orientation.start_motor(AXIS_Z) + +exit/ +orientation.stop_motor(AXIS_Z) + + + + + + + slow_down + entry/ +reduce_speed() + + + + + + + start_turn + entry/ +calculate_turn() + + + + + + + initial + + + + + + + finish_turn + entry/ +complete_turn() + + + + + + + + + idle + entry/ + + + + + + wait + entry/ + + + + + + maintain + entry/ +orientation.start_motor(AXIS_Z) + +exit/ +orientation.stop_motor(AXIS_Z) + + + + + + + correct_cw + entry/ +orientation.set_motor_moment(AXIS_Z, -M) + + + + + + + correct_ccw + entry/ +orientation.set_motor_moment(AXIS_Z, M) + + + + + + + initial + + + + + + + + + static + entry/ + + + + + + initial + + + + + + + + + + + initial + + + + + + + informal + Init scripts: + +test3sm_constants.py +test3sm_orient.py + + + + + + + + + + + + + + STOP/ + + + + + + + + + + + + + TANGENT(target_a)/ +update_turn_parameters(target_a, 0.0) + + + + + + + + + + + + + BACK(target_a)/ +update_turn_parameters(target_a, 180.0) + + + + + + + + + + + + + + + + + + + + + [completed()]/ + + + + + + + + + [completed()]/ + + + + + + + + + TIME_TICK [orientation_completed()]/ +DISPATCH(cpu, 'ORIENTED') +DISPATCH(navigation, 'ORIENTED') + + + + + + + + + + + + + [orientation.get_angular_velocity(AXIS_Z) < DW]/ + + + + + + + + + [orientation.get_angular_velocity(AXIS_Z) > DW]/ + + + + + + + + + + + + + + + + + + + + + + + + + [completed()]/ + + + + + + + + + + + + [is_target_dw()]/ + + + + + + + + + [not is_target_dw()]/ + + + + + + + + + diff --git a/tests/18-output.txt b/tests/18-output.txt new file mode 100644 index 0000000..35319a1 --- /dev/null +++ b/tests/18-output.txt @@ -0,0 +1,5 @@ +Document: {id: '', name: 'orientation', format: 'yEd Ostranna', meta: {standard version: '1.0', name: 'orientation', transition order: transition first, event propagation: block events}, elements: {State Machine: {id: 'G', name: 'orientation', elements: {Composite State: {id: 'n0', name: 'orientation', actions: {a {entry}}, geometry: (409.905; 50.5953; 1149.48; 725.384), elements: {Composite State: {id: 'n0::n0', name: 'turn', actions: {a {entry, behavior: 'orientation.start_motor(AXIS_Z)'}, a {exit, behavior: 'orientation.stop_motor(AXIS_Z)'}}, geometry: (445.462; 97.7135; 297.495; 506.213), elements: {Simple State: {id: 'n0::n0::n0', name: 'slow_down', actions: {a {entry, behavior: 'reduce_speed()'}}, geometry: (460.462; 286.453; 267.495; 69.2119)}, Simple State: {id: 'n0::n0::n1', name: 'start_turn', actions: {a {entry, behavior: 'calculate_turn()'}}, geometry: (460.462; 396.384; 267.495; 69.2119)}, Initial: {id: 'n0::n0::n2', name: '', geometry: (594.209; 247.953)}, Simple State: {id: 'n0::n0::n3', name: 'finish_turn', actions: {a {entry, behavior: 'complete_turn()'}}, geometry: (460.462; 506.315; 267.495; 69.2119)}}}, Simple State: {id: 'n0::n1', name: 'idle', actions: {a {entry}}, geometry: (766.168; 103.962; 313.217; 117.952)}, Composite State: {id: 'n0::n2', name: 'wait', actions: {a {entry}}, geometry: (1102.6; 106.937; 432.213; 640.663), elements: {Composite State: {id: 'n0::n2::n0', name: 'maintain', actions: {a {entry, behavior: 'orientation.start_motor(AXIS_Z)'}, a {exit, behavior: 'orientation.stop_motor(AXIS_Z)'}}, geometry: (1121.6; 320.744; 393.6; 400.074), elements: {Simple State: {id: 'n0::n2::n0::n0', name: 'correct_cw', actions: {a {entry, behavior: 'orientation.set_motor_moment(AXIS_Z, -M)'}}, geometry: (1140.35; 479.237; 358.315; 75.3372)}, Simple State: {id: 'n0::n2::n0::n1', name: 'correct_ccw', actions: {a {entry, behavior: 'orientation.set_motor_moment(AXIS_Z, M)'}}, geometry: (1140.35; 624.163; 358.315; 75.3372)}, Initial: {id: 'n0::n2::n0::n2', name: '', geometry: (1319.51; 436.353)}}}, Simple State: {id: 'n0::n2::n1', name: 'static', actions: {a {entry}}, geometry: (1122.71; 201.439; 393.6; 75.3372)}, Initial: {id: 'n0::n2::n2', name: '', geometry: (1319.51; 158.554)}}}}}, Initial: {id: 'n1', name: '', geometry: (945.784; -25.4024)}, Comment: {id: 'n2', body: 'Init scripts: + +test3sm_constants.py +test3sm_orient.py', geometry: (445.462; 652.554; 160.084; 95.0456)}, Transition: {id: 'e0', source: 'n1', target: 'n0::n1', sp: (0; 0), tp: (23.0079; -7.04775)}, Transition: {id: 'e1', source: 'n0', target: 'n0::n1', action: {trigger: 'STOP'}, sp: (-157.872; -122.809), tp: (-4.11896; -7.29727), polyline: [ (826.77; -4.95139), (918.657; -4.95139) ]}, Transition: {id: 'n0::e0', source: 'n0::n1', target: 'n0::n0', action: {trigger: 'TANGENT(target_a)', behavior: 'update_turn_parameters(target_a, 0.0)'}, sp: (95.232; 21.0292), tp: (129.208; 23.5618), polyline: [ (1018.01; 374.382) ]}, Transition: {id: 'n0::e1', source: 'n0::n1', target: 'n0::n0', action: {trigger: 'BACK(target_a)', behavior: 'update_turn_parameters(target_a, 180.0)'}, sp: (113.643; 25.9294), tp: (148.774; 117.967), polyline: [ (1036.42; 468.787) ]}, Transition: {id: 'n0::n0::e0', source: 'n0::n0::n2', target: 'n0::n0::n0', sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0::n0::e1', source: 'n0::n0::n0', target: 'n0::n0::n1', action: {guard: 'completed()'}, sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0::n0::e2', source: 'n0::n0::n1', target: 'n0::n0::n3', action: {guard: 'completed()'}, sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0::e2', source: 'n0::n2', target: 'n0::n1', action: {trigger: 'TIME_TICK', guard: 'orientation_completed()', behavior: 'DISPATCH(cpu, 'ORIENTED') +DISPATCH(navigation, 'ORIENTED')'}, sp: (-216.094; 98.8431), tp: (128.22; 13.3933), polyline: [ (1051; 526.111) ]}, Transition: {id: 'n0::n2::n0::e0', source: 'n0::n2::n0::n0', target: 'n0::n2::n0::n1', action: {guard: 'orientation.get_angular_velocity(AXIS_Z) < DW'}, sp: (-154.389; 1.81038), tp: (-154.389; 5.48153)}, Transition: {id: 'n0::n2::n0::e1', source: 'n0::n2::n0::n1', target: 'n0::n2::n0::n0', action: {guard: 'orientation.get_angular_velocity(AXIS_Z) > DW'}, sp: (163.3; -10.0207), tp: (163.3; 1.09301)}, Transition: {id: 'n0::n2::n0::e2', source: 'n0::n2::n0::n2', target: 'n0::n2::n0::n0', sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0::n2::e0', source: 'n0::n2::n2', target: 'n0::n2::n1', sp: (0; 0), tp: (0; 0)}, Transition: {id: 'n0::e3', source: 'n0::n0::n3', target: 'n0::n2', action: {guard: 'completed()'}, sp: (71.4174; 14.495), tp: (-17.6166; 284.015), polyline: [ (665.627; 711.284) ]}, Transition: {id: 'n0::n2::e1', source: 'n0::n2::n0', target: 'n0::n2::n1', action: {guard: 'is_target_dw()'}, sp: (138.108; -80.2858), tp: (136.997; 11.0857)}, Transition: {id: 'n0::n2::e2', source: 'n0::n2::n1', target: 'n0::n2::n0', action: {guard: 'not is_target_dw()'}, sp: (-136.091; 13.4535), tp: (-134.98; -169.298)}}}}