summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/epoch/tests/unit/data
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 00:55:53 +0000
commit129b974b59c74140570847bb4a2774d41d1e5fae (patch)
treef2dc68e7186b8157e33aebbc2526e016912ded82 /debian/missing-sources/epoch/tests/unit/data
parentAdding upstream version 3.2.1. (diff)
downloadknot-resolver-129b974b59c74140570847bb4a2774d41d1e5fae.tar.xz
knot-resolver-129b974b59c74140570847bb4a2774d41d1e5fae.zip
Adding debian version 3.2.1-3.debian/3.2.1-3debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/missing-sources/epoch/tests/unit/data')
-rw-r--r--debian/missing-sources/epoch/tests/unit/data/array_format.coffee106
-rw-r--r--debian/missing-sources/epoch/tests/unit/data/chart.coffee121
-rw-r--r--debian/missing-sources/epoch/tests/unit/data/keyvalue_format.coffee101
-rw-r--r--debian/missing-sources/epoch/tests/unit/data/tuple_format.coffee76
4 files changed, 404 insertions, 0 deletions
diff --git a/debian/missing-sources/epoch/tests/unit/data/array_format.coffee b/debian/missing-sources/epoch/tests/unit/data/array_format.coffee
new file mode 100644
index 0000000..a043a1e
--- /dev/null
+++ b/debian/missing-sources/epoch/tests/unit/data/array_format.coffee
@@ -0,0 +1,106 @@
+describe 'Epoch.Data.Format.array', ->
+ startTime = 1000
+
+ it 'should format flat arrays', ->
+ expected = [ {values: [{x: 0, y: 1}, {x: 1, y: 2}, {x: 2, y: 3}]} ]
+ assert.data expected, Epoch.Data.Format.array([1, 2, 3])
+
+ it 'should format multi-dimensional arrays', ->
+ expected = [
+ { values: [{x: 0, y: 1}, {x: 1, y: 2}]},
+ { values: [{x: 0, y: 3}, {x: 1, y: 4}]}
+ ]
+ assert.data expected, Epoch.Data.Format.array([[1, 2], [3, 4]])
+
+ it 'should respect the x option', ->
+ expected = [{values: [{x: 1, y: 1}, {x: 2, y: 2}]}]
+ result = Epoch.Data.Format.array [1, 2], {x: (d, i) -> i+1}
+ assert.data expected, result
+
+ it 'should respect the y option', ->
+ expected = [{values: [{x: 0, y: 2}, {x: 1, y: 4}]}]
+ result = Epoch.Data.Format.array [1, 2], {y: (d) -> d*2}
+ assert.data expected, result
+
+ it 'should format pie chart data with flat arrays', ->
+ input = [20, 30, 40]
+ expected = ({value: v} for v in input)
+ result = Epoch.Data.Format.array input, {type: 'pie'}
+ assert.equal expected.length, result.length, "Result did not have the expected number of layers"
+ for i in [0...expected.length]
+ assert.equal expected[i].value, result[i].value, "Result #{i} did not have the epected value"
+
+ it 'should not format pie chart data with multi-dimensional arrays', ->
+ assert.equal Epoch.Data.Format.array([[1], [2]], {type: 'pie'}).length, 0
+
+ it 'should format real-time plot data with flat arrays', ->
+ input = [1, 2, 3]
+ expected = [{ values: ({time: startTime+parseInt(i), y: v} for i,v of input) }]
+ result = Epoch.Data.Format.array(input, {type: 'time.line', startTime: startTime})
+ assert.timeData expected, result
+
+ it 'should format real-time plot data with multi-dimensional arrays', ->
+ input = [[1, 2], [3, 4]]
+ expected = []
+ for layer in input
+ expected.push {values: ({time: startTime+parseInt(i), y: v} for i, v of layer)}
+ result = Epoch.Data.Format.array(input, {type: 'time.line', startTime: startTime})
+ assert.timeData expected, result
+
+ it 'should format heatmap data with flat arrays', ->
+ input = [{'1': 1, '2': 2}, {'3': 3, '4': 4}]
+ expected = [{values: ({time: startTime+parseInt(i), histogram: h} for i, h of input)}]
+ result = Epoch.Data.Format.array(input, {type: 'time.heatmap', startTime: startTime})
+ assert.data expected, result, ['time', 'heatmap']
+
+ it 'should format heatmap data with multi-dimensional arrays', ->
+ input = [
+ [{'1': 1, '2': 2}, {'3': 3, '4': 4}],
+ [{'5': 5, '6': 6}, {'7': 7, '8': 8}]
+ ]
+ expected = [
+ { values: ({time: startTime+parseInt(i), histogram: h} for i, h of input[0]) },
+ { values: ({time: startTime+parseInt(i), histogram: h} for i, h of input[1]) },
+ ]
+ result = Epoch.Data.Format.array(input, {type: 'time.heatmap', startTime: startTime})
+ assert.data expected, result, ['time', 'heatmap']
+
+ it 'should correctly apply labels if the labels option is present', ->
+ labels = ['alpha', 'beta']
+ result = Epoch.Data.Format.array [[1], [2]], {labels: labels}
+ for i in [0...labels.length]
+ assert.equal labels[i], result[i].label
+
+ it 'should correctly apply labels if the autoLabels option is set', ->
+ labels = ['A', 'B', 'C']
+ result = Epoch.Data.Format.array [[1], [2], [3]], {autoLabels: true}
+ for i in [0...labels.length]
+ assert.equal labels[i], result[i].label
+
+ it 'should prefer the labels option to the autoLabels option if both are set', ->
+ labels = ['alpha', 'beta']
+ result = Epoch.Data.Format.array [[1], [2]], {labels: labels, autoLabels: true}
+ for i in [0...labels.length]
+ assert.equal labels[i], result[i].label
+
+ it 'should produce single series entries correctly', ->
+ result = Epoch.Data.Format.array.entry(2)
+ assert.isArray result
+ assert.equal 1, result.length
+ assert.isObject result[0]
+ assert.equal 0, result[0].x
+ assert.equal 2, result[0].y
+
+ it 'should produce multi-series entries correctly', ->
+ expected = [
+ { x: 0, y: 1 },
+ { x: 0, y: 2 },
+ { x: 0, y: 3 }
+ ]
+ result = Epoch.Data.Format.array.entry([1, 2, 3])
+ assert.isArray result
+ assert.equal 3, result.length
+ for i in [0...expected.length]
+ assert.isObject result[i]
+ assert.equal expected[i].x, result[i].x
+ assert.equal expected[i].y, result[i].y
diff --git a/debian/missing-sources/epoch/tests/unit/data/chart.coffee b/debian/missing-sources/epoch/tests/unit/data/chart.coffee
new file mode 100644
index 0000000..ed115a1
--- /dev/null
+++ b/debian/missing-sources/epoch/tests/unit/data/chart.coffee
@@ -0,0 +1,121 @@
+
+describe 'Epoch.Chart.options', ->
+ it 'should set the type option to "area" for basic area charts', ->
+ assert.equal new Epoch.Chart.Area().options.type, 'area'
+
+ it 'should set the type option to "bar" for basic bar charts', ->
+ assert.equal new Epoch.Chart.Bar().options.type, 'bar'
+
+ it 'should set the type option to "histogram" for basic histogram charts', ->
+ assert.equal new Epoch.Chart.Histogram().options.type, 'histogram'
+
+ it 'should set the type option to "line" for basic line charts', ->
+ assert.equal new Epoch.Chart.Line().options.type, 'line'
+
+ it 'should set the type option to "pie" for basic pie charts', ->
+ assert.equal new Epoch.Chart.Pie().options.type, 'pie'
+
+ it 'should set the type option to "scatter" for basic scatter charts', ->
+ assert.equal new Epoch.Chart.Scatter().options.type, 'scatter'
+
+ it 'should set the type option to "time.area" for real-time area charts', ->
+ assert.equal new Epoch.Time.Area().options.type, 'time.area'
+
+ it 'should set the type option to "time.bar" for real-time bar charts', ->
+ assert.equal new Epoch.Time.Bar().options.type, 'time.bar'
+
+ it 'should set the type option to "time.gauge" for real-time gauge charts', ->
+ assert.equal new Epoch.Time.Gauge().options.type, 'time.gauge'
+
+ it 'should set the type option to "time.heatmap" for real-time heatmap charts', ->
+ assert.equal new Epoch.Time.Heatmap().options.type, 'time.heatmap'
+
+ it 'should set the type option to "time.line" for real-time line charts', ->
+ assert.equal new Epoch.Time.Line().options.type, 'time.line'
+
+describe 'Epoch.Chart._formatData', ->
+ assertBasicData = (klassName, type) ->
+ data = [1, 2, 3, 4]
+ expected = Epoch.data 'array', data, {type: type}
+ chart = new Epoch.Chart[klassName]
+ data: data
+ dataFormat: 'array'
+ assert.data expected, chart.data
+
+ assertTimeData = (klassName, type) ->
+ data = [1, 2, 3, 4]
+ expected = Epoch.data 'array', data, {type: type, time: (d, i) -> parseInt(i)}
+ chart = new Epoch.Time[klassName]
+ data: data
+ dataFormat:
+ name: 'array'
+ options: { time: (d, i) -> parseInt(i) }
+ assert.timeData expected, chart.data
+
+ it 'should correctly detect and format array type data', ->
+ data = [1, 2, 3]
+ expected = Epoch.data 'array', data
+ chart = new Epoch.Chart.Base
+ data: data
+ dataFormat: 'array'
+ assert.data expected, chart.data
+
+ it 'should correctly detect and format tuple type data', ->
+ data = [[1, 1], [2, 4], [3, 78]]
+ expected = Epoch.data 'tuple', data
+ chart = new Epoch.Chart.Base
+ data: data
+ dataFormat: 'tuple'
+ assert.data expected, chart.data
+
+ it 'should correctly detect and format keyvalue type data', ->
+ data = [ {a: 20, b: 30, x: 10}, {a: 40, b: 50, x: 20} ]
+ expected = Epoch.data 'keyvalue', data, ['a', 'b'], { x: (d) -> d.x }
+ chart = new Epoch.Chart.Base
+ data: data
+ dataFormat:
+ name: 'keyvalue'
+ arguments: [['a', 'b']]
+ options: { x: (d, i) -> d.x }
+ assert.data expected, chart.data
+
+ it 'should correctly format area chart data', ->
+ assertBasicData 'Area', 'area'
+
+ it 'should correctly format bar chart data', ->
+ assertBasicData 'Bar', 'bar'
+
+ it 'should correctly format line data', ->
+ assertBasicData 'Line', 'line'
+
+ it 'should correctly format scatter data', ->
+ assertBasicData 'Scatter', 'scatter'
+
+ it 'should correctly format pie data', ->
+ data = [1, 2, 3]
+ expected = data.map (d) -> {value: d}
+ result = (new Epoch.Chart.Pie(data: data, dataFormat: 'array')).data
+ for i in [0...expected.length]
+ assert.equal expected[i].value, result[i].value
+
+ it 'should correctly format histogram data', ->
+ data = (parseInt(Math.random() * 100) for i in [0...100])
+ format = Epoch.data('array', data, { type: 'histogram' })
+ expected = (new Epoch.Chart.Histogram())._prepareData(format)
+ chart = new Epoch.Chart.Histogram({ data: data, dataFormat: 'array' })
+ assert.data expected, chart.data
+
+ it 'should correctly format real-time area data', ->
+ assertTimeData 'Area', 'time.area'
+
+ it 'should correctly format real-time bar data', ->
+ assertTimeData 'Bar', 'time.bar'
+
+ it 'should correctly format real-time heatmap data', ->
+ assertTimeData 'Heatmap', 'time.heatmap'
+
+ it 'should correctly format real-time line data', ->
+ assertTimeData 'Line', 'time.line'
+
+
+
diff --git a/debian/missing-sources/epoch/tests/unit/data/keyvalue_format.coffee b/debian/missing-sources/epoch/tests/unit/data/keyvalue_format.coffee
new file mode 100644
index 0000000..1ac5fcc
--- /dev/null
+++ b/debian/missing-sources/epoch/tests/unit/data/keyvalue_format.coffee
@@ -0,0 +1,101 @@
+describe 'Epoch.Data.Format.keyvalue', ->
+
+ data = [
+ { x: 1, a: 20, b: 30, c: 40, hist: 10, time: 0 },
+ { x: 2, a: 45, b: 83, c: 8, hist: 11, time: 1 },
+ { x: 3, a: 17, b: 72, c: 54, hist: 12, time: 2 },
+ { x: 4, a: 99, b: 19, c: 39, hist: 13, time: 3 }
+ ]
+
+ it 'should format a single series for basic plots', ->
+ expected = [{ values: (data.map (d, i) -> { x: parseInt(i), y: d.a }) }]
+ result = Epoch.Data.Format.keyvalue(data, ['a'])
+ assert.data expected, result
+
+ it 'should format multiple series for basic plots', ->
+ expected = [
+ { values: (data.map (d, i) -> {x: parseInt(i), y: d.a }) },
+ { values: (data.map (d, i) -> {x: parseInt(i), y: d.b }) },
+ { values: (data.map (d, i) -> {x: parseInt(i), y: d.c }) }
+ ]
+ result = Epoch.Data.Format.keyvalue(data, ['a', 'b', 'c'])
+ assert.data expected, result
+
+ it 'should format a single series for real-time plots', ->
+ expected = [
+ { values: (data.map (d, i) -> { time: d.time, y: d.a }) }
+ ]
+ result = Epoch.Data.Format.keyvalue(data, ['a'], { type: 'time.line', time: (d) -> d.time })
+ assert.data expected, result
+
+ it 'should format multiple series for real-time plots', ->
+ expected = [
+ { values: (data.map (d, i) -> { time: d.time, y: d.a }) }
+ { values: (data.map (d, i) -> { time: d.time, y: d.b }) }
+ { values: (data.map (d, i) -> { time: d.time, y: d.c }) }
+ ]
+ result = Epoch.Data.Format.keyvalue(data, ['a', 'b', 'c'], { type: 'time.line', time: (d) -> d.time })
+ assert.data expected, result
+
+ it 'should correctly format heatmap data', ->
+ expected = [
+ { values: (data.map (d, i) -> {time: d.time, histogram: d.hist }) }
+ ]
+ result = Epoch.Data.Format.keyvalue(data, ['hist'], {type: 'time.heatmap', time: ((d) -> d.time) })
+ assert.data expected, result
+
+ it 'should return an empty set for type time.gauge and type pie', ->
+ assert.equal Epoch.Data.Format.keyvalue(data, ['a'], {type: 'pie'}).length, 0
+ assert.equal Epoch.Data.Format.keyvalue(data, ['a'], {type: 'time.gauge'}).length, 0
+
+ it 'should respect the x option', ->
+ expected = [{ values: (data.map (d, i) -> {x: d.x, y: d.a }) }]
+ result = Epoch.Data.Format.keyvalue(data, ['a'], {x: (d) -> d.x})
+ assert.data expected, result
+
+ it 'should respect the y option', ->
+ expected = [{ values: (data.map (d, i) -> {x: parseInt(i), y: d.a + 2 }) }]
+ result = Epoch.Data.Format.keyvalue(data, ['a'], {y: (d) -> d + 2})
+ assert.data expected, result
+
+ it 'should apply key name labels by default', ->
+ labels = ['a', 'b', 'c', 'hist']
+ layers = Epoch.Data.Format.keyvalue(data, ['a', 'b', 'c', 'hist'])
+ for i in [0...labels.length]
+ assert.equal labels[i], layers[i].label
+
+ it 'should override key name labels with given labels', ->
+ labels = ['x', 'y', 'z']
+ layers = Epoch.Data.Format.keyvalue(data, ['a', 'b', 'c'], {labels: labels})
+ for i in [0...labels.length]
+ assert.equal labels[i], layers[i].label
+
+ it 'should apply automatic labels only when labels are not given and key labels are off', ->
+ labels = ['A', 'B']
+ layers = Epoch.Data.Format.keyvalue(data, ['a', 'b'], {keyLabels: false, autoLabels: true})
+ for i in [0...labels.length]
+ assert.equal labels[i], layers[i].label
+
+ it 'should produce single series entries correctly', ->
+ input = data[0]
+ keys = ['a']
+ expected = [{x: 0, y: input.a}]
+ result = Epoch.Data.Format.keyvalue.entry(input, keys)
+ assert.isArray result
+ assert.equal 1, result.length
+ assert.isObject result[0]
+ assert.equal 0, result[0].x
+ assert.equal input.a, result[0].y
+
+ it 'should produce multi-series entries correctly', ->
+ input = data[1]
+ keys = ['a', 'b', 'c']
+ options = {x: 'x'}
+ expected = ({x: input.x, y: input[key]} for key in keys)
+ result = Epoch.Data.Format.keyvalue.entry(input, keys, options)
+ assert.isArray result
+ assert.equal expected.length, result.length
+ for i in [0...expected.length]
+ assert.isObject result[i]
+ assert.equal expected[i].x, result[i].x
+ assert.equal expected[i].y, result[i].y
diff --git a/debian/missing-sources/epoch/tests/unit/data/tuple_format.coffee b/debian/missing-sources/epoch/tests/unit/data/tuple_format.coffee
new file mode 100644
index 0000000..a55f559
--- /dev/null
+++ b/debian/missing-sources/epoch/tests/unit/data/tuple_format.coffee
@@ -0,0 +1,76 @@
+describe 'Epoch.Data.Format.tuple', ->
+ it 'should format flat tuple arrays', ->
+ input = [[1, 2], [3, 4], [5, 6]]
+ expected = [{values: input.map((d) -> {x: d[0], y: d[1]})}]
+ result = Epoch.Data.Format.tuple(input)
+ assert.data expected, result
+
+ it 'should format nested layers of tuple arrays', ->
+ input = [
+ [ [1, 2], [3, 4] ],
+ [ [5, 6], [7, 8] ]
+ ]
+ expected = input.map (series) ->
+ {values: series.map((d) -> {x: d[0], y: d[1]})}
+ result = Epoch.Data.Format.tuple(input)
+ assert.data expected, result
+
+ it 'should respect the x option', ->
+ input = [[1, 2], [3, 4], [5, 6]]
+ expected = [{values: input.map((d, i) -> {x: i, y: d[1]})}]
+ result = Epoch.Data.Format.tuple(input, {x: (d, i) -> i})
+ assert.data expected, result
+
+ it 'should respect the y option', ->
+ input = [[1, 2], [3, 4], [5, 6]]
+ expected = [{values: input.map((d, i) -> {x: d[0], y: i})}]
+ result = Epoch.Data.Format.tuple(input, {y: (d, i) -> i})
+ assert.data expected, result
+
+ it 'should format flat tuples of real-time data', ->
+ input = [[1, 2], [3, 4], [5, 6]]
+ expected = [{values: input.map((d) -> {time: d[0], y: d[1]})}]
+ result = Epoch.Data.Format.tuple(input, {type: 'time.line'})
+ assert.data expected, result
+
+ it 'should format nested layers of real-time tuple data', ->
+ input = [
+ [ [1, 2], [3, 4] ],
+ [ [5, 6], [7, 8] ]
+ ]
+ expected = input.map (series) ->
+ {values: series.map((d) -> {time: d[0], y: d[1]})}
+ result = Epoch.Data.Format.tuple(input, {type: 'time.line'})
+ assert.data expected, result
+
+ it 'should respect the time option', ->
+ input = [[1, 2], [3, 4], [5, 6]]
+ expected = [{values: input.map((d, i) -> {time: i, y: d[1]})}]
+ result = Epoch.Data.Format.tuple(input, {type: 'time.line', time: (d, i) -> i})
+ assert.data expected, result
+
+ it 'should ignore heatmap, pie, and gauge charts', ->
+ input = [[1, 2], [3, 4], [5, 6]]
+ assert.equal 0, Epoch.Data.Format.tuple(input, {type: 'time.heatmap'}).length
+ assert.equal 0, Epoch.Data.Format.tuple(input, {type: 'time.gauge'}).length
+ assert.equal 0, Epoch.Data.Format.tuple(input, {type: 'pie'}).length
+
+ it 'should produce single series entries correctly', ->
+ input = [5, 6]
+ result = Epoch.Data.Format.tuple.entry(input)
+ assert.isArray result
+ assert.equal 1, result.length
+ assert.isObject result[0]
+ assert.equal input[0], result[0].x
+ assert.equal input[1], result[0].y
+
+ it 'should produce multi-series entries correctly', ->
+ input = [[5, -10], [4, 8], [2, 3]]
+ expected = ({x: d[0], y: d[1]} for d in input)
+ result = Epoch.Data.Format.tuple.entry(input)
+ assert.isArray result
+ assert.equal expected.length, result.length
+ for i in [0...expected.length]
+ assert.isObject result[i]
+ assert.equal expected[i].x, result[i].x
+ assert.equal expected[i].y, result[i].y