Этот коммит содержится в:
Mario Vitale
2023-03-27 16:28:42 +02:00
родитель da7a6825ce
Коммит ba6b97fb62
1142 изменённых файлов: 44 добавлений и 44 удалений

Просмотреть файл

@@ -0,0 +1,48 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
function* distributeItems(total, divider) {
if (divider === 0) {
yield 0;
} else {
let rest = total % divider;
const result = total / divider;
for (let i = 0; i < divider; i++) {
if (rest-- > 0) {
yield Math.ceil(result);
} else {
yield Math.floor(result);
}
}
}
}
function getTestFilesIdentifier(numberOfTestFiles, part, of) {
const PART = parseInt(part, 10) || 1;
const OF = parseInt(of, 10) || 1;
if (PART > OF) {
throw new Error(`"--part=${PART}" should not be greater than "--of=${OF}"`);
}
const distributions = [];
for (const member of distributeItems(numberOfTestFiles, OF)) {
distributions.push(member);
}
const indexedPart = (PART - 1);
let start = 0;
for (let i = 0; i < indexedPart; i++) {
start += distributions[i];
}
const end = distributions[indexedPart] + start;
const count = distributions[indexedPart];
return {start, end, count};
}
module.exports = {
getTestFilesIdentifier,
};