Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 20th, 2012  |  syntax: None  |  size: 0.90 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # coding: utf-8
  2. $: << File.dirname(__FILE__) + '/terminal'
  3. $: << File.dirname(__FILE__) + '/logic_device'
  4.  
  5. require 'terminal'
  6. require 'xor'
  7. require 'and'
  8.  
  9. describe LogicDevice do
  10.   RSpec::Matchers.define :compute do |*data, expect|
  11.     match do |actual|
  12.       logic = actual.new(data.size)
  13.       data.each_with_index do |val, index|
  14.         logic.get_input_terminal(index).state = val
  15.       end
  16.       (@result = logic.get_output_terminal.state) == expect[:to]
  17.     end
  18.  
  19.     failure_message_for_should do
  20.       RSpec::Expectations::Differ.new.diff_as_object(@result, expect[:to])
  21.     end
  22.   end
  23.  
  24.   describe Xor do
  25.     subject { Xor }
  26.     it { should compute 1, 0, to: 1 }
  27.     it { should compute 0, 1, to: 1 }
  28.     it { should compute 0, 0, to: 0 }
  29.     it { should compute 1, 1, to: 0 }
  30.   end
  31.  
  32.   describe And do
  33.     subject { And }
  34.     it { should compute 1, 1, 1, to: 1 }
  35.     it { should compute 1, 1, 0, to: 0 }
  36.   end
  37. end