-
Notifications
You must be signed in to change notification settings - Fork 433
/
status_helper_test.rb
35 lines (29 loc) · 1.48 KB
/
status_helper_test.rb
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
require File.expand_path(File.dirname(__FILE__) + "/..") + "/test_helper"
class StatusHelperTest < ActiveSupport::TestCase
test 'resample' do
# it can't do magic
assert_equal([], StatusHelper.resample([], 1000))
now = 10000
testarray = []
10.times do |i|
testarray << [now - i * 10, i]
end
# [[10000, 0], [9990, 1], [9980, 2], [9970, 3], [9960, 4], [9950, 5], [9940, 6], [9930, 7], [9920, 8], [9910, 9]]
# while the testarray increases, the timestamps go down, so the result needs to decrease
assert_equal([[9910.0, 9.0], [9919.0, 8.0], [9928.0, 7.0], [9937.0, 6.0], [9946.0, 5.0], [9955.0, 4.0], [9964.0, 3.0], [9973.0, 2.0], [9982.0, 1.0], [9991.0, 0.0]],
StatusHelper.resample(testarray, 10))
assert_equal([[9901.0, 9.0], [9919.0, 7.5], [9937.0, 5.5], [9955.0, 3.5], [9973.0, 1.5]],
StatusHelper.resample(testarray, 5))
# now increase the last sequence
testarray << [now+1, 1000]
assert_equal([[9900.9, 9.0], [9919.1, 7.5], [9937.300000000001, 5.5], [9955.500000000002, 3.5], [9973.700000000003, 1.5]],
StatusHelper.resample(testarray, 5))
# now add a gap
testarray.delete [9980, 2]
testarray.delete [9970, 3]
testarray.delete [9960, 4]
# the value stays the same in 2 intervals
assert_equal([[9900.9, 9.0], [9919.1, 7.5], [9937.300000000001, 5.5], [9955.500000000002, 5.5], [9973.700000000003, 1.0]],
StatusHelper.resample(testarray, 5))
end
end