Sha256: af30cf769e2355b00bddd56d434ac838b2c33ac4508fabea348a5fad49f80895

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

require 'test_helper'

class CInstructionTest < Minitest::Test
  def test_translation_of_unconditional_jump
    bytecode = CInstruction.translate('0;JMP')
    assert_equal '1110101010000111', bytecode
  end

  def test_translation_of_assignment
    bytecode = CInstruction.translate('A=M+1')
    assert_equal '1111110111100000', bytecode
  end

  def test_that_bad_instruction_raises_error
    assert_raises(ParserError) { CInstruction.translate(';JMP') }
  end

  def test_that_computation_translator_writes_on_output
    bytecode = nil
    ComputationTranslator.stub(:translate, '0000000') do
      bytecode = CInstruction.translate('0;JMP')
    end

    assert_equal '1110000000000111', bytecode
  end

  def test_that_destination_translator_writes_on_output
    bytecode = nil
    DestinationTranslator.stub(:translate, '111') do
      bytecode = CInstruction.translate('0;JMP')
    end

    assert_equal '1110101010111111', bytecode
  end

  def test_that_jump_translator_writes_on_output
    bytecode = nil
    JumpTranslator.stub(:translate, '000') do
      bytecode = CInstruction.translate('0;JMP')
    end

    assert_equal '1110101010000000', bytecode
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hack_assembler-0.2.0 test/c_instruction_test.rb
hack_assembler-0.1.0 test/c_instruction_test.rb