<commit_before>import {assert} from 'chai'
import {unitFormatter} from '../../lib/unitFormatter'

describe('unitFormatter', () => {
  it('returns an object with format and axisFormat functions', () => {
    const formatters = unitFormatter()
    assert.property(formatters, 'format')
    assert.typeOf(formatters.format, 'function')
    assert.property(formatters, 'axisFormat')
    assert.typeOf(formatters.axisFormat, 'function')
  })

  it('formats money with toLocaleString()', () => {
    const formatters = unitFormatter('kroner')

    const expected = `${parseFloat(1999).toLocaleString()} kr`
    assert.equal(formatters.format(1999), expected)
    assert.equal(formatters.axisFormat(1999), expected)
  })

  it('formats per mil with ‰ character and 2 decimals', () => {
    const formatters = unitFormatter('promille')
    assert.equal(formatters.format(1.9), '1.90 ‰')
    assert.equal(formatters.format(19), '19.00 ‰')
    assert.equal(formatters.format(0.7512312), '0.75 ‰')

    assert.equal(formatters.axisFormat(1.9), '1.90 ‰')
    assert.equal(formatters.axisFormat(19), '19.00 ‰')
    assert.equal(formatters.axisFormat(0.7512312), '0.75 ‰')
  })

  it('formats per cent using 2 decimals and adding % character', () => {
    const formatters = unitFormatter('prosent')
    assert.equal(formatters.format(190), '190.00 %')
    assert.equal(formatters.format(29), '29.00 %')

  })

  it('formats per cent on axis with no decimals', () => {
    const formatters = unitFormatter('prosent')
    assert.equal(formatters.axisFormat(19), '19 %')
    assert.equal(formatters.axisFormat(0.29), '0 %')
  })

  it('formats unknown units with toLocaleString()', () => {<commit_msg>Add some more tests for formatting of percentages<commit_after>import {assert} from 'chai'
import {unitFormatter} from '../../lib/unitFormatter'

describe('unitFormatter', () => {
  it('returns an object with format and axisFormat functions', () => {
    const formatters = unitFormatter()
    assert.property(formatters, 'format')
    assert.typeOf(formatters.format, 'function')
    assert.property(formatters, 'axisFormat')
    assert.typeOf(formatters.axisFormat, 'function')
  })

  it('formats money with toLocaleString()', () => {
    const formatters = unitFormatter('kroner')

    const expected = `${parseFloat(1999).toLocaleString()} kr`
    assert.equal(formatters.format(1999), expected)
    assert.equal(formatters.axisFormat(1999), expected)
  })

  it('formats per mil with ‰ character and 2 decimals', () => {
    const formatters = unitFormatter('promille')
    assert.equal(formatters.format(1.9), '1.90 ‰')
    assert.equal(formatters.format(19), '19.00 ‰')
    assert.equal(formatters.format(0.7512312), '0.75 ‰')

    assert.equal(formatters.axisFormat(1.9), '1.90 ‰')
    assert.equal(formatters.axisFormat(19), '19.00 ‰')
    assert.equal(formatters.axisFormat(0.7512312), '0.75 ‰')
  })

  it('formats per cent using 2 decimals and adding % character', () => {
    const formatters = unitFormatter('prosent')
    assert.equal(formatters.format(190), '190.00 %')
    assert.equal(formatters.format(29), '29.00 %')
    assert.equal(formatters.format(29.29), '29.29 %')
    assert.equal(formatters.format(0.9), '0.90 %')
  })

  it('formats per cent on axis with no decimals', () => {
    const formatters = unitFormatter('prosent')
    assert.equal(formatters.axisFormat(19), '19 %')
    assert.equal(formatters.axisFormat(0.29), '0 %')
  })

  it('formats unknown units with toLocaleString()', () => {
{'fraction_non_alphanumeric': 0.16866096866096866, 'fraction_numerical': 0.04928774928774929, 'mean_word_length': 4.327769347496206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7189255', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1127, 'n_words': 229}