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 { formatSignificant, formatFixed } from '../format'
import { FIXED_UNDERFLOW_BEHAVIOR } from '../constants'
import { formatSignificant, formatSignificantDecimals, formatFixed, formatFixedDecimals } from '../format'
import { FIXED_UNDERFLOW_BEHAVIOR, ROUNDING_MODE } from '../constants'
function constructFormatSignificantOptions(
significantDigits: number,
roundingMode: BigInteger.RoundingMode = ROUNDING_MODE,
forceIntegerSignificance: boolean = false,
format: FlexibleFormat = false
): FormatSignificantOptions {
return {
significantDigits,
roundingMode,
forceIntegerSignificance,
format
}
......@@ -16,15 +20,17 @@ function constructFormatSignificantOptions(
function constructFormatFixedOptions(
decimalPlaces: number,
roundingMode: BigInteger.RoundingMode = ROUNDING_MODE,
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 {
return {
decimalPlaces,
roundingMode,
dropTrailingZeros,
format,
underflowBehavior
underflowBehavior,
format
}
}
......@@ -33,6 +39,11 @@ describe('formatSignificant', (): void => {
const formatted = formatSignificant('1.234', constructFormatSignificantOptions(2))
expect(formatted).toBe('1.2')
})
test('decimal', (): void => {
const formatted = formatSignificantDecimals('1234', 3, constructFormatSignificantOptions(2))
expect(formatted).toBe('1.2')
})
})
describe('formatFixed', (): void => {
......@@ -40,4 +51,9 @@ describe('formatFixed', (): void => {
const formatted = formatFixed('1.234', constructFormatFixedOptions(1))
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