From 381bc5ef8f058299734ffc9c9a94d09330b1aa33 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Thu, 31 Oct 2024 13:06:45 +0100 Subject: [PATCH] use reversed distribution in report viewer --- report-viewer/src/model/Distribution.ts | 3 ++- report-viewer/tests/unit/model/Distribution.test.ts | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/report-viewer/src/model/Distribution.ts b/report-viewer/src/model/Distribution.ts index f0652c92d..ce1e695bc 100644 --- a/report-viewer/src/model/Distribution.ts +++ b/report-viewer/src/model/Distribution.ts @@ -11,8 +11,9 @@ export class Distribution { public splitIntoBuckets(bucketCount: BucketOptions): number[] { const bucketArray = new Array(bucketCount).fill(0) const divisor = 100 / bucketCount + const reversedDistribution = Array.from(this._distribution).reverse() for (let i = 99; i >= 0; i--) { - bucketArray[Math.floor(i / divisor)] += this._distribution[i] + bucketArray[Math.floor(i / divisor)] += reversedDistribution[i] } return bucketArray } diff --git a/report-viewer/tests/unit/model/Distribution.test.ts b/report-viewer/tests/unit/model/Distribution.test.ts index 88a756922..b01bb7bdf 100644 --- a/report-viewer/tests/unit/model/Distribution.test.ts +++ b/report-viewer/tests/unit/model/Distribution.test.ts @@ -2,10 +2,10 @@ import { describe, expect, it } from 'vitest' import { Distribution } from '@/model/Distribution' const distributionData = [ + 0, 7, 15, 42, 109, 225, 470, 869, 1442, 2052, 3025, 4056, 5091, 6130, 7023, 7292, 7445, 7177, + 6343, 5373, 4309, 3163, 2244, 1544, 923, 493, 273, 168, 61, 31, 8, 12, 2, 1, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, - 1, 2, 12, 8, 31, 61, 168, 273, 493, 923, 1544, 2244, 3163, 4309, 5373, 6343, 7177, 7445, 7292, - 7023, 6130, 5091, 4056, 3025, 2052, 1442, 869, 470, 225, 109, 42, 15, 7, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] const distribution = new Distribution(distributionData) @@ -14,7 +14,8 @@ describe('Distribution', () => { expect(distribution.splitIntoBuckets(10)).toEqual([0, 0, 0, 0, 0, 0, 26, 13209, 58955, 5231]) }), it('get in 100 Buckets', () => { - expect(distribution.splitIntoBuckets(100)).toEqual(distributionData) + const reversedOriginal = Array.from(distributionData).reverse() + expect(distribution.splitIntoBuckets(100)).toEqual(reversedOriginal) }), it('get in 25 Buckets', () => { expect(distribution.splitIntoBuckets(25)).toEqual([