Skip to content

Commit

Permalink
Merge pull request #847 from nextcloud/backport/810/stable28
Browse files Browse the repository at this point in the history
[stable28] fix #745 ValueError: random_int(): Argument #1 ($min) must be less than or equal to argument #2 ($max)
  • Loading branch information
ChristophWurst authored Feb 15, 2024
2 parents 05c40eb + 89c7556 commit 7e8e975
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Service/NegativeSampleGenerator.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7e8e975

Please sign in to comment.