Skip to content

Commit

Permalink
Make new tests documented
Browse files Browse the repository at this point in the history
  • Loading branch information
ntrel committed Nov 20, 2023
1 parent a2c2f79 commit bd67a0c
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions std/algorithm/searching.d
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,10 @@ template canFind(alias pred="a == b")
assert(!canFind(arr, 4));

// find one of several needles
assert([0, 1, 2, 3].canFind(3, 2));
assert([0, 1, 2, 3].canFind(3, 2) == 2); // second needle found
assert([0, 1, 2, 3].canFind([1, 3], 2) == 2);

assert(canFind(arr, [1, 2], [2, 3]));
assert(canFind(arr, [1, 2], [2, 3]) == 1);
assert(canFind(arr, [1, 7], [2, 3]));
Expand All @@ -2596,13 +2600,6 @@ template canFind(alias pred="a == b")
assert(canFind(arr, [1, 3], [2, 4]) == 0);
}

// More multiple needles
@safe unittest
{
assert([1, 2, 3].canFind(3, 2) == 2);
assert([1, 2, 3].canFind([1, 3], 2) == 2);
}

/**
* Example using a custom predicate.
* Note that the needle appears as the second argument of the predicate.
Expand Down

0 comments on commit bd67a0c

Please sign in to comment.