From 0be0c1cc73b4012b82314713d17d1fc812c7e4d4 Mon Sep 17 00:00:00 2001 From: Revanshu Paliwal Date: Wed, 2 Nov 2022 14:02:01 +0100 Subject: [PATCH] SONAR-17553 Removing getMinDecimalsCountToBeDistinctFromThreshold as its not used anywhere --- .../js/helpers/__tests__/measures-test.ts | 42 +------------------ .../sonar-web/src/main/js/helpers/measures.ts | 23 ---------- 2 files changed, 1 insertion(+), 64 deletions(-) diff --git a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts index 2c7d78e0dd4..2f90fc1cb58 100644 --- a/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts +++ b/server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts @@ -20,12 +20,7 @@ import { Dict } from '../../types/types'; import { getMessages } from '../l10nBundle'; -import { - enhanceConditionWithMeasure, - formatMeasure, - getMinDecimalsCountToBeDistinctFromThreshold, - isPeriodBestValue, -} from '../measures'; +import { enhanceConditionWithMeasure, formatMeasure, isPeriodBestValue } from '../measures'; import { mockQualityGateStatusCondition } from '../mocks/quality-gates'; import { mockMeasureEnhanced, mockMetric } from '../testMocks'; @@ -250,38 +245,3 @@ describe('#formatMeasure()', () => { expect(formatMeasure(undefined, 'INT')).toBe(''); }); }); - -describe('getMinDecimalsCountToBeDistinctFromThreshold', () => { - it('should return default if no threshold', () => { - expect(getMinDecimalsCountToBeDistinctFromThreshold(2.67, undefined)).toBe(1); - }); - - it('should return 1 if delta is 0', () => { - expect(getMinDecimalsCountToBeDistinctFromThreshold(2.5, 2.5)).toBe(1); - }); - - it('should return 1 if the delta is larger than 0.1', () => { - [0.1, 0.15, 0.2, 0.5, 0.8, 1].forEach((delta) => { - expect(getMinDecimalsCountToBeDistinctFromThreshold(2.5 + delta, 2.5)).toBe(1); - expect(getMinDecimalsCountToBeDistinctFromThreshold(2.5 - delta, 2.5)).toBe(1); - }); - }); - - it('should return enough precision to see the delta', () => { - expect(getMinDecimalsCountToBeDistinctFromThreshold(2.55, 2.5)).toBe(2); - expect(getMinDecimalsCountToBeDistinctFromThreshold(2.505, 2.5)).toBe(3); - expect(getMinDecimalsCountToBeDistinctFromThreshold(2.5005, 2.5)).toBe(4); - expect(getMinDecimalsCountToBeDistinctFromThreshold(85.01, 85)).toBe(2); - expect(getMinDecimalsCountToBeDistinctFromThreshold(84.95, 85)).toBe(2); - // eslint-disable-next-line no-loss-of-precision - expect(getMinDecimalsCountToBeDistinctFromThreshold(84.999999999999554, 85)).toBe( - '9999999999995'.length - ); - // eslint-disable-next-line no-loss-of-precision - expect(getMinDecimalsCountToBeDistinctFromThreshold(85.0000000000000954, 85)).toBe( - '00000000000009'.length - ); - // eslint-disable-next-line no-loss-of-precision - expect(getMinDecimalsCountToBeDistinctFromThreshold(85.00000000000000009, 85)).toBe(1); - }); -}); diff --git a/server/sonar-web/src/main/js/helpers/measures.ts b/server/sonar-web/src/main/js/helpers/measures.ts index 6580495d6f3..d8161fc15a4 100644 --- a/server/sonar-web/src/main/js/helpers/measures.ts +++ b/server/sonar-web/src/main/js/helpers/measures.ts @@ -104,29 +104,6 @@ export function getShortType(type: string): string { return type; } -/* - * Conditional decimal count for QualityGate-impacting measures - * (e.g. Coverage %) - * Increase the number of decimals if the value is close to the threshold - * We count the precision (number of 0's, i.e. log10 and round down) needed to show the difference - * E.g. threshold 85, value 84.9993 -> delta = 0.0007, we need 4 decimals to see the difference - * otherwise rounding will make it look like they are equal. - */ -const DEFAULT_DECIMALS = 1; -export function getMinDecimalsCountToBeDistinctFromThreshold( - value: number, - threshold: number | undefined -): number { - if (!threshold) { - return DEFAULT_DECIMALS; - } - const delta = Math.abs(threshold - value); - if (delta < 0.1 && delta > 0) { - return -Math.floor(Math.log10(delta)); - } - return DEFAULT_DECIMALS; -} - function useFormatter( value: string | number | undefined, formatter: Formatter, -- 2.39.5