2015-10-14 20:49:05 +02:00
|
|
|
require_relative '../../helper'
|
2015-10-19 13:46:12 +02:00
|
|
|
require "interpreter/interpreter"
|
|
|
|
|
|
|
|
# Fragments are small programs that we run through the interpreter and really only check
|
|
|
|
# - the no. of instructions processed
|
|
|
|
# - the stdout output
|
|
|
|
|
2014-05-21 20:13:12 +02:00
|
|
|
|
2014-05-21 20:37:04 +02:00
|
|
|
|
2014-05-21 20:13:12 +02:00
|
|
|
module Fragments
|
|
|
|
|
2015-10-19 13:46:12 +02:00
|
|
|
def setup
|
|
|
|
@stdout = ""
|
|
|
|
end
|
2015-07-18 13:33:09 +02:00
|
|
|
def check
|
2015-10-22 17:16:29 +02:00
|
|
|
machine = Register.machine.boot
|
2015-10-09 20:53:22 +02:00
|
|
|
machine.parse_and_compile @string_input
|
2015-10-19 13:46:12 +02:00
|
|
|
machine.collect
|
2015-11-05 11:22:48 +01:00
|
|
|
@interpreter = Interpreter::Interpreter.new
|
|
|
|
@interpreter.start machine.init
|
2015-10-19 13:46:12 +02:00
|
|
|
count = 0
|
|
|
|
begin
|
|
|
|
count += 1
|
|
|
|
#puts interpreter.instruction
|
2015-11-05 11:22:48 +01:00
|
|
|
@interpreter.tick
|
|
|
|
end while( ! @interpreter.instruction.nil?)
|
2015-10-19 13:46:12 +02:00
|
|
|
assert_equal @length , count
|
2015-11-05 11:22:48 +01:00
|
|
|
assert_equal @stdout , @interpreter.stdout
|
2014-06-05 12:02:36 +02:00
|
|
|
end
|
2015-05-16 11:53:10 +02:00
|
|
|
|
2014-05-21 20:13:12 +02:00
|
|
|
end
|