Skip to content

Commit

Permalink
Avoid signed/unsigned comparison.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 312716796
  • Loading branch information
hzeller committed May 21, 2020
1 parent cb07575 commit 1d466c0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions common/strings/range_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ TEST(ByteOffsetRangeTest, EmptyInEmpty) {

TEST(ByteOffsetRangeTest, RangeInvariant) {
const absl::string_view superstring("xxxxxxxx");
for (int i = 0; i < superstring.length(); ++i) {
for (int j = i; j < superstring.length(); ++j) {
for (size_t i = 0; i < superstring.length(); ++i) {
for (size_t j = i; j < superstring.length(); ++j) {
const auto substring = superstring.substr(i, j - i);
EXPECT_EQ(SubstringOffsets(substring, superstring), IntPair(i, j))
<< i << ", " << j;
Expand All @@ -60,8 +60,8 @@ TEST(ByteOffsetRangeTest, RangeInvariant) {
// Tests that swapping substring with superstring fails.
TEST(ByteOffsetRangeTest, InsideOut) {
const absl::string_view superstring("yyyyyyy");
for (int i = 0; i < superstring.length(); ++i) {
for (int j = i; j < superstring.length(); ++j) {
for (size_t i = 0; i < superstring.length(); ++i) {
for (size_t j = i; j < superstring.length(); ++j) {
const auto substring = superstring.substr(i, j - i);
EXPECT_DEATH(SubstringOffsets(superstring, substring), "")
<< i << ", " << j;
Expand All @@ -71,8 +71,8 @@ TEST(ByteOffsetRangeTest, InsideOut) {

TEST(ByteOffsetRangeTest, PartialOverlap) {
const absl::string_view superstring("zzzz");
for (int i = 0; i < superstring.length(); ++i) {
for (int j = 1; j < superstring.length(); ++j) {
for (size_t i = 0; i < superstring.length(); ++i) {
for (size_t j = 1; j < superstring.length(); ++j) {
const auto left = superstring.substr(0, i);
const auto right = superstring.substr(j);
EXPECT_DEATH(SubstringOffsets(left, right), "") << i << ", " << j;
Expand Down
12 changes: 6 additions & 6 deletions common/util/range_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ TEST(SubRangeIndicesTest, Empty) {

TEST(SubRangeIndicesTest, RangeInvariant) {
const std::vector<int> supersequence(5);
for (int i = 0; i < supersequence.size(); ++i) {
for (int j = i; j < supersequence.size(); ++j) {
for (size_t i = 0; i < supersequence.size(); ++i) {
for (size_t j = i; j < supersequence.size(); ++j) {
const auto subsequence =
make_range(supersequence.begin() + i, supersequence.begin() + j);
EXPECT_EQ(SubRangeIndices(subsequence, supersequence), IntPair(i, j))
Expand All @@ -191,8 +191,8 @@ TEST(SubRangeIndicesTest, RangeInvariant) {
// Tests that swapping subsequence with supersequence fails.
TEST(SubRangeIndicesTest, InsideOut) {
const std::vector<int> supersequence(5);
for (int i = 0; i < supersequence.size(); ++i) {
for (int j = i; j < supersequence.size(); ++j) {
for (size_t i = 0; i < supersequence.size(); ++i) {
for (size_t j = i; j < supersequence.size(); ++j) {
const auto subsequence =
make_range(supersequence.begin() + i, supersequence.begin() + j);
EXPECT_DEATH(SubRangeIndices(supersequence, subsequence), "")
Expand All @@ -203,8 +203,8 @@ TEST(SubRangeIndicesTest, InsideOut) {

TEST(SubRangeIndicesTest, PartialOverlap) {
const std::vector<int> v(4);
for (int i = 0; i < v.size(); ++i) {
for (int j = 1; j < v.size(); ++j) {
for (size_t i = 0; i < v.size(); ++i) {
for (size_t j = 1; j < v.size(); ++j) {
const auto left = make_range(v.begin(), v.begin() + i);
const auto right = make_range(v.begin() + j, v.end());
EXPECT_DEATH(SubRangeIndices(left, right), "") << i << ", " << j;
Expand Down

0 comments on commit 1d466c0

Please sign in to comment.