Skip to content

Commit

Permalink
odp calc test
Browse files Browse the repository at this point in the history
  • Loading branch information
sorja committed Nov 3, 2023
1 parent 8066110 commit b35877e
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/meta/assessment/originalDataPoint/odps/test/calc.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Numbers } from 'utils/numbers'

import { calcTotalSubSubFieldArea } from 'meta/assessment/originalDataPoint/odps/calc'

import { odp1, odp2, odp3 } from './mockODP'

const testsCalcTotalSubSubFieldArea = [
{
name: 'calcTotalSubSubFieldArea - 1: all parent values 0, return 0',
odp: odp1,
expected: Numbers.toBigNumber('0'),
},
{
name: 'calcTotalSubSubFieldArea - 2: parent value exist, child value empty, return null',
odp: odp2,
expected: null,
},
{
name: 'calcTotalSubSubFieldArea - 3: parent values exist, child value empty, child value filled, return value',
odp: odp3,
expected: Numbers.BigNumber('375'),
},
]

describe('ODPs.calc', () => {
testsCalcTotalSubSubFieldArea.forEach((_test) => {
test(_test.name, () => {
const result = calcTotalSubSubFieldArea({
originalDataPoint: _test.odp,
field: 'forestPercent',
subField: 'forestNaturalPercent',
subSubField: 'forestNaturalForestOfWhichPrimaryForestPercent',
})
expect(result).toEqual(_test.expected)
})
})

// TODO: test calcTotalArea
// TODO: test calcTotalFieldArea
// TODO: test calcTotalSubFieldArea
// TODO: test calcTotalSubSubFieldArea
// TODO: test calcTotalLandArea
})
199 changes: 199 additions & 0 deletions src/meta/assessment/originalDataPoint/odps/test/mockODP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
import { OriginalDataPoint } from 'meta/assessment/originalDataPoint/originalDataPoint'

export const odp1 = {
id: 1400,
countryIso: 'X01',
year: 2011,
dataSourceAdditionalComments: 'Add comments here',
dataSourceMethods: ['nationalForestInventory'],
dataSourceReferences: '',
description: '',
nationalClasses: [
{
area: '1500.00',
name: 'Open forest',
uuid: '02b381ca-2c39-49f7-9fef-80a3463f8f6b',
definition: 'Add definition here',
forestPercent: '100.00',
forestNaturalPercent: '0.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '100.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: null,
forestNaturalForestOfWhichPrimaryForestPercent: '0',
},
{
area: '900.00',
name: 'Closed forest',
uuid: '3986836e-eac8-4287-a625-11df18a60d01',
definition: '',
forestPercent: '100.00',
forestNaturalPercent: '0.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '100.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: '5.00',
forestNaturalForestOfWhichPrimaryForestPercent: '0',
},
{
area: '550.00',
name: 'Plantations',
uuid: '42b9b108-c655-40f3-a865-934346dfa859',
definition: '',
forestPercent: '100.00',
forestNaturalPercent: '0.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '100.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: null,
forestNaturalForestOfWhichPrimaryForestPercent: '0',
},
{
area: '300.00',
name: 'Woodland',
uuid: '578bb1d6-961a-48c1-b489-877641f3c17f',
definition: '',
forestPercent: '0.00',
otherWoodedLandPercent: '100.00',
},
{
name: '',
definition: '',
uuid: '6c611c99-9eab-4369-a56b-16c671e491da',
placeHolder: true,
},
],
idLegacy: null,
} as OriginalDataPoint

export const odp2 = {
id: 1400,
countryIso: 'X01',
year: 2011,
dataSourceAdditionalComments: 'Add comments here',
dataSourceMethods: ['nationalForestInventory'],
dataSourceReferences: '',
description: '',
nationalClasses: [
{
area: '1500.00',
name: 'Open forest',
uuid: '02b381ca-2c39-49f7-9fef-80a3463f8f6b',
definition: 'Add definition here',
forestPercent: '100.00',
forestNaturalPercent: '50.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '50.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: null,
forestNaturalForestOfWhichPrimaryForestPercent: null,
},
{
area: '900.00',
name: 'Closed forest',
uuid: '3986836e-eac8-4287-a625-11df18a60d01',
definition: '',
forestPercent: '100.00',
forestNaturalPercent: '0.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '100.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: '5.00',
forestNaturalForestOfWhichPrimaryForestPercent: '0',
},
{
area: '550.00',
name: 'Plantations',
uuid: '42b9b108-c655-40f3-a865-934346dfa859',
definition: '',
forestPercent: '100.00',
forestNaturalPercent: '0.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '100.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: null,
forestNaturalForestOfWhichPrimaryForestPercent: '0',
},
{
area: '300.00',
name: 'Woodland',
uuid: '578bb1d6-961a-48c1-b489-877641f3c17f',
definition: '',
forestPercent: '0.00',
otherWoodedLandPercent: '100.00',
},
{
name: '',
definition: '',
uuid: '6c611c99-9eab-4369-a56b-16c671e491da',
placeHolder: true,
},
],
idLegacy: null,
} as OriginalDataPoint

export const odp3 = {
id: 1400,
countryIso: 'X01',
year: 2011,
dataSourceAdditionalComments: 'Add comments here',
dataSourceMethods: ['nationalForestInventory'],
dataSourceReferences: '',
description: '',
nationalClasses: [
{
area: '1500.00',
name: 'Open forest',
uuid: '02b381ca-2c39-49f7-9fef-80a3463f8f6b',
definition: 'Add definition here',
forestPercent: '100.00',
forestNaturalPercent: '50.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '50.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: null,
forestNaturalForestOfWhichPrimaryForestPercent: '50.00',
},
{
area: '900.00',
name: 'Closed forest',
uuid: '3986836e-eac8-4287-a625-11df18a60d01',
definition: '',
forestPercent: '100.00',
forestNaturalPercent: '50.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '100.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: '5.00',
forestNaturalForestOfWhichPrimaryForestPercent: null,
},
{
area: '550.00',
name: 'Plantations',
uuid: '42b9b108-c655-40f3-a865-934346dfa859',
definition: '',
forestPercent: '100.00',
forestNaturalPercent: '0.00',
otherWoodedLandPercent: '0',
forestPlantationPercent: '100.00',
otherPlantedForestPercent: '0.00',
forestPlantationIntroducedPercent: null,
forestNaturalForestOfWhichPrimaryForestPercent: '0',
},
{
area: '300.00',
name: 'Woodland',
uuid: '578bb1d6-961a-48c1-b489-877641f3c17f',
definition: '',
forestPercent: '0.00',
otherWoodedLandPercent: '100.00',
},
{
name: '',
definition: '',
uuid: '6c611c99-9eab-4369-a56b-16c671e491da',
placeHolder: true,
},
],
idLegacy: null,
} as OriginalDataPoint

0 comments on commit b35877e

Please sign in to comment.