Skip to content
Snippets Groups Projects
Commit 068e95b7 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Added unit tests for interval spread and flatten

parent d066cb98
No related branches found
No related tags found
No related merge requests found
import { import {
computeErasureIntervals, computeErasureIntervals,
combineErasureIntervals, combineErasureIntervals,
spreadErasureIntervals,
flattenErasureIntervals,
} from "../src/erasure.js" } from "../src/erasure.js"
describe("erasure intervals", () => { describe("erasure intervals", () => {
...@@ -91,4 +93,31 @@ describe("erasure intervals", () => { ...@@ -91,4 +93,31 @@ describe("erasure intervals", () => {
expect(combined).toStrictEqual(expected) expect(combined).toStrictEqual(expected)
}) })
it("spreads flattened intervals", () => {
const il = [[0.1, 1.25], [1.5, 2.0], [7.5, 7.75]]
const spread = spreadErasureIntervals(il)
const expected = { 0: [[0.1, 1.0]], 1: [[0.0, 0.25], [0.5, 1.0]], 7: [[0.5, 0.75]] }
expect(spread).toStrictEqual(expected)
})
it("spreads singulatity intervals", () => {
const il = [[0.0, 0.0], [3.5, 3.5], [99.0, 99.0]]
const spread = spreadErasureIntervals(il)
const expected = { 0: [[0.0, 0.0]], 3: [[0.5, 0.5]], 99: [[0.0, 0.0]] }
expect(spread).toStrictEqual(expected)
})
it("flattens spread intervals", () => {
const is = { 0: [[0.1, 1.0]], 1: [[0.0, 0.3], [0.4, 1.0]], 7: [[0.35, 0.75]] }
const flattened = flattenErasureIntervals(is)
const expected = [[0.1, 1.0], [1.0, 1.3], [1.4, 2.0], [7.35, 7.75]]
expect(flattened).toStrictEqual(expected)
})
}) })
...@@ -127,7 +127,7 @@ export function combineErasureIntervals(i1, i2) { ...@@ -127,7 +127,7 @@ export function combineErasureIntervals(i1, i2) {
} }
export function spreadErasureIntervals(intervals) { export function spreadErasureIntervals(intervals) {
const spread = [] const spread = {}
intervals.forEach(([l, u]) => { intervals.forEach(([l, u]) => {
if (u > l) { if (u > l) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment