mirror of
https://github.com/dlang/phobos.git
synced 2025-04-30 23:20:29 +03:00
examples of algorithm usage
This commit is contained in:
parent
3f521ca8eb
commit
c0032f9e2f
1 changed files with 17 additions and 11 deletions
|
@ -5822,9 +5822,9 @@ if (is(typeof(binaryFun!pred(r1.front, r2.front))))
|
||||||
return r2.empty ? (r1 = r, true) : false;
|
return r2.empty ? (r1 = r, true) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
//scope(success) writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
|
||||||
auto s1 = "Hello world";
|
auto s1 = "Hello world";
|
||||||
assert(!skipOver(s1, "Ha"));
|
assert(!skipOver(s1, "Ha"));
|
||||||
assert(s1 == "Hello world");
|
assert(s1 == "Hello world");
|
||||||
|
@ -5851,6 +5851,7 @@ if (is(typeof(binaryFun!pred(r.front, e))))
|
||||||
: false;
|
: false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
unittest {
|
unittest {
|
||||||
auto s1 = "Hello world";
|
auto s1 = "Hello world";
|
||||||
assert(!skipOver(s1, 'a'));
|
assert(!skipOver(s1, 'a'));
|
||||||
|
@ -6774,6 +6775,7 @@ int cmp(alias pred = "a < b", R1, R2)(R1 r1, R2 r2) if (isSomeString!R1 && isSom
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
@ -10991,6 +10993,20 @@ template canFind(alias pred="a == b")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
unittest
|
||||||
|
{
|
||||||
|
assert(canFind([0, 1, 2, 3], 2) == true);
|
||||||
|
assert(canFind([0, 1, 2, 3], [1, 2], [2, 3]));
|
||||||
|
assert(canFind([0, 1, 2, 3], [1, 2], [2, 3]) == 1);
|
||||||
|
assert(canFind([0, 1, 2, 3], [1, 7], [2, 3]));
|
||||||
|
assert(canFind([0, 1, 2, 3], [1, 7], [2, 3]) == 2);
|
||||||
|
|
||||||
|
assert(canFind([0, 1, 2, 3], 4) == false);
|
||||||
|
assert(!canFind([0, 1, 2, 3], [1, 3], [2, 4]));
|
||||||
|
assert(canFind([0, 1, 2, 3], [1, 3], [2, 4]) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
debug(std_algorithm) scope(success)
|
debug(std_algorithm) scope(success)
|
||||||
|
@ -11001,16 +11017,6 @@ unittest
|
||||||
auto b = a[a.length / 2];
|
auto b = a[a.length / 2];
|
||||||
assert(canFind(a, b));
|
assert(canFind(a, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(canFind([0, 1, 2, 3], 2) == true);
|
|
||||||
assert(canFind([0, 1, 2, 3], [1, 2], [2, 3]));
|
|
||||||
assert(canFind([0, 1, 2, 3], [1, 2], [2, 3]) == 1);
|
|
||||||
assert(canFind([0, 1, 2, 3], [1, 7], [2, 3]));
|
|
||||||
assert(canFind([0, 1, 2, 3], [1, 7], [2, 3]) == 2);
|
|
||||||
|
|
||||||
assert(canFind([0, 1, 2, 3], 4) == false);
|
|
||||||
assert(!canFind([0, 1, 2, 3], [1, 3], [2, 4]));
|
|
||||||
assert(canFind([0, 1, 2, 3], [1, 3], [2, 4]) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unittest
|
unittest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue