From f25b2b0d6890f302e4caa8ed5a6365fb19822468 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 20 Mar 2021 22:35:29 -0500 Subject: [PATCH] Tests for fan rescaling based on fan_percentage --- tests/fff_print/test_gcodewriter.cpp | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/fff_print/test_gcodewriter.cpp b/tests/fff_print/test_gcodewriter.cpp index d533aa5ad..5b569beb1 100644 --- a/tests/fff_print/test_gcodewriter.cpp +++ b/tests/fff_print/test_gcodewriter.cpp @@ -94,3 +94,43 @@ SCENARIO("set_speed emits values with fixed-point output.", "[GCodeWriter]") { } } } + +SCENARIO("set_fan rescales based on fan_percentage.", "[GCode][GCodeWriter]") { + GIVEN("GCodeWriter instance with comments off and RepRap flavor") { + GCodeWriter writer; + writer.config.gcode_comments.value = false; + writer.config.gcode_flavor.value = gcfRepRap; + WHEN("set_fan is called to set speed to 100\% with fan_percentage = true") { + writer.config.fan_percentage.value = true; + THEN("Fan value is set to 100.") { + REQUIRE_THAT(writer.set_fan(100, true), Catch::Equals("M106 S100\n")); + } + AND_WHEN("Fan value is set to 93\%") { + THEN("Output string is 'M106 S93'") { + REQUIRE_THAT(writer.set_fan(93, true), Catch::Equals("M106 S93\n")); + } + } + AND_WHEN("Fan value is set to 21\%") { + THEN("Output string is 'M106 S21'") { + REQUIRE_THAT(writer.set_fan(21, true), Catch::Equals("M106 S21\n")); + } + } + } + WHEN("set_fan is called to set speed to 100\% with fan_percentage = false") { + writer.config.fan_percentage.value = false; + THEN("Output string is 'M106 S255'") { + REQUIRE_THAT(writer.set_fan(100, true), Catch::Equals("M106 S255\n")); + } + AND_WHEN("Fan value is set to 93\%") { + THEN("Output string is 'M106 S237'") { + REQUIRE_THAT(writer.set_fan(93, true), Catch::Equals("M106 S237.15\n")); + } + } + AND_WHEN("Fan value is set to 21\%") { + THEN("Output string is 'M106 S54'") { + REQUIRE_THAT(writer.set_fan(21, true), Catch::Equals("M106 S53.55\n")); + } + } + } + } +}