Skip to content

Commit

Permalink
Fix tests after speed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oir committed Nov 29, 2023
1 parent 2c96520 commit 87ab883
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
17 changes: 6 additions & 11 deletions demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ int main(int /*argc*/, char** /*argv*/) {
// completion in terms of #sentences but we are also interested in speed
// in terms of tokens per second.'
std::atomic<size_t> sents{0}, toks{0};
auto bar =
ProgressBar(&sents).total(1010).message("Sents").speed(1) |
Counter(&toks).message("Toks").speed(1);
auto bar = ProgressBar(&sents).total(1010).message("Sents").speed(1) |
Counter(&toks).message("Toks").speed(1);
bar.show();
for (int i = 0; i < 1010; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -102,11 +101,8 @@ int main(int /*argc*/, char** /*argv*/) {

{ // Progress bar with no-tty mode
std::atomic<size_t> sents{0}, toks{0};
auto bar = ProgressBar(&sents)
.total(20100)
.message("Sents")
.speed(1)
.no_tty();
auto bar =
ProgressBar(&sents).total(20100).message("Sents").speed(1).no_tty();
bar.show();
for (int i = 0; i < 20100; i++) {
std::this_thread::sleep_for(13ms);
Expand All @@ -118,9 +114,8 @@ int main(int /*argc*/, char** /*argv*/) {

{ // Composite display of a ProgressBar and Counter with no-tty mode
std::atomic<size_t> sents{0}, toks{0};
auto bar =
ProgressBar(&sents).total(20100).message("Sents") |
Counter(&toks).message("Toks").speed_unit("tok/s").speed(1);
auto bar = ProgressBar(&sents).total(20100).message("Sents") |
Counter(&toks).message("Toks").speed_unit("tok/s").speed(1);
bar.no_tty();
bar.show();
for (int i = 0; i < 20100; i++) {
Expand Down
8 changes: 2 additions & 6 deletions meanwhile/meanwhile.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ class Counter : public AsyncDisplay {
}
};


// Class: ProgressBar
// Displays a progress bar, by comparing the progress value being monitored to a
// given total value. Optionally reports speed.
Expand All @@ -549,7 +548,7 @@ class ProgressBar : public AsyncDisplay {

Progress* progress_; // work done so far
std::unique_ptr<Speedometer<Progress>> speedom_;
std::string speed_unit_ = "it/s"; // unit of speed text next to speed
std::string speed_unit_ = "it/s"; // unit of speed text next to speed
static constexpr size_t width_ = 30; // width of progress bar
// (TODO: make customizable?)
ValueType total_{100}; // total work
Expand Down Expand Up @@ -631,9 +630,7 @@ class ProgressBar : public AsyncDisplay {
}

protected:
void init(Progress* progress) {
progress_ = progress;
}
void init(Progress* progress) { progress_ = progress; }

ProgressBar(std::ostream& out = std::cout) : AsyncDisplay(out) {}

Expand Down Expand Up @@ -741,7 +738,6 @@ class ProgressBar : public AsyncDisplay {
}
};


} // namespace mew

#endif
11 changes: 4 additions & 7 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ TEMPLATE_LIST_TEST_CASE("Counter constant", "[counter]", ProgressTypeList) {
using ValueType = value_t<TestType>;

TestType amount{GENERATE(as<ValueType>(), 0, 3)};
auto sp = GENERATE(Speed::None, Speed::Last);
auto sp = GENERATE(as<std::optional<double>>(), std::nullopt, 1);
std::string unit = GENERATE("", "thing/10ms");

auto ctr = Counter(&amount, out)
Expand All @@ -103,7 +103,7 @@ TEMPLATE_LIST_TEST_CASE("Counter constant", "[counter]", ProgressTypeList) {
std::string amountstr = ss.str();

std::string expected = "Doing things " + amountstr + " ";
if (sp == Speed::Last) {
if (sp == 1.) {
if (unit.empty()) {
expected += "(0.00) ";
} else {
Expand Down Expand Up @@ -135,7 +135,7 @@ TEMPLATE_LIST_TEST_CASE("Counter", "[counter]", ProgressTypeList) {

TestType amount{GENERATE(as<ValueType>(), 0, 3)};
ValueType initial = amount;
auto sp = GENERATE(Speed::None, Speed::Last);
auto sp = GENERATE(as<std::optional<double>>(), std::nullopt, 1);
bool no_tty = GENERATE(true, false);
std::string unit = GENERATE("", "thing/10ms");

Expand Down Expand Up @@ -363,10 +363,7 @@ TEST_CASE("Composite bar-counter", "[composite]") {
.message("Sents")
.style(Bars)
.interval(0.01) |
Counter(&toks, out)
.message("Toks")
.speed_unit("tok/s")
.speed(Speed::Last);
Counter(&toks, out).message("Toks").speed_unit("tok/s").speed(1);
bar.show();
for (int i = 0; i < 505; i++) {
std::this_thread::sleep_for(0.13ms);
Expand Down

0 comments on commit 87ab883

Please sign in to comment.