Sha256: c99ad36c45d93b3aa2e2dcef465e28f21a5ac97e8c37aa9cba32b1f64d781346
Contents?: true
Size: 581 Bytes
Versions: 12
Compression:
Stored size: 581 Bytes
Contents
#!/usr/bin/env ruby require 'test/unit' require 'flexmock' class TemperatureSampler def initialize(sensor) @sensor = sensor end def average_temp total = (0...3).collect { @sensor.read_temperature }.inject { |i, s| i + s } total / 3.0 end end class TestTemperatureSampler < Test::Unit::TestCase def test_tempurature_sampler readings = [10, 12, 14] mock_sensor = FlexMock.new mock_sensor.mock_handle(:read_temperature) { readings.shift } sampler = TemperatureSampler.new(mock_sensor) assert_equal 12, sampler.average_temp end end
Version data entries
12 entries across 12 versions & 1 rubygems