* Returns an array of maxium `count` parsed input sources, randomly * selected from a primary corpus and a list of secondary corpora.
(primaryCorpus, secondaryCorpora, count)
| 24 | * selected from a primary corpus and a list of secondary corpora. |
| 25 | */ |
| 26 | function getRandomInputs(primaryCorpus, secondaryCorpora, count) { |
| 27 | count = random.randInt(2, count); |
| 28 | |
| 29 | // Choose 40%-80% of inputs from primary corpus. |
| 30 | const primaryCount = Math.floor(random.uniform(0.4, 0.8) * count); |
| 31 | count -= primaryCount; |
| 32 | |
| 33 | let inputs = primaryCorpus.getRandomTestcases(primaryCount); |
| 34 | |
| 35 | // Split remainder equally between the secondary corpora. |
| 36 | const secondaryCount = Math.floor(count / secondaryCorpora.length); |
| 37 | |
| 38 | for (let i = 0; i < secondaryCorpora.length; i++) { |
| 39 | let currentCount = secondaryCount; |
| 40 | if (i == secondaryCorpora.length - 1) { |
| 41 | // Last one takes the remainder. |
| 42 | currentCount = count; |
| 43 | } |
| 44 | |
| 45 | count -= currentCount; |
| 46 | if (currentCount) { |
| 47 | inputs = inputs.concat( |
| 48 | secondaryCorpora[i].getRandomTestcases(currentCount)); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return random.shuffle(inputs); |
| 53 | } |
| 54 | |
| 55 | class Runner { |
| 56 | *inputGen() { |
no test coverage detected