<commit_before>import {assert} from 'chai'
import {queryResultNester, nestedQueryResultLabelizer} from '../../lib/queryResultNester'

//const util = require('util')

describe('queryResultNester', () => {

  it('groups data according to displayNesting down to categories and series', () => {

    const nested = queryResultNester([
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '0', innvkat5: 'alle', fylkeId: '01'},
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '1', innvkat5: 'alle', fylkeId: '01'},
    ], ['aar', 'innvkat5', 'kjonn'])

    //console.log(util.inspect(nested, {showHidden: false, depth: null})))

    assert.equal(nested[0].key, '2014')
    assert.equal(nested[0].values[0].key, 'alle')
    assert.equal(nested[0].values[0].values[0].key, '0')
    assert.equal(nested[0].values[0].values[0].values, 29)

    assert.equal(nested[0].values[0].values[1].key, '1')
    assert.equal(nested[0].values[0].values[1].values, 29)
  })

  it('sums leaf node values beyond the specified nesting level', () => {
    let nested = queryResultNester([
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '0', innvkat5: 'alle', fylkeId: '01'},
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '1', innvkat5: 'alle', fylkeId: '01'},
    ], ['aar', 'innvkat5'])

    assert.equal(nested[0].key, '2014')
    assert.equal(nested[0].values[0].key, 'alle')
    assert.equal(nested[0].values[0].values, 29 + 29)

    nested = queryResultNester([
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '0', innvkat5: 'alle', fylkeId: '01'},
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '1', innvkat5: 'alle', fylkeId: '01'},
    ], ['aar'])

    assert.equal(nested[0].key, '2014')
    assert.equal(nested[0].values, 29 + 29)
  })
})

describe('queryResultLabelizer', () => {
  it('recursively adds title properties to nodes', () => {
    const labelized = nestedQueryResultLabelizer([
      {key: '2014', values: [{key: 'norskfodte_m_innvf', values: [{key: '0', values: 18}]}]}
    ], ['aar', 'innvkat5', 'kjonn'])

    assert.equal(labelized[0].title, '2014')
    assert.equal(labelized[0].values[0].title, 'norskfødte med innvandrerforeldre')
    assert.equal(labelized[0].values[0].values[0].title, 'kvinne')
  })
})<commit_msg>Rename test suite<commit_after>import {assert} from 'chai'
import {queryResultNester, nestedQueryResultLabelizer} from '../../lib/queryResultNester'

//const util = require('util')

describe('queryResultNester', () => {

  it('groups data according to displayNesting down to categories and series', () => {

    const nested = queryResultNester([
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '0', innvkat5: 'alle', fylkeId: '01'},
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '1', innvkat5: 'alle', fylkeId: '01'},
    ], ['aar', 'innvkat5', 'kjonn'])

    //console.log(util.inspect(nested, {showHidden: false, depth: null})))

    assert.equal(nested[0].key, '2014')
    assert.equal(nested[0].values[0].key, 'alle')
    assert.equal(nested[0].values[0].values[0].key, '0')
    assert.equal(nested[0].values[0].values[0].values, 29)

    assert.equal(nested[0].values[0].values[1].key, '1')
    assert.equal(nested[0].values[0].values[1].values, 29)
  })

  it('sums leaf node values beyond the specified nesting level', () => {
    let nested = queryResultNester([
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '0', innvkat5: 'alle', fylkeId: '01'},
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '1', innvkat5: 'alle', fylkeId: '01'},
    ], ['aar', 'innvkat5'])

    assert.equal(nested[0].key, '2014')
    assert.equal(nested[0].values[0].key, 'alle')
    assert.equal(nested[0].values[0].values, 29 + 29)

    nested = queryResultNester([
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '0', innvkat5: 'alle', fylkeId: '01'},
      {aar: '2014', tabellvariabel: '29', enhet: 'personer', kjonn: '1', innvkat5: 'alle', fylkeId: '01'},
    ], ['aar'])

    assert.equal(nested[0].key, '2014')
    assert.equal(nested[0].values, 29 + 29)
  })
})

describe('nestedQueryResultLabelizer', () => {
  it('recursively adds title properties to nodes', () => {
    const labelized = nestedQueryResultLabelizer([
      {key: '2014', values: [{key: 'norskfodte_m_innvf', values: [{key: '0', values: 18}]}]}
    ], ['aar', 'innvkat5', 'kjonn'])

    assert.equal(labelized[0].title, '2014')
    assert.equal(labelized[0].values[0].title, 'norskfødte med innvandrerforeldre')
    assert.equal(labelized[0].values[0].values[0].title, 'kvinne')
  })
})
{'fraction_non_alphanumeric': 0.21066098081023454, 'fraction_numerical': 0.05458422174840085, 'mean_word_length': 4.538370720188902, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '1981105', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1744, 'n_words': 358}