From adcbe4347ccd485a273f81687b8456c63784e0c3 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Tue, 9 Mar 2021 13:54:42 +0100 Subject: [PATCH] Fixed unit tests. --- src/libslic3r/Flow.cpp | 5 +++-- src/libslic3r/Flow.hpp | 3 ++- src/libslic3r/GCode.cpp | 3 ++- tests/fff_print/test_flow.cpp | 6 +++--- tests/fff_print/test_print.cpp | 14 +++++++------- tests/fff_print/test_printgcode.cpp | 13 +++++++------ 6 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/Flow.cpp b/src/libslic3r/Flow.cpp index 6e54a517ca..1645bf683a 100644 --- a/src/libslic3r/Flow.cpp +++ b/src/libslic3r/Flow.cpp @@ -150,6 +150,7 @@ Flow Flow::with_spacing(float new_spacing) const auto new_diameter = new_spacing - gap; out.m_width = out.m_height = new_diameter; } else { + assert(m_width >= m_height); out.m_width += new_spacing - m_spacing; if (out.m_width < out.m_height) throw Slic3r::InvalidArgument("Invalid spacing supplied to Flow::with_spacing()"); @@ -162,7 +163,7 @@ Flow Flow::with_spacing(float new_spacing) const Flow Flow::with_cross_section(float area_new) const { assert(! m_bridge); - assert(flow.width() >= flow.height()); + assert(m_width >= m_height); // Adjust for bridge_flow_ratio, maintain the extrusion spacing. float area = this->mm3_per_mm(); @@ -179,7 +180,7 @@ Flow Flow::with_cross_section(float area_new) const } else if (area_new < area - EPSILON) { // Decreasing the flow rate. float width_new = m_width - (area - area_new) / m_height; - assert(width_dif > 0); + assert(width_new > 0); if (width_new > m_height) { // Shrink the extrusion width. return this->with_width(width_new); diff --git a/src/libslic3r/Flow.hpp b/src/libslic3r/Flow.hpp index 937fb176ab..428d31c1f7 100644 --- a/src/libslic3r/Flow.hpp +++ b/src/libslic3r/Flow.hpp @@ -117,7 +117,8 @@ public: private: Flow(float width, float height, float spacing, float nozzle_diameter, bool bridge) : - m_width(width), m_height(height), m_spacing(spacing), m_nozzle_diameter(nozzle_diameter), m_bridge(bridge) {} + m_width(width), m_height(height), m_spacing(spacing), m_nozzle_diameter(nozzle_diameter), m_bridge(bridge) + { assert(width >= height); } float m_width { 0 }; float m_height { 0 }; diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index fd6c82b84f..28a68e1715 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1815,7 +1815,8 @@ namespace Skirt { // Extrude skirt at the print_z of the raft layers and normal object layers // not at the print_z of the interlaced support material layers. std::map> skirt_loops_per_extruder_out; - assert(skirt_done.empty()); + //For sequential print, the following test may fail when extruding the 2nd and other objects. + // assert(skirt_done.empty()); if (skirt_done.empty() && print.has_skirt() && ! print.skirt().entities.empty() && layer_tools.has_skirt) { skirt_loops_per_extruder_all_printing(print, layer_tools, skirt_loops_per_extruder_out); skirt_done.emplace_back(layer_tools.print_z); diff --git a/tests/fff_print/test_flow.cpp b/tests/fff_print/test_flow.cpp index b679a07e35..08ba15a84a 100644 --- a/tests/fff_print/test_flow.cpp +++ b/tests/fff_print/test_flow.cpp @@ -96,7 +96,7 @@ SCENARIO("Flow: Flow math for non-bridges", "[Flow]") { GIVEN("Nozzle Diameter of 0.4, a desired width of 1mm and layer height of 0.5") { ConfigOptionFloatOrPercent width(1.0, false); float nozzle_diameter = 0.4f; - float layer_height = 0.5f; + float layer_height = 0.4f; // Spacing for non-bridges is has some overlap THEN("External perimeter flow has spacing fixed to 1.125 * nozzle_diameter") { @@ -126,8 +126,8 @@ SCENARIO("Flow: Flow math for non-bridges", "[Flow]") { REQUIRE(flow.width() == Approx(1.125 * nozzle_diameter)); } } - WHEN("Layer height is set to 0.2") { - layer_height = 0.3f; + WHEN("Layer height is set to 0.25") { + layer_height = 0.25f; THEN("Min width is set.") { auto flow = Flow::new_from_config_width(frPerimeter, ConfigOptionFloatOrPercent(0, false), nozzle_diameter, layer_height); REQUIRE(flow.width() == Approx(1.125 * nozzle_diameter)); diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index 3250443ed0..fc2ac3dee2 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -53,8 +53,8 @@ SCENARIO("Print: Changing number of solid surfaces does not cause all surfaces t config.set_deserialize({ { "top_solid_layers", 2 }, { "bottom_solid_layers", 1 }, - { "layer_height", 0.5 }, // get a known number of layers - { "first_layer_height", 0.5 } + { "layer_height", 0.25 }, // get a known number of layers + { "first_layer_height", 0.25 } }); Slic3r::Print print; Slic3r::Model model; @@ -72,8 +72,8 @@ SCENARIO("Print: Changing number of solid surfaces does not cause all surfaces t }; print.process(); test_is_solid_infill(0, 0); // should be solid - test_is_solid_infill(0, 39); // should be solid - test_is_solid_infill(0, 38); // should be solid + test_is_solid_infill(0, 79); // should be solid + test_is_solid_infill(0, 78); // should be solid WHEN("Model is re-sliced with top_solid_layers == 3") { config.set("top_solid_layers", 3); print.apply(model, config); @@ -82,9 +82,9 @@ SCENARIO("Print: Changing number of solid surfaces does not cause all surfaces t test_is_solid_infill(0, 0); } AND_THEN("Print object has 3 top solid layers") { - test_is_solid_infill(0, 39); - test_is_solid_infill(0, 38); - test_is_solid_infill(0, 37); + test_is_solid_infill(0, 79); + test_is_solid_infill(0, 78); + test_is_solid_infill(0, 77); } } } diff --git a/tests/fff_print/test_printgcode.cpp b/tests/fff_print/test_printgcode.cpp index 10d3af9a31..d6f6eca58a 100644 --- a/tests/fff_print/test_printgcode.cpp +++ b/tests/fff_print/test_printgcode.cpp @@ -244,23 +244,24 @@ SCENARIO( "PrintGCode basic functionality", "[PrintGCode]") { { "complete_objects", true }, { "gcode_comments", true }, { "layer_gcode", ";Layer:[layer_num] ([layer_z] mm)" }, - { "layer_height", 1.0 }, - { "first_layer_height", 1.0 } + { "layer_height", 0.1 }, + { "first_layer_height", 0.1 } }); // End of the 1st object. - size_t pos = gcode.find(";Layer:19 "); + std::string token = ";Layer:199 "; + size_t pos = gcode.find(token); THEN("First and second object last layer is emitted") { // First object REQUIRE(pos != std::string::npos); - pos += 10; + pos += token.size(); REQUIRE(pos < gcode.size()); double z = 0; REQUIRE((sscanf(gcode.data() + pos, "(%lf mm)", &z) == 1)); REQUIRE(z == Approx(20.)); // Second object - pos = gcode.find(";Layer:39 ", pos); + pos = gcode.find(";Layer:399 ", pos); REQUIRE(pos != std::string::npos); - pos += 10; + pos += token.size(); REQUIRE(pos < gcode.size()); REQUIRE((sscanf(gcode.data() + pos, "(%lf mm)", &z) == 1)); REQUIRE(z == Approx(20.));