2018-03-29 17:17:19 +02:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
2018-05-13 14:28:10 +02:00
|
|
|
class TestTextWriter #< MiniTest::Test
|
2018-03-29 17:17:19 +02:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@machine = Risc.machine.boot
|
|
|
|
end
|
|
|
|
def test_init
|
|
|
|
@text_writer = TextWriter.new(@machine)
|
|
|
|
end
|
|
|
|
def test_write_fails
|
|
|
|
@text_writer = TextWriter.new(@machine)
|
|
|
|
assert_raises{ @text_writer.write_as_string} #must translate first
|
|
|
|
end
|
2018-05-13 14:28:10 +02:00
|
|
|
end
|
|
|
|
class TestTextWriterPositions < MiniTest::Test
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@machine = Risc.machine.boot
|
2018-05-16 20:00:14 +02:00
|
|
|
@machine.translate(:arm)
|
2018-05-13 14:28:10 +02:00
|
|
|
@machine.position_all
|
2018-03-29 17:17:19 +02:00
|
|
|
@text_writer = TextWriter.new(@machine)
|
2018-05-13 14:28:10 +02:00
|
|
|
end
|
|
|
|
def test_write_all
|
2018-03-29 17:17:19 +02:00
|
|
|
assert @text_writer.write_as_string
|
|
|
|
end
|
2018-05-13 14:28:10 +02:00
|
|
|
def test_sorted_class
|
|
|
|
assert_equal Array , @text_writer.sorted_objects.class
|
|
|
|
end
|
|
|
|
def test_sorted_positions1
|
|
|
|
sorted_objects = @text_writer.sorted_objects
|
|
|
|
sorted_objects.each_slice(2) do |l,r|
|
2018-05-13 17:01:45 +02:00
|
|
|
next unless r
|
2018-05-13 14:28:10 +02:00
|
|
|
assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.class}, #{r.class}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def test_sorted_positions2
|
|
|
|
sorted_objects = @text_writer.sorted_objects
|
|
|
|
sorted_objects.shift
|
|
|
|
sorted_objects.each_slice(2) do |l,r|
|
|
|
|
next unless r
|
|
|
|
assert Position.get(l).at < Position.get(r).at , "#{Position.get(l)} < #{Position.get(r)} , #{l.class}, #{r.class}"
|
|
|
|
end
|
|
|
|
end
|
2018-03-29 17:17:19 +02:00
|
|
|
end
|
|
|
|
end
|