2020-02-16 18:56:07 +00:00
|
|
|
import { expect } from 'chai'
|
|
|
|
import {
|
2020-02-24 15:41:19 +00:00
|
|
|
concatTemporals,
|
|
|
|
createTemporalEvaluation,
|
|
|
|
zipTemporals
|
2020-02-16 18:56:07 +00:00
|
|
|
} from '../source/engine/period'
|
|
|
|
|
|
|
|
const neverEnding = value => [{ start: null, end: null, value: value }]
|
2020-02-24 15:41:19 +00:00
|
|
|
describe('Periods : zip', () => {
|
|
|
|
it('should zip two empty temporalValue', () => {
|
|
|
|
const result = zipTemporals([], [])
|
2020-02-16 18:56:07 +00:00
|
|
|
expect(result).to.deep.equal([])
|
|
|
|
})
|
|
|
|
|
2020-02-24 15:41:19 +00:00
|
|
|
it('should zip constant temporalValue', () => {
|
|
|
|
const result = zipTemporals(neverEnding(1), neverEnding(2))
|
2020-02-16 18:56:07 +00:00
|
|
|
expect(result).to.deep.equal(neverEnding([1, 2]))
|
|
|
|
})
|
|
|
|
|
2020-02-24 15:41:19 +00:00
|
|
|
it('should zip changing temporalValue', () => {
|
|
|
|
const value1 = createTemporalEvaluation(true, {
|
|
|
|
start: null,
|
|
|
|
end: '01/08/2020'
|
|
|
|
})
|
2020-02-16 18:56:07 +00:00
|
|
|
const value2 = neverEnding(1)
|
2020-02-24 15:41:19 +00:00
|
|
|
expect(zipTemporals(value1, value2)).to.deep.equal([
|
2020-02-16 18:56:07 +00:00
|
|
|
{ start: null, end: '01/08/2020', value: [true, 1] },
|
|
|
|
{ start: '02/08/2020', end: null, value: [false, 1] }
|
|
|
|
])
|
2020-02-24 15:41:19 +00:00
|
|
|
expect(zipTemporals(value2, value1)).to.deep.equal([
|
2020-02-16 18:56:07 +00:00
|
|
|
{ start: null, end: '01/08/2020', value: [1, true] },
|
|
|
|
{ start: '02/08/2020', end: null, value: [1, false] }
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
2020-02-24 15:41:19 +00:00
|
|
|
it('should zip two overlapping temporalValue', () => {
|
|
|
|
const value1 = createTemporalEvaluation(1, {
|
2020-02-16 18:56:07 +00:00
|
|
|
start: '01/07/2019',
|
|
|
|
end: '30/06/2020'
|
|
|
|
})
|
2020-02-24 15:41:19 +00:00
|
|
|
const value2 = createTemporalEvaluation(2, {
|
2020-02-16 18:56:07 +00:00
|
|
|
start: '01/01/2019',
|
|
|
|
end: '31/12/2019'
|
|
|
|
})
|
|
|
|
|
2020-02-24 15:41:19 +00:00
|
|
|
expect(zipTemporals(value1, value2)).to.deep.equal([
|
2020-02-16 18:56:07 +00:00
|
|
|
{ start: null, end: '31/12/2018', value: [false, false] },
|
|
|
|
{ start: '01/01/2019', end: '30/06/2019', value: [false, 2] },
|
|
|
|
{ start: '01/07/2019', end: '31/12/2019', value: [1, 2] },
|
|
|
|
{ start: '01/01/2020', end: '30/06/2020', value: [1, false] },
|
|
|
|
{ start: '01/07/2020', end: null, value: [false, false] }
|
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2020-02-24 15:41:19 +00:00
|
|
|
describe('Periods : concat', () => {
|
|
|
|
it('should merge concat overlapping temporalValue', () => {
|
|
|
|
const value1 = createTemporalEvaluation(10)
|
2020-02-16 18:56:07 +00:00
|
|
|
const value2 = [
|
|
|
|
{ start: null, end: '14/04/2019', value: 100 },
|
|
|
|
{ start: '15/04/2019', end: '08/08/2019', value: 2000 },
|
|
|
|
{ start: '09/08/2019', end: null, value: 200 }
|
|
|
|
]
|
|
|
|
|
2020-02-24 15:41:19 +00:00
|
|
|
expect(concatTemporals([value1, value2])).to.deep.equal([
|
|
|
|
{ start: null, end: '14/04/2019', value: [10, 100] },
|
|
|
|
{ start: '15/04/2019', end: '08/08/2019', value: [10, 2000] },
|
|
|
|
{ start: '09/08/2019', end: null, value: [10, 200] }
|
2020-02-16 18:56:07 +00:00
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|