Sha256: ae1ac5e37e6d8494eaebe1a091db000245efb6662c0a3f9d2692eb97e133be44

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require File.expand_path 'test_helper', File.dirname(__FILE__)

class TestArduinoFirmata < MiniTest::Unit::TestCase

  def setup
    @arduino = ArduinoFirmata.connect ENV['ARDUINO']
  end

  def test_arduino
    assert @arduino.version > '2.0'
    @arduino.close
  end

  def test_digital_read
    0.upto(13).each do |pin|
      din = @arduino.digital_read pin
      assert [true,false].include? din
    end
    @arduino.close
  end

  def test_analog_read
    0.upto(5).each do |pin|
      ain = @arduino.analog_read pin
      assert 0 <= ain and ain < 1024
    end
    @arduino.close
  end

  def test_digital_write
    0.upto(13).each do |pin|
      assert @arduino.digital_write(pin, true) == true
      assert @arduino.digital_write(pin, false) == false
    end
    @arduino.close
  end

  def test_analog_write
    0.upto(13).each do |pin|
      value = rand(256)
      assert @arduino.analog_write(pin, value) == value
    end
    @arduino.close
  end

  def test_servo_write
    0.upto(13).each do |pin|
      angle = rand(181)
      assert @arduino.servo_write(pin, angle) == angle
    end
    @arduino.close
  end

  def test_pin_mode
    0.upto(13).each do |pin|
      mode = [ArduinoFirmata::OUTPUT, ArduinoFirmata::INPUT].sample
      assert @arduino.pin_mode(pin, mode) == mode
    end
    @arduino.close
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
arduino_firmata-0.2.4 test/test_arduino_firmata.rb
arduino_firmata-0.2.3 test/test_arduino_firmata.rb
arduino_firmata-0.2.2 test/test_arduino_firmata.rb
arduino_firmata-0.2.1 test/test_arduino_firmata.rb
arduino_firmata-0.2.0 test/test_arduino_firmata.rb
arduino_firmata-0.1.8 test/test_arduino_firmata.rb