Commit cdaa8df1 authored by Noah Zinsmeister's avatar Noah Zinsmeister

fix formatting tests

parent e572535a
import BigInteger from 'bignumber.js'
import { FlexibleFormat, FormatSignificantOptions, FormatFixedOptions } from '../types' import { FlexibleFormat, FormatSignificantOptions, FormatFixedOptions } from '../types'
import { formatSignificant, formatFixed } from '../format' import { formatSignificant, formatSignificantDecimals, formatFixed, formatFixedDecimals } from '../format'
import { FIXED_UNDERFLOW_BEHAVIOR } from '../constants' import { FIXED_UNDERFLOW_BEHAVIOR, ROUNDING_MODE } from '../constants'
function constructFormatSignificantOptions( function constructFormatSignificantOptions(
significantDigits: number, significantDigits: number,
roundingMode: BigInteger.RoundingMode = ROUNDING_MODE,
forceIntegerSignificance: boolean = false, forceIntegerSignificance: boolean = false,
format: FlexibleFormat = false format: FlexibleFormat = false
): FormatSignificantOptions { ): FormatSignificantOptions {
return { return {
significantDigits, significantDigits,
roundingMode,
forceIntegerSignificance, forceIntegerSignificance,
format format
} }
...@@ -16,15 +20,17 @@ function constructFormatSignificantOptions( ...@@ -16,15 +20,17 @@ function constructFormatSignificantOptions(
function constructFormatFixedOptions( function constructFormatFixedOptions(
decimalPlaces: number, decimalPlaces: number,
roundingMode: BigInteger.RoundingMode = ROUNDING_MODE,
dropTrailingZeros: boolean = true, dropTrailingZeros: boolean = true,
format: FlexibleFormat = false, underflowBehavior: FIXED_UNDERFLOW_BEHAVIOR = FIXED_UNDERFLOW_BEHAVIOR.ONE_DIGIT,
underflowBehavior: FIXED_UNDERFLOW_BEHAVIOR = FIXED_UNDERFLOW_BEHAVIOR.ONE_DIGIT format: FlexibleFormat = false
): FormatFixedOptions { ): FormatFixedOptions {
return { return {
decimalPlaces, decimalPlaces,
roundingMode,
dropTrailingZeros, dropTrailingZeros,
format, underflowBehavior,
underflowBehavior format
} }
} }
...@@ -33,6 +39,11 @@ describe('formatSignificant', (): void => { ...@@ -33,6 +39,11 @@ describe('formatSignificant', (): void => {
const formatted = formatSignificant('1.234', constructFormatSignificantOptions(2)) const formatted = formatSignificant('1.234', constructFormatSignificantOptions(2))
expect(formatted).toBe('1.2') expect(formatted).toBe('1.2')
}) })
test('decimal', (): void => {
const formatted = formatSignificantDecimals('1234', 3, constructFormatSignificantOptions(2))
expect(formatted).toBe('1.2')
})
}) })
describe('formatFixed', (): void => { describe('formatFixed', (): void => {
...@@ -40,4 +51,9 @@ describe('formatFixed', (): void => { ...@@ -40,4 +51,9 @@ describe('formatFixed', (): void => {
const formatted = formatFixed('1.234', constructFormatFixedOptions(1)) const formatted = formatFixed('1.234', constructFormatFixedOptions(1))
expect(formatted).toBe('1.2') expect(formatted).toBe('1.2')
}) })
test('regular', (): void => {
const formatted = formatFixedDecimals('1234', 3, constructFormatFixedOptions(1))
expect(formatted).toBe('1.2')
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment