test/test_cm17a_device.rb in x10-cm17a-0.9.0 vs test/test_cm17a_device.rb in x10-cm17a-1.0.0
- old
+ new
@@ -24,11 +24,11 @@
class << self
def setup_controller(controller)
X10.controller = controller
controller.mock_handle(:device, 1) { |house, unit|
X10::Cm17a::Device.new(house, unit, controller)
- }
+ }
end
def use
super do |mock|
setup_controller(mock)
@@ -55,76 +55,66 @@
end
def test_on
MockController.use do |controller|
controller.mock_handle(:command, 1) { |house, unit, cmd, step|
- assert_equal X10::Cm17a::ON, cmd
+ assert_equal :on, cmd
assert_equal 0, step
}
dev = X10.device('a1')
dev.on
end
end
def test_off
MockController.use do |controller|
controller.mock_handle(:command, 1) { |house, unit, cmd, step|
- assert_equal X10::Cm17a::OFF, cmd
+ assert_equal :off, cmd
assert_equal 0, step
}
dev = X10.device('a1')
dev.off
end
end
- def test_step_size
- MockController.use do |controller|
- dev = X10.device('a1')
- assert_equal 0, dev.send(:steps_for, 0.0)
- assert_equal 5, dev.send(:steps_for, 0.5)
- assert_equal 5, dev.send(:steps_for, -0.5)
- assert_equal 10, dev.send(:steps_for, 1.0)
- end
- end
-
def test_adjust
MockController.use do |controller|
controller.mock_handle(:command, 2) { |house, unit, cmd, step|
if step == 4
assert_equal 4, step
- assert_equal X10::Cm17a::BRIGHTEN, cmd
+ assert_equal :brighten, cmd
else
assert_equal 3, step
- assert_equal X10::Cm17a::DIM, cmd
+ assert_equal :dim, cmd
end
}
dev = X10.device('a1')
- dev.adjust(0.4)
- dev.adjust(-0.3)
+ dev.step(4)
+ dev.step(-3)
end
end
def test_big_adjustments
MockController.use do |controller|
controller.mock_handle(:command, 2) { |house, unit, cmd, step|
- assert_equal X10::Cm17a::DIM, cmd
+ assert_equal :dim, cmd
if step == 6
assert_equal 6, step
else
assert_equal 3, step
end
}
dev = X10.device('a1')
- dev.adjust(-0.9)
+ dev.step(-9)
end
end
def test_small_adjustments
MockController.use do |controller|
controller.mock_handle(:command, 0) { }
dev = X10.device('a1')
- dev.adjust(0.0)
+ dev.step(0)
end
end
def test_device_addressing
MockController.use do |controller|
@@ -133,80 +123,12 @@
assert_equal 2, unit
}
dev = X10.device('b3')
dev.off
dev.on
- dev.adjust(1)
- dev.adjust(-1)
+ dev.step(1)
+ dev.step(-1)
end
- end
-end
-
-######################################################################
-class TestCm17aNonApi < Test::Unit::TestCase
- def setup
- X10.controller = MockController.new
- X10.controller.mock_handle(:command) { }
- MockController.setup_controller(X10.controller)
- @dev = X10.device("a1")
- end
-
- def teardown
- X10.controller = nil
- end
-
- def test_query
- @dev.on
- assert @dev.send(:on?)
- assert ! @dev.send(:off?)
- @dev.off
- assert ! @dev.send(:on?)
- assert @dev.send(:off?)
- @dev.on
- assert @dev.send(:on?)
- assert ! @dev.send(:off?)
- end
-
- def test_undefined_on_off_state
- assert_raises(X10::X10Error) {
- @dev.send(:on?)
- }
- end
-
- def test_undefined_level
- assert_raises(X10::X10Error) {
- @dev.send(:level)
- }
- end
-
- def test_undefined_level_after_adjust
- assert_raises(X10::X10Error) {
- @dev.adjust(0.3)
- @dev.send(:level)
- }
- end
-
- def test_level
- @dev.off
- assert_equal 0.0, @dev.send(:level)
-
- @dev.adjust(-0.5)
- assert_equal 0.0, @dev.send(:level)
-
- @dev.on
- assert_equal 1.0, @dev.send(:level)
-
- @dev.adjust(0.1)
- assert_equal 1.0, @dev.send(:level)
-
- @dev.adjust(-0.5)
- assert_equal 0.5, @dev.send(:level)
-
- @dev.adjust(-0.5)
- assert_equal 0.0, @dev.send(:level)
-
- @dev.adjust(-0.5)
- assert_equal 0.0, @dev.send(:level)
end
end
######################################################################
class TestCm17aController < Test::Unit::TestCase