Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 640838 | Differences between
and this patch

Collapse All | Expand All

(-)a/CMakeLists.txt (-3 lines)
Lines 110-118 set(engine_SRCS # Except main.cpp. Link Here
110
)
125
)
111
126
112
# List of tests. For each test there must be a file tests/${NAME}.cpp and a file tests/${NAME}.h.
127
# List of tests. For each test there must be a file tests/${NAME}.cpp and a file tests/${NAME}.h.
113
set(engine_TEST
114
    GCodePlannerTest
115
)
116
set(engine_TEST_INFILL
128
set(engine_TEST_INFILL
117
)
129
)
118
set(engine_TEST_UTILS
130
set(engine_TEST_UTILS
(-)a/tests/GCodePlannerTest.cpp (-99 lines)
Lines 1-99 Link Here
1
//Copyright (c) 2015 Ultimaker B.V.
2
//CuraEngine is released under the terms of the AGPLv3 or higher.
3
4
#include "GCodePlannerTest.h"
5
6
#include "../src/MeshGroup.h" //Needed to construct the GCodePlanner.
7
8
#define ALLOWED_ESTIMATE_ERROR 0.1 //Fraction of the time estimates that the estimate is allowed to be off from the ground truth.
9
10
namespace cura
11
{
12
13
CPPUNIT_TEST_SUITE_REGISTRATION(GCodePlannerTest);
14
15
void GCodePlannerTest::setUp()
16
{
17
    SettingsBase settings;
18
    settings.setSetting("machine_extruder_count", "1");
19
    MeshGroup meshgroup(&settings);
20
    meshgroup.createExtruderTrain(0);
21
22
    storage = new SliceDataStorage(&meshgroup); //Empty data.
23
    storage->retraction_config_per_extruder[0].speed = 25; // set some semi realistic data
24
    storage->retraction_config_per_extruder[0].primeSpeed = 25;
25
    storage->retraction_config_per_extruder[0].distance = 10;
26
27
    // make a new GCodePathConfig and put it at a dummy place (note that the config is not an actual travel config!)
28
    storage->travel_config_per_extruder.emplace_back(PrintFeatureType::MoveCombing);
29
    storage->travel_config_per_extruder.back().init(60, MM2INT(0.4), 3000, 20, 1.0);
30
31
    FanSpeedLayerTimeSettings fan_speed_layer_time_settings; //A dummy fan speed and layer time settings.
32
    fan_speed_layer_time_settings.cool_min_layer_time = 0;
33
    fan_speed_layer_time_settings.cool_min_layer_time_fan_speed_max = 1;
34
    fan_speed_layer_time_settings.cool_fan_speed_min = 0;
35
    fan_speed_layer_time_settings.cool_fan_speed_max = 1;
36
    fan_speed_layer_time_settings.cool_min_speed = 0.5;
37
    std::vector<FanSpeedLayerTimeSettings> fan_speed_layer_time_settings_per_extruder;
38
    fan_speed_layer_time_settings_per_extruder.push_back(fan_speed_layer_time_settings);
39
    //                              Slice     layer  z  layer   last        current   is inside  fan speed and layer                        combing           comb    travel  travel avoid
40
    //                              storage   nr        height  position    extruder  mesh       time settings                              mode              offset  avoid   distance
41
    gCodePlanner = new GCodePlanner(*storage, 0,     0, 0.1,    Point(0,0), 0,        false,     fan_speed_layer_time_settings_per_extruder, CombingMode::OFF, 100,    false,  50          );
42
}
43
44
void GCodePlannerTest::tearDown()
45
{
46
    delete gCodePlanner;
47
    gCodePlanner = nullptr;
48
    delete storage;
49
    storage = nullptr;
50
}
51
52
void GCodePlannerTest::computeNaiveTimeEstimatesRetractionTest()
53
{
54
55
    TimeMaterialEstimates estimate_empty = gCodePlanner->computeNaiveTimeEstimates(); //First try estimating time and material without any content.
56
    TimeMaterialEstimates estimate_empty_expected(0,0,0,0); //We expect the estimate of all time and material used to be 0.
57
    verifyEstimates(estimate_empty,estimate_empty_expected,"Empty GCodePlanner");
58
    
59
    GCodeExport gcode;
60
    GCodePathConfig configuration = storage->travel_config_per_extruder.back();
61
    RetractionConfig retraction_config = storage->retraction_config_per_extruder.back();
62
    gCodePlanner->addExtrusionMove(Point(0, 0), &configuration, SpaceFillType::Lines, 1.0f); //Need to have at least one path to have a configuration.
63
    GCodePath* travel_path = gCodePlanner->getLatestPathWithConfig(&configuration, SpaceFillType::None);
64
    gCodePlanner->addTravel_simple(Point(10, 0), travel_path);
65
    TimeMaterialEstimates before_retract = gCodePlanner->computeNaiveTimeEstimates();
66
    travel_path->retract = true;
67
    TimeMaterialEstimates after_retract = gCodePlanner->computeNaiveTimeEstimates();
68
    TimeMaterialEstimates estimate_one_retraction = after_retract - before_retract;
69
    double retract_unretract_time = retraction_config.distance / retraction_config.primeSpeed;
70
    TimeMaterialEstimates estimate_one_retraction_expected(0,retract_unretract_time * 0.5,retract_unretract_time * 0.5,0);
71
    verifyEstimates(estimate_one_retraction,estimate_one_retraction_expected,"One retraction");
72
}
73
74
void GCodePlannerTest::verifyEstimates(const TimeMaterialEstimates& observed,const TimeMaterialEstimates& expected,std::string test_description)
75
{
76
    //Check each of the four estimates in the TimeMaterialEstimate instances.
77
    {
78
        std::stringstream ss;
79
        ss << test_description << ": Extrude time is " << observed.getExtrudeTime() << " instead of the expected " << expected.getExtrudeTime();
80
        CPPUNIT_ASSERT_MESSAGE(ss.str(),observed.getExtrudeTime() - expected.getExtrudeTime() < expected.getExtrudeTime() * ALLOWED_ESTIMATE_ERROR + 0.001);
81
    }
82
    {
83
        std::stringstream ss;
84
        ss << test_description << ": Unretracted travel time is " << (observed.getTotalUnretractedTime() - observed.getExtrudeTime()) << " instead of the expected " << (expected.getTotalUnretractedTime() - expected.getExtrudeTime());
85
        CPPUNIT_ASSERT_MESSAGE(ss.str(),observed.getTotalUnretractedTime() - observed.getExtrudeTime() - (expected.getTotalUnretractedTime() - expected.getExtrudeTime()) < (expected.getTotalUnretractedTime() - expected.getExtrudeTime()) * ALLOWED_ESTIMATE_ERROR + 0.001);
86
    }
87
    {
88
        std::stringstream ss;
89
        ss << test_description << ": Retracted travel time is " << (observed.getTotalTime() - observed.getTotalUnretractedTime()) << " instead of the expected " << (expected.getTotalTime() - expected.getTotalUnretractedTime());
90
        CPPUNIT_ASSERT_MESSAGE(ss.str(),observed.getTotalTime() - observed.getTotalUnretractedTime() - (expected.getTotalTime() - expected.getTotalUnretractedTime()) < (expected.getTotalTime() - expected.getTotalUnretractedTime()) * ALLOWED_ESTIMATE_ERROR + 0.001);
91
    }
92
    {
93
        std::stringstream ss;
94
        ss << test_description << ": Material used is " << observed.getMaterial() << " instead of the expected " << expected.getMaterial();
95
        CPPUNIT_ASSERT_MESSAGE(ss.str(),observed.getMaterial() - expected.getMaterial() < expected.getMaterial() * ALLOWED_ESTIMATE_ERROR + 0.001);
96
    }
97
}
98
99
}
(-)a/tests/GCodePlannerTest.h (-76 lines)
Lines 1-76 Link Here
1
//Copyright (c) 2015 Ultimaker B.V.
2
//CuraEngine is released under the terms of the AGPLv3 or higher.
3
4
#ifndef GCODEPLANNERTEST_H
5
#define GCODEPLANNERTEST_H
6
7
#include <cppunit/TestFixture.h>
8
#include <cppunit/extensions/HelperMacros.h>
9
10
#include "../src/gcodePlanner.h"
11
#include "../src/sliceDataStorage.h"
12
13
namespace cura
14
{
15
16
class GCodePlannerTest : public CppUnit::TestFixture
17
{
18
    CPPUNIT_TEST_SUITE(GCodePlannerTest);
19
    CPPUNIT_TEST(computeNaiveTimeEstimatesRetractionTest);
20
    CPPUNIT_TEST_SUITE_END();
21
    
22
public:
23
    /*!
24
     * \brief Sets up the test suite to prepare for testing.
25
     * 
26
     * This creates an instance of <em>gcodePlanner</em>, ready for filling with
27
     * data.
28
     */
29
    void setUp();
30
31
    /*!
32
     * \brief Tears down the test suite when testing is done.
33
     * 
34
     * This destroys the <em>gcodePlanner</em> instance.
35
     */
36
    void tearDown();
37
    
38
    //The actual test cases.
39
    void computeNaiveTimeEstimatesRetractionTest();
40
    
41
private:
42
    /*!
43
     * \brief The instance of gcodePlanner that can be used for testing.
44
     * 
45
     * This instance is re-created for each test. Between tests it will be
46
     * <em>nullptr</em>.
47
     */
48
    GCodePlanner* gCodePlanner;
49
    
50
    /*!
51
     * \brief Slice data storage to construct the <em>GCodePlanner</em> with.
52
     * 
53
     * It also holds configurations for the paths to add to the
54
     * <em>GCodePlanner</em>.
55
     */
56
    SliceDataStorage* storage;
57
    
58
    /*!
59
     * \brief Asserts that the two time material estimates are equal.
60
     * 
61
     * If they are not equal, the error messages are formulated according to the
62
     * specified observed results versus the specified expected results. It will
63
     * include a specified string describing what test it was.
64
     * 
65
     * \param observed The observed time material estimates.
66
     * \param expected The expected (true) time material estimates.
67
     * \param test_description A description of the test that was performed to
68
     * get the observed results.
69
     */
70
    void verifyEstimates(const TimeMaterialEstimates& observed,const TimeMaterialEstimates& expected,std::string test_description);
71
};
72
73
}
74
75
#endif // GCODEPLANNERTEST_H
76
(-)a/tests/runtest.py (-1 / +4 lines)
Lines 235-245 class Setting: Link Here
235
            tree = ast.parse(code, "eval")
235
            tree = ast.parse(code, "eval")
236
            compiled = compile(code, self._key, "eval")
236
            compiled = compile(code, self._key, "eval")
237
        except (SyntaxError, TypeError) as e:
237
        except (SyntaxError, TypeError) as e:
238
            print("Parse error in function (" + code + ") for setting", self._key + ":", str(e))
238
            print("Parse error in function (" + str(code) + ") for setting", self._key + ":", str(e))
239
            return None
239
        except IllegalMethodError as e:
240
        except IllegalMethodError as e:
240
            print("Use of illegal method", str(e), "in function (" + code + ") for setting", self._key)
241
            print("Use of illegal method", str(e), "in function (" + code + ") for setting", self._key)
242
            return None
241
        except Exception as e:
243
        except Exception as e:
242
            print("Exception in function (" + code + ") for setting", self._key + ":", str(e))
244
            print("Exception in function (" + code + ") for setting", self._key + ":", str(e))
245
            return None
243
246
244
        return eval(compiled, globals(), locals)
247
        return eval(compiled, globals(), locals)
245
248
246
namespace cura
249
namespace cura
247
{
250
{
248
    CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);
251
    CPPUNIT_TEST_SUITE_REGISTRATION(StringTest);

Return to bug 640838