]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17553 Removing getMinDecimalsCountToBeDistinctFromThreshold as its not used...
authorRevanshu Paliwal <revanshu.paliwal@sonarsource.com>
Wed, 2 Nov 2022 13:02:01 +0000 (14:02 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 4 Nov 2022 20:03:11 +0000 (20:03 +0000)
server/sonar-web/src/main/js/helpers/__tests__/measures-test.ts
server/sonar-web/src/main/js/helpers/measures.ts

index 2c7d78e0dd47dbc3359b89d7583a096d697d99d3..2f90fc1cb58c9f6c4d98e9d57846100a177268f4 100644 (file)
 
 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);
-  });
-});
index 6580495d6f332238abf373135a2cdb65780c68b5..d8161fc15a46e58449ce9e666db6570bd054baf3 100644 (file)
@@ -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,