mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 05:02:45 +01:00
Merge test/editor-track-golden into feat/editor-norms
# Conflicts: # application/editormodeselftestexpect.cpp
This commit is contained in:
@@ -223,6 +223,7 @@ editor_mode::selftest_result editor_mode::selftest_dispatch(std::string const &c
|
||||
// expect joint <track> <start|end> <gap m> <angle deg> <cant step mm> the end of the first path against the end of another track
|
||||
// nearest to it within 1 m: the gap, the kink and the step of the cant between them, each at most
|
||||
// expect records <name> <count> [kind] the records of the switch store of the name, with the connections having the switch among theirs
|
||||
// expect shaped <switch> <yes|no> the switch keeps the shape its record says, or was bent out of it
|
||||
// expect speed <track> <km/h> [tolerance], expect gauge <track> <m> [tolerance] as editor_track::velocity gives it / the gauge
|
||||
// expect track <name> <present|removed>
|
||||
// expect route <track> <in|out> the track is a part of the line open in the route tool, or not
|
||||
@@ -248,8 +249,13 @@ void editor_mode::selftest_step()
|
||||
std::ifstream stream(file);
|
||||
std::string line;
|
||||
while (std::getline(stream, line))
|
||||
if (false == line.empty() && line.front() != '#')
|
||||
test.lines.push_back(line);
|
||||
{
|
||||
// an indented comment or a line of blanks is no command either
|
||||
auto const first{line.find_first_not_of(" \t\r")};
|
||||
if (first == std::string::npos || line[first] == '#')
|
||||
continue;
|
||||
test.lines.push_back(line.substr(first));
|
||||
}
|
||||
WriteLog("SELFTEST: " + std::to_string(test.lines.size()) + " steps from " + file);
|
||||
}
|
||||
++editor_selftest::frames();
|
||||
|
||||
@@ -51,6 +51,13 @@ inline std::size_t &failures()
|
||||
return count;
|
||||
}
|
||||
|
||||
// a command whose subject isn't there, a track name mistyped, fails the run as an expectation does
|
||||
inline void fail()
|
||||
{
|
||||
++expectations();
|
||||
++failures();
|
||||
}
|
||||
|
||||
// apart from the 1 of a start which failed or of an error which ended the editor
|
||||
inline constexpr int failed_exit_code{2};
|
||||
|
||||
|
||||
@@ -186,6 +186,24 @@ void expect_records(std::string const &What, std::istringstream &Words)
|
||||
expectation(count == wanted, What, std::to_string(count), std::to_string(wanted));
|
||||
}
|
||||
|
||||
// expect shaped <switch> <yes|no>: the switch keeps the shape its record says, or was bent out of it
|
||||
void expect_shaped(std::string const &What, std::istringstream &Words)
|
||||
{
|
||||
std::string name;
|
||||
std::string wanted;
|
||||
Words >> name >> wanted;
|
||||
if (malformed(What, Words))
|
||||
return;
|
||||
auto const *track{simulation::Paths.find(name)};
|
||||
if (track == nullptr || track->m_editorremoved)
|
||||
{
|
||||
expectation(false, What, "no track " + name, "a switch");
|
||||
return;
|
||||
}
|
||||
auto const shaped{switch_store::of(*track).has_value()};
|
||||
expectation(shaped == (wanted == "yes"), What, shaped ? "yes" : "no", wanted);
|
||||
}
|
||||
|
||||
// expect speed <track> <km/h> [tolerance], expect gauge <track> <m> [tolerance]
|
||||
void expect_track_value(std::string const &What, std::string const &Kind, std::istringstream &Words)
|
||||
{
|
||||
@@ -385,6 +403,8 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
|
||||
expect_joint(what, words, &editor_mode::cant_of_roll);
|
||||
else if (kind == "records")
|
||||
expect_records(what, words);
|
||||
else if (kind == "shaped")
|
||||
expect_shaped(what, words);
|
||||
else if (kind == "speed" || kind == "gauge")
|
||||
expect_track_value(what, kind, words);
|
||||
else if (kind == "track")
|
||||
@@ -404,6 +424,6 @@ editor_mode::selftest_result editor_mode::selftest_expect(std::string const &com
|
||||
else if (kind == "steps")
|
||||
expect_steps(what, words, static_cast<std::size_t>(std::ranges::count_if(m_history, [](EditorSnapshot const &Step) { return false == Step.joined; })));
|
||||
else
|
||||
expectation(false, what, "no expectation " + kind, "cant, joint, records, speed, gauge, track, route, norms, findings, height, lift, includes, status or steps");
|
||||
expectation(false, what, "no expectation " + kind, "cant, joint, records, shaped, speed, gauge, track, route, norms, findings, height, lift, includes, status or steps");
|
||||
return selftest_result::handled;
|
||||
}
|
||||
|
||||
@@ -404,8 +404,15 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm
|
||||
double gauge{1500.0};
|
||||
std::string name;
|
||||
words >> gauge >> name;
|
||||
auto *track{name.empty() ? nullptr : simulation::Paths.find(name)};
|
||||
if (false == name.empty() && (track == nullptr || track->m_editorremoved))
|
||||
{
|
||||
editor_selftest::fail();
|
||||
WriteLog("SELFTEST FAIL routegauge: no track " + name);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
// the line of the track opened in the route tool, as a click on it with the tool does, unless it's in the line open already
|
||||
if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved && std::ranges::find(m_route.chain.tracks, track) == m_route.chain.tracks.end())
|
||||
if (track != nullptr && std::ranges::find(m_route.chain.tracks, track) == m_route.chain.tracks.end())
|
||||
{
|
||||
m_track_tab = track_tab::route;
|
||||
m_route.single = false;
|
||||
@@ -426,7 +433,8 @@ editor_mode::selftest_result editor_mode::selftest_track(std::string const &comm
|
||||
std::string reason;
|
||||
if (track == nullptr || track->m_editorremoved || index < 0 || index >= static_cast<int>(track->m_paths.size()) || false == editor_track::can_edit_geometry(*track, reason))
|
||||
{
|
||||
WriteLog("SELFTEST trackcant: no path " + name + " " + std::to_string(index) + " to edit " + reason);
|
||||
editor_selftest::fail();
|
||||
WriteLog("SELFTEST FAIL trackcant: no path " + name + " " + std::to_string(index) + " to edit " + reason);
|
||||
return selftest_result::handled;
|
||||
}
|
||||
// as the field of the inspector takes it: the rolls of the path set, then the edit committed with the track as it was before
|
||||
|
||||
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "application/editormode.h"
|
||||
#include "application/editoruilayer.h"
|
||||
#include "application/editormodeselftest.h"
|
||||
#include "application/editormodeshared.h"
|
||||
#include "editor/editorFormat.hpp"
|
||||
#include "editor/editorGeometry.hpp"
|
||||
@@ -2098,8 +2099,15 @@ editor_mode::selftest_result editor_mode::selftest_props(std::string const &Comm
|
||||
// the set made of the tracks, also of one, and the last of them selected, as the set stays the selection only with it
|
||||
m_track_set.clear();
|
||||
for (std::string name; Words >> name;)
|
||||
{
|
||||
if (auto *track{simulation::Paths.find(name)}; track != nullptr && false == track->m_editorremoved)
|
||||
{
|
||||
m_track_set.push_back(track);
|
||||
continue;
|
||||
}
|
||||
editor_selftest::fail();
|
||||
WriteLog("SELFTEST FAIL tracksetdelete: no track " + name);
|
||||
}
|
||||
m_node = m_track_set.empty() ? nullptr : m_track_set.back();
|
||||
m_track_point = {};
|
||||
ui()->set_node(m_node);
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
wait 5
|
||||
switchplace Rz_60E1-300-1:9 40 150 1 1
|
||||
expect records z1 1 switch
|
||||
expect shaped z1 yes
|
||||
# the end of the diverging path of z1 moved aside with the gizmo: z1 no longer has the shape its record says
|
||||
select z1
|
||||
gizmo begin translate 1 end
|
||||
gizmo offset 0.5 0 0
|
||||
gizmo end
|
||||
# the drag went through: without it the case would only delete a switch which kept its shape
|
||||
expect shaped z1 no
|
||||
expect records z1 1 switch
|
||||
deletetrack z1
|
||||
expect track z1 removed
|
||||
|
||||
@@ -1180,7 +1180,8 @@ TEST_CASE("alignment: the cant ramp the norms ask for, which a track laid on fro
|
||||
CHECK(alignment::cant_ramp_length(100.0, 120.0, gentle) == doctest::Approx(100.0));
|
||||
// the ramp is never shorter at a higher speed
|
||||
double previous{0.0};
|
||||
for (double speed = 20.0; speed <= 200.0; speed += 10.0) {
|
||||
for (int step{0}; step <= 18; ++step) {
|
||||
auto const speed{20.0 + 10.0 * step};
|
||||
auto const length{alignment::cant_ramp_length(speed, 80.0, norms)};
|
||||
CHECK(length >= previous);
|
||||
previous = length;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// the cant of the tracks the editor lays and joins: from mm to the roll of the paths and back, signed with the turn, and matched
|
||||
// across the joints of the tracks
|
||||
//
|
||||
// the inspector of the editor shows and takes the cant on a base of 1500 mm in lambdas of its own (application/editormodetrack.cpp);
|
||||
// named, as editor_mode::cant_of_roll() and roll_of_cant(), they come with the quick fixes of the track editing, and their tests with them
|
||||
// the inspector of the editor shows and takes the cant on a base of 1500 mm through editor_mode::cant_of_roll() and roll_of_cant()
|
||||
// (application/editormodetrack.cpp). They live in the editor, which the unit tests don't link, so the self-test cases check them
|
||||
// through the inspector: tests/editor/cases/1_inspector_cant.txt
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
|
||||
@@ -182,6 +182,22 @@ TEST_CASE("track text: what the game writes otherwise than it was given, the sam
|
||||
// what doesn't survive yet: each fails until it does, then doctest reports the test passing against should_fail, and the entry goes
|
||||
// over to the files of the entries which come out the same
|
||||
|
||||
// what those tests start from, checked apart from them: under should_fail a missing file or entry would pass for a loss
|
||||
TEST_CASE("track text: the entries known to be lost are there, with what they're about, and read") {
|
||||
track_reading const reading;
|
||||
struct known {
|
||||
char const *name;
|
||||
char const *about;
|
||||
};
|
||||
for (auto const &[name, about] : {known{"angles", " angle1 15 "}, known{"fouling", " fouling1 ukres_a "}, known{"tor1@iso1", "tor1@iso1"}, known{"digits", " digits "}}) {
|
||||
CAPTURE(name);
|
||||
auto const text{entry("known_lost.scn", name)};
|
||||
REQUIRE(false == text.empty());
|
||||
CHECK(text.find(about) != std::string::npos);
|
||||
CHECK(read_track(text) != nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("track text: the angles the ends are cut at are written back (known lost: read and dropped)" * doctest::should_fail()) {
|
||||
track_reading const reading;
|
||||
round_trip const trip{entry("known_lost.scn", "angles")};
|
||||
|
||||
Reference in New Issue
Block a user