Class: SequenceMovingAverageTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
MoreMath
Defined in:
tests/sequence_moving_average_test.rb

Constant Summary

Constants included from MoreMath

MoreMath::Infinity, MoreMath::STD_NORMAL_DISTRIBUTION, MoreMath::VERSION, MoreMath::VERSION_ARRAY, MoreMath::VERSION_BUILD, MoreMath::VERSION_MAJOR, MoreMath::VERSION_MINOR

Instance Method Summary collapse

Instance Method Details

#setupObject



9
10
11
# File 'tests/sequence_moving_average_test.rb', line 9

def setup
  @seq = Sequence.new([ 3, 1, 7, 5, 6 ])
end

#test_moving_averageObject



19
20
21
22
23
24
25
26
27
28
29
# File 'tests/sequence_moving_average_test.rb', line 19

def test_moving_average
  assert_equal @seq.elements.map(&:to_f),
    @seq.moving_average(1)
  assert_equal [ (3 + 1) / 2.0, (1 + 7) / 2.0, (7 + 5) / 2.0, (5 + 6) / 2.0 ],
    @seq.moving_average(2)
  assert_equal [ (3 + 1 + 7) / 3.0, (1 + 7 + 5) / 3.0, (7 + 5 + 6) / 3.0 ],
    @seq.moving_average(3)
  assert_equal [ (3 + 1 + 7 + 5) / 4.0, (1 + 7 + 5 + 6) / 4.0 ],
    @seq.moving_average(4)
  assert_equal [ @seq.mean ], @seq.moving_average(5)
end

#test_moving_average_failObject



13
14
15
16
17
# File 'tests/sequence_moving_average_test.rb', line 13

def test_moving_average_fail
  assert_raise(ArgumentError) { @seq.moving_average(0) }
  assert_raise(ArgumentError) { @seq.moving_average(-1) }
  assert_raise(ArgumentError) { @seq.moving_average(@seq.size + 1) }
end