From e520454c3e1988c894399f138c863495505dec3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Thu, 9 Sep 2021 12:01:31 +0200 Subject: [PATCH] Fixed unit tests after the previous commit. --- t/combineinfill.t | 10 +++++++++- tests/fff_print/test_gcodewriter.cpp | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/t/combineinfill.t b/t/combineinfill.t index 925e5b11d..a19e817a1 100644 --- a/t/combineinfill.t +++ b/t/combineinfill.t @@ -36,7 +36,15 @@ plan tests => 8; $layer_infill{$self->Z} = 1; } } - $layers{$args->{Z}} = 1 if $cmd eq 'G1' && $info->{dist_Z} > 0; + # Previously, all G-code commands had a fixed number of decimal points with means with redundant zeros after decimal points. + # We changed this behavior and got rid of these redundant padding zeros, which caused this test to fail + # because the position in Z-axis is compared as a string, and previously, G-code contained the following two commands: + # "G1 Z5 F5000 ; lift nozzle" + # "G1 Z5.000 F7800.000" + # That has a different Z-axis position from the view of string comparisons of floating-point numbers. + # To correct the computation of the number of printed layers, even in the case of string comparisons of floating-point numbers, + # we filtered out the G-code command with the commend 'lift nozzle'. + $layers{$args->{Z}} = 1 if $cmd eq 'G1' && $info->{dist_Z} && index($info->{comment}, 'lift nozzle') == -1; }); my $layers_with_perimeters = scalar(keys %layer_infill); diff --git a/tests/fff_print/test_gcodewriter.cpp b/tests/fff_print/test_gcodewriter.cpp index a4c8aa09a..15ffaebb4 100644 --- a/tests/fff_print/test_gcodewriter.cpp +++ b/tests/fff_print/test_gcodewriter.cpp @@ -78,13 +78,13 @@ SCENARIO("set_speed emits values with fixed-point output.", "[GCodeWriter]") { } } WHEN("set_speed is called to set speed to 1") { - THEN("Output string is G1 F1.000") { - REQUIRE_THAT(writer.set_speed(1.0), Catch::Equals("G1 F1.000\n")); + THEN("Output string is G1 F1") { + REQUIRE_THAT(writer.set_speed(1.0), Catch::Equals("G1 F1\n")); } } WHEN("set_speed is called to set speed to 203.200022") { - THEN("Output string is G1 F203.200") { - REQUIRE_THAT(writer.set_speed(203.200022), Catch::Equals("G1 F203.200\n")); + THEN("Output string is G1 F203.2") { + REQUIRE_THAT(writer.set_speed(203.200022), Catch::Equals("G1 F203.2\n")); } } WHEN("set_speed is called to set speed to 203.200522") {