Skip to content

Commit aaf8c50

Browse files
committed
unittest: Use range-for-loops
Signed-off-by: Stefan Weil <[email protected]>
1 parent 631882a commit aaf8c50

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

unittest/linlsq_test.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class LLSQTest : public testing::Test {
3030
}
3131
FCOORD PtsMean(const std::vector<FCOORD>& pts) {
3232
FCOORD total(0, 0);
33-
for (size_t i = 0; i < pts.size(); i++) {
34-
total += pts[i];
33+
for (const auto& p : pts) {
34+
total += p;
3535
}
3636
return (pts.size() > 0) ? total / pts.size() : total;
3737
}
@@ -41,9 +41,9 @@ class LLSQTest : public testing::Test {
4141
FCOORD nvec = !orth;
4242
nvec.normalise();
4343
double expected_answer = 0;
44-
for (size_t i = 0; i < pts.size(); i++) {
45-
llsq.add(pts[i].x(), pts[i].y());
46-
double dot = nvec % (pts[i] - xavg);
44+
for (const auto& p : pts) {
45+
llsq.add(p.x(), p.y());
46+
double dot = nvec % (p - xavg);
4747
expected_answer += dot * dot;
4848
}
4949
expected_answer /= pts.size();

unittest/stringrenderer_test.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
#include <memory>
1313
#include <string>
1414

15-
#include "absl/strings/str_split.h" // for absl::StrSplit
15+
#include "absl/strings/str_split.h" // for absl::StrSplit
1616

17-
#include "include_gunit.h"
1817
#include "allheaders.h"
1918
#include "boxchar.h"
2019
#include "boxread.h"
2120
#include "commandlineflags.h"
2221
#include "genericvector.h"
22+
#include "include_gunit.h"
2323
#include "stringrenderer.h"
2424
#include "strngs.h"
2525

@@ -65,9 +65,9 @@ class StringRendererTest : public ::testing::Test {
6565
if (!FLAGS_display) return;
6666
const std::vector<BoxChar*>& boxchars = renderer_->GetBoxes();
6767
Boxa* boxes = boxaCreate(0);
68-
for (size_t i = 0; i < boxchars.size(); ++i) {
69-
if (boxchars[i]->box())
70-
boxaAddBox(boxes, const_cast<Box*>(boxchars[i]->box()), L_CLONE);
68+
for (const auto& boxchar : boxchars) {
69+
if (boxchar->box())
70+
boxaAddBox(boxes, const_cast<Box*>(boxchar->box()), L_CLONE);
7171
}
7272
Pix* box_pix = pixDrawBoxaRandom(pix, boxes, 1);
7373
boxaDestroy(&boxes);
@@ -203,8 +203,8 @@ TEST_F(StringRendererTest, DoesRenderLigatures) {
203203

204204
static int FindBoxCharXCoord(const std::vector<BoxChar*>& boxchars,
205205
const std::string& ch) {
206-
for (size_t i = 0; i < boxchars.size(); ++i) {
207-
if (boxchars[i]->ch() == ch) return boxchars[i]->box()->x;
206+
for (const auto& boxchar : boxchars) {
207+
if (boxchar->ch() == ch) return boxchar->box()->x;
208208
}
209209
return INT_MAX;
210210
}
@@ -223,8 +223,7 @@ TEST_F(StringRendererTest, ArabicBoxcharsInLTROrder) {
223223
EXPECT_TRUE(ReadMemBoxes(0, false, boxes_str.c_str(), false, nullptr, &texts,
224224
nullptr, nullptr));
225225
std::string ltr_str;
226-
for (int i = 0; i < texts.size(); ++i)
227-
ltr_str += texts[i].string();
226+
for (int i = 0; i < texts.size(); ++i) ltr_str += texts[i].string();
228227
// The string should come out perfectly reversed, despite there being a
229228
// ligature.
230229
EXPECT_EQ(ltr_str, kRevWord);
@@ -364,7 +363,8 @@ TEST_F(StringRendererTest, DoesRenderWordBoxes) {
364363
renderer_->RenderToImage(kEngText, strlen(kEngText), &pix));
365364
pixDestroy(&pix);
366365
// Verify #boxchars = #words + #spaces
367-
std::vector<std::string> words = absl::StrSplit(kEngText, ' ', absl::SkipEmpty());
366+
std::vector<std::string> words =
367+
absl::StrSplit(kEngText, ' ', absl::SkipEmpty());
368368
const int kNumSpaces = words.size() - 1;
369369
const int kExpectedNumBoxes = words.size() + kNumSpaces;
370370
const std::vector<BoxChar*>& boxchars = renderer_->GetBoxes();

0 commit comments

Comments
 (0)