Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] fix #745 ValueError: random_int(): Argument #1 ($min) must be less than or equal to argument #2 ($max) #848

Merged
merged 2 commits into from Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Service/NegativeSampleGenerator.php
Expand Up @@ -71,7 +71,7 @@ private function getUniqueIPsPerUser(Dataset $positives): array {
private function generateFromRealData(array $uidVec, array $uniqueIps): array {
return array_merge(
$uidVec,
$uniqueIps[random_int(0, count($uniqueIps) - 1)]
empty($uniqueIps) ? [] : $uniqueIps[random_int(0, count($uniqueIps) - 1)]
);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/Service/NegativeSampleGeneratorTest.php
Expand Up @@ -131,6 +131,17 @@ public function testGenerateMultipleShuffledFromLimitedUnique(): void {
'sample has a unique IP'
);
}

$positives = new Unlabeled([
array_merge(self::decToBitArray(1, 16), self::decToBitArray(1, 32)),
array_merge(self::decToBitArray(2, 16), self::decToBitArray(1, 32)),
array_merge(self::decToBitArray(3, 16), self::decToBitArray(1, 32)),
array_merge(self::decToBitArray(4, 16), self::decToBitArray(1, 32)),
]);

$result = $this->generator->generateShuffledFromPositiveSamples($positives, 5);

self::assertCount(5, $result);
}

/**
Expand Down