-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathpoint_spec.rb
More file actions
73 lines (59 loc) · 2.53 KB
/
point_spec.rb
File metadata and controls
73 lines (59 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'spec_helper'
describe Squid::Point do
let(:options) { {minmax: minmax, height: height, labels: labels, stack: stack?, formats: formats} }
let(:minmax) { [-50, 150] }
let(:height) { 100 }
let(:labels) { [false] }
let(:stack?) { false }
let(:formats) { [:percentage, :seconds] }
let(:series) { [[-10.0, 109.9, 30.0], [nil, 20.0, -50.0]] }
describe '.for' do
subject(:points) { Squid::Point.for series, options }
it 'calculates the height considering each value within minmax, relative to the height' do
expect(points.first.map &:height).to eq [-5.0, 54.95, 15.0]
expect(points.last.map &:height).to eq [nil, 10.0, -25.0]
end
it 'calculates the y considering the height and the y of the "0" value' do
expect(points.first.map &:y).to eq [20.0, 79.95, 40.0]
expect(points.last.map &:y).to eq [nil, 35.0, 0.0]
end
it 'returns the index of each value' do
expect(points.first.map &:index).to eq [0, 1, 2]
expect(points.last.map &:index).to eq [0, 1, 2]
end
it 'returns whether each value is negative' do
expect(points.first.map &:negative).to eq [true, false, false]
expect(points.last.map &:negative).to eq [false, false, true]
end
it 'does not returns the labels by default' do
expect(points.first.map &:label).to eq [nil, nil, nil]
expect(points.last.map &:label).to eq [nil, nil, nil]
end
context 'given the :labels option is set' do
let(:labels) { [true, true] }
it 'returns a formatted label for each value' do
expect(points.first.map &:label).to eq %w(-10.0% 109.9% 30.0%)
expect(points.last.map &:label).to eq ['', '0:20', '-0:50']
end
end
context 'given the series are stacked' do
let(:stack?) { true }
it 'the height of each value is not affected' do
expect(points.first.map &:height).to eq [-5.0, 54.95, 15.0]
expect(points.last.map &:height).to eq [nil, 10.0, -25.0]
end
it 'the y of each value is affected by the previous value of the same index with the same signum' do
expect(points.first.map &:y).to eq [20.0, 79.95, 40.0]
expect(points.last.map &:y).to eq [nil, 89.95, 0.0]
end
end
context "given a positive min" do
let(:minmax) { [100, 150] }
let(:series) { [[110.0, 100, 130.0], [nil, 120.0, 150.0]] }
it 'generates y values relative to the minimum' do
expect(points.first.map &:y).to eq [20.0, 0.0, 60.0]
expect(points.last.map &:y).to eq [nil, 40.0, 100.0]
end
end
end
end