<commit_before>use v6;
use Test;
use List::Utils;

my @array = (1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 7, 8);

ok(([<=] @array), "array is sorted properly");

for (1.5, 2, 2.5, 3, 3.5, 4, 5.5, 6, 8) -> $x
{
    my $i = lower-bound(@array, $x);
    ok(@array[$i - 1] < $x <= @array[$i], "lower bound - 1 < $x <= lower bound");
}

is(lower-bound(@array, 8.5), @array.elems, "Off the big end returns max_index + 1");
is(upper-bound(@array, 0.5), 0, "Off the little end returns 0");

for (1.5, 2, 2.5, 3, 3.5, 4, 5.5, 6) -> $x
{
    my $i = upper-bound(@array, $x);
    ok(@array[$i - 1] <= $x < @array[$i], "upper bound - 1 <= $x < upper bound");
}

is(lower-bound(@array, 8), @array.elems - 1, "Equal to the big end returns max_index");
is(lower-bound(@array, 8.5), @array.elems, "Off the big end returns max_index + 1");

my @masak = "a" xx 10, "b" xx 100;
is binary-search(@masak, * eq "a"), 10, 'binary-search finds a/b boundary';
{
    my $count = 0;
    is binary-search(@masak, { $count++; $_ eq "a" }), 10, 'binary-search finds a/b boundary';
    ok $count < 8, "Doesn't do extra tests";
}

my @alpha = <a a b c c c d e f f>;

for "b".."f" -> $x {
    my $i = lower-bound(@alpha, $x);
    ok @alpha[$i - 1] lt $x le @alpha[$i], "lower bound - 1 lt $x le lower bound";
}

is lower-bound(@alpha, "f"), @alpha.elems - 2, "Equal to the big end returns max_index - 1"; # - 1 because "f" is doubled
is lower-bound(@alpha, "g"), @alpha.elems, "Off the big end returns max_index + 1";

for "b".."e" -> $x
{
    my $i = upper-bound(@alpha, $x);
    ok @alpha[$i - 1] le $x lt @alpha[$i], "upper bound - 1 <= $x < upper bound";
}
<commit_msg>GLR fix for binary search test<commit_after>use v6;
use Test;
use List::Utils;

my @array = (1, 2, 2, 3, 4, 5, 5, 5, 5, 6, 7, 8);

ok(([<=] @array), "array is sorted properly");

for (1.5, 2, 2.5, 3, 3.5, 4, 5.5, 6, 8) -> $x
{
    my $i = lower-bound(@array, $x);
    ok(@array[$i - 1] < $x <= @array[$i], "lower bound - 1 < $x <= lower bound");
}

is(lower-bound(@array, 8.5), @array.elems, "Off the big end returns max_index + 1");
is(upper-bound(@array, 0.5), 0, "Off the little end returns 0");

for (1.5, 2, 2.5, 3, 3.5, 4, 5.5, 6) -> $x
{
    my $i = upper-bound(@array, $x);
    ok(@array[$i - 1] <= $x < @array[$i], "upper bound - 1 <= $x < upper bound");
}

is(lower-bound(@array, 8), @array.elems - 1, "Equal to the big end returns max_index");
is(lower-bound(@array, 8.5), @array.elems, "Off the big end returns max_index + 1");

my @masak = flat "a" xx 10, "b" xx 100;
is binary-search(@masak, * eq "a"), 10, 'binary-search finds a/b boundary';
{
    my $count = 0;
    is binary-search(@masak, { $count++; $_ eq "a" }), 10, 'binary-search finds a/b boundary';
    ok $count < 8, "Doesn't do extra tests";
}

my @alpha = <a a b c c c d e f f>;

for "b".."f" -> $x {
    my $i = lower-bound(@alpha, $x);
    ok @alpha[$i - 1] lt $x le @alpha[$i], "lower bound - 1 lt $x le lower bound";
}

is lower-bound(@alpha, "f"), @alpha.elems - 2, "Equal to the big end returns max_index - 1"; # - 1 because "f" is doubled
is lower-bound(@alpha, "g"), @alpha.elems, "Off the big end returns max_index + 1";

for "b".."e" -> $x
{
    my $i = upper-bound(@alpha, $x);
    ok @alpha[$i - 1] le $x lt @alpha[$i], "upper bound - 1 <= $x < upper bound";
}

{'fraction_non_alphanumeric': 0.2263575350823673, 'fraction_numerical': 0.044539353264185476, 'mean_word_length': 3.1141781681304894, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6666637', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1345, 'n_words': 476}