diff --git a/Code/Mantid/Framework/API/src/Progress.cpp b/Code/Mantid/Framework/API/src/Progress.cpp index 6ce87bc61fea6c61d2a9e28cf5342c87a32d6359..541a967f94c68d2b7aa1c47c58d65959f23cd43a 100644 --- a/Code/Mantid/Framework/API/src/Progress.cpp +++ b/Code/Mantid/Framework/API/src/Progress.cpp @@ -83,6 +83,7 @@ void Progress::reportIncrement(int inc, const std::string& msg) void Progress::setNumSteps(int nsteps) { m_numSteps = nsteps; + if (m_numSteps <= 0) m_numSteps = 1; // Minimum of 1 m_step = (m_end-m_start) / (m_numSteps); int notifyStep = 1; m_notifyStep = (static_cast<int>(double(m_numSteps)*notifyStep/100/(m_end-m_start))); diff --git a/Code/Mantid/Framework/API/test/ProgressTextTest.h b/Code/Mantid/Framework/API/test/ProgressTextTest.h index a17bd6f9b2513ea985dd4747574a65433eadb7ed..e42392d45e3260ef50d3d58500764397c4108e44 100644 --- a/Code/Mantid/Framework/API/test/ProgressTextTest.h +++ b/Code/Mantid/Framework/API/test/ProgressTextTest.h @@ -8,6 +8,7 @@ #include <iomanip> #include <cstdlib> +#include "MantidAPI/Progress.h" #include "MantidAPI/ProgressText.h" using namespace Mantid::API; @@ -22,6 +23,16 @@ public: TS_ASSERT_THROWS_NOTHING(p.setNumSteps(100)); } + void test_constructors() + { + // No steps? + TS_ASSERT_THROWS_NOTHING(Progress p(NULL, 0.0, 1.0, 0); p.report(); ); + TS_ASSERT_THROWS_NOTHING(ProgressText p(0.0, 1.0, 0); ); + // Max is < min + TS_ASSERT_THROWS_NOTHING(Progress p(NULL, 1.0, 0.5, 10); p.report(); ); + TS_ASSERT_THROWS_NOTHING(ProgressText p(NULL, 1.0, 0.5, 10); ); + } + /// Disabled because it has text output void xtest_with_stdout()