|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift.org open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2019 - 2020 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See https://swift.org/LICENSE.txt for license information
|
@@ -187,3 +187,26 @@ TEST(IndexSubset, Insertion) {
|
187 | 187 | EXPECT_EQ(indices1->adding(3, ctx.Ctx),
|
188 | 188 | IndexSubset::get(ctx.Ctx, 5, {0, 2, 3, 4}));
|
189 | 189 | }
|
| 190 | + |
| 191 | +TEST(IndexSubset, FindNext) { |
| 192 | + TestContext ctx; |
| 193 | + auto *indices1 = IndexSubset::get(ctx.Ctx, 5, {1, 2, 4}); |
| 194 | + EXPECT_EQ(indices1->findFirst(), 1); |
| 195 | + EXPECT_EQ(indices1->findNext(/*startIndex*/ -1), 1); |
| 196 | + EXPECT_EQ(indices1->findNext(/*startIndex*/ 0), 1); |
| 197 | + EXPECT_EQ(indices1->findNext(/*startIndex*/ 1), 2); |
| 198 | + EXPECT_EQ(indices1->findNext(/*startIndex*/ 2), 4); |
| 199 | + EXPECT_EQ(indices1->findNext(/*startIndex*/ 3), 4); |
| 200 | +} |
| 201 | + |
| 202 | +TEST(IndexSubset, FindPrevious) { |
| 203 | + TestContext ctx; |
| 204 | + auto *indices1 = IndexSubset::get(ctx.Ctx, 5, {0, 2, 4}); |
| 205 | + EXPECT_EQ(indices1->findLast(), 4); |
| 206 | + EXPECT_EQ(indices1->findPrevious(/*endIndex*/ 5), 4); |
| 207 | + EXPECT_EQ(indices1->findPrevious(/*endIndex*/ 4), 2); |
| 208 | + EXPECT_EQ(indices1->findPrevious(/*endIndex*/ 3), 2); |
| 209 | + EXPECT_EQ(indices1->findPrevious(/*endIndex*/ 2), 0); |
| 210 | + EXPECT_EQ(indices1->findPrevious(/*endIndex*/ 1), 0); |
| 211 | + EXPECT_EQ(indices1->findPrevious(/*endIndex*/ 0), -1); |
| 212 | +} |
0 commit comments