diff --git a/lib/sponsors.ts b/lib/sponsors.ts index e4c96c954..7c14a5fcd 100644 --- a/lib/sponsors.ts +++ b/lib/sponsors.ts @@ -107,8 +107,9 @@ export function makeIconSets( const toPick = icons.map(icon => { return { icon: icon, - // Number of times we'd expect to see this, divided by number of times we saw it - error: result.length / icon.topIconShowEvery / (sponsorAppearanceCount.get(icon) || 0.00001), + // Number of times we'd expect to see this, divided by number of times we saw it, assuming that we pick + // this one next. + error: (result.length + 1) / icon.topIconShowEvery / ((sponsorAppearanceCount.get(icon) || 0) + 1), }; }); toPick.sort((lhs, rhs) => rhs.error - lhs.error); diff --git a/test/sponsors-test.ts b/test/sponsors-test.ts index 8b1236f82..f878b241e 100644 --- a/test/sponsors-test.ts +++ b/test/sponsors-test.ts @@ -226,6 +226,23 @@ levels: ]); expect(() => makeIconSets(icons, 2)).toThrow(); }); + it('should pick icons appropriately when one is required every time and the others fit in ok every 3', () => { + const sponsor1 = parse({name: 'Sponsor1', topIconShowEvery: 1, icon: '1'}); + const sponsor2 = parse({name: 'Sponsor2', topIconShowEvery: 3, icon: '2'}); + const sponsor3 = parse({name: 'Sponsor3', topIconShowEvery: 3, icon: '3'}); + const sponsor4 = parse({name: 'Sponsor4', topIconShowEvery: 3, icon: '4'}); + const sponsor5 = parse({name: 'Sponsor5', topIconShowEvery: 3, icon: '5'}); + const sponsor6 = parse({name: 'Sponsor6', topIconShowEvery: 3, icon: '6'}); + const icons = [sponsor1, sponsor2, sponsor3, sponsor4, sponsor5, sponsor6]; + expect(makeIconSets(icons, 10)).toEqual([icons]); + expect(makeIconSets(icons, 3)).toEqual([ + [sponsor1, sponsor2, sponsor3], + [sponsor1, sponsor4, sponsor5], + [sponsor1, sponsor2, sponsor6], + [sponsor1, sponsor3, sponsor4], + [sponsor1, sponsor5, sponsor6], + ]); + }); }); describe('Our specific sponsor file', () => {