Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/user/bugfix.single-step-progressbar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Single-step simulations now complete their progress indicator without dividing by zero.
2 changes: 1 addition & 1 deletion external/progressbar/include/progressbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ inline void progressbar::update() {
int perc = 0;

// compute percentage, if did not change, do nothing and return
perc = progress*100./(n_cycles-1);
perc = n_cycles == 1 ? 100 : progress*100./(n_cycles-1);
Comment thread
97gamjak marked this conversation as resolved.
if (perc < last_perc) return;

// update percentage each unit
Expand Down
6 changes: 6 additions & 0 deletions tests/src/utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(source_files
testStringUtilities.cpp
testMathUtilities.cpp
testCollectionUtilities.cpp
testProgressbar.cpp
)

foreach(source_file ${source_files})
Expand All @@ -27,6 +28,11 @@ foreach(source_file ${source_files})
set_property(TEST ${test_name} PROPERTY LABELS utilties)
endforeach()

target_include_directories(testProgressbar
PRIVATE
${PROJECT_SOURCE_DIR}/external/progressbar/include
)

if(${BUILD_WITH_GCOVR})
include(CodeCoverage)
setup_target_for_coverage_gcovr_html(
Expand Down
38 changes: 38 additions & 0 deletions tests/src/utilities/testProgressbar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*****************************************************************************
<GPL_HEADER>

PQ
Copyright (C) 2023-now Jakob Gamper

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

<GPL_HEADER>
******************************************************************************/

#include <gtest/gtest.h>

#include <sstream>
#include <string>

#include "progressbar.hpp"

TEST(TestProgressbar, singleIterationCompletes)
{
auto output = std::ostringstream();
auto bar = progressbar(1, true, output);

bar.update();

EXPECT_NE(output.str().find("100%"), std::string::npos);
}
Loading