Skip to content

Commit

Permalink
Merge pull request #18 from mumuki/fix-final-board-postcondition
Browse files Browse the repository at this point in the history
Fix final board postcondition
  • Loading branch information
flbulgarelli authored Jan 4, 2018
2 parents f3135d0 + 26b9b4d commit a176a98
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 76 deletions.
5 changes: 4 additions & 1 deletion lib/assets_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
class Mumukit::Server::App < Sinatra::Base
register Sinatra::CrossOrigin

configure do
enable :cross_origin
end

def self.get_asset(route, path, type)
get "/assets/#{route}" do
cross_origin
send_file File.expand_path("bower_components/#{path}"), { type: type }
end
end
Expand Down
19 changes: 10 additions & 9 deletions lib/checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ def check_final_board(output, expected)
result = output[:result]

assert_not_boom status, result
actual = result[:finalBoard][:table][:gbb]

expected_board = result[:extraBoard]
actual_board = result[:finalBoard]
boards_match = board_json(expected_board).eql? board_json(actual_board)
headers_match = expected_board[:head].eql?(actual_board[:head]) || !@options[:check_head_position]

fail_with status: :check_final_board_failed_different_boards,
result: {
initial: result[:initialBoard],
expected: result[:extraBoard],
actual: result[:finalBoard]
} if clean(actual) != clean(expected)
expected: expected_board,
actual: actual_board
} unless boards_match && headers_match
end

def check_error(output, expected)
Expand Down Expand Up @@ -77,11 +81,8 @@ def fail_with(error)
fail error.to_json
end

def clean(gbb)
clean_gbb = gbb.gsub /\r|\n| Azul 0| Negro 0| Rojo 0| Verde 0/, ''
decapitated_gbb = clean_gbb.gsub /head \d+ \d+/, ''

@options[:check_head_position] ? clean_gbb : decapitated_gbb
def board_json(board)
board[:table][:json]
end

def convert_known_reason_code(code)
Expand Down
10 changes: 9 additions & 1 deletion lib/gobstones/batch_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ def parse_options(test)
struct(key: :show_final_board, default: true),
struct(key: :check_head_position, default: false),
struct(key: :subject, default: nil)
].map { |it| [it.key, test[it.key] || it.default] }.to_h
].map { |it| [
it.key,
if test[it.key].nil?
it.default
else
test[it.key]
end
]
}.to_h
end

def preconditions
Expand Down
127 changes: 62 additions & 65 deletions spec/metatest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,13 @@
end
let(:dummy_view_board) do
{ head: { x: 0, y: 0 }, width: 3, height: 3, table: {
json: []
json: [[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]]
} }
end
let(:dummy_gbb) do
'GBB/1.0\r\nsize 1 1\r\nhead 0 0\r\n'
end
let(:exit_status) { 29 }
let(:compilation_board) {
[
{
status: "passed",
result: {
extraBoard: dummy_view_board,
initialBoard: dummy_view_board,
finalBoard: {
head: { x: 0, y: 1 },
width: 3,
height: 3,
table: {
gbb: "GBB/1.0\r\nsize 3 3\r\nhead 1 0\r\n",
json: []
},
returnValue: exit_status
},
}
}
]
}

let(:compilation_boom) do
[
{
Expand All @@ -62,48 +43,79 @@
]
end

def board_with_stones(headX, headY, cell10 = {})
{
head: { x: headX, y: headY },
width: 3,
height: 3,
table: {
gbb: dummy_gbb,
json: [
[{}, {}, {}],
[{}, {}, {}],
[{ black: 1, green: 1 }, cell10, {}]
]
},
returnValue: exit_status
}
end

def compilation_board(expected_board = dummy_view_board)
[
{
status: "passed",
result: {
extraBoard: expected_board,
initialBoard: dummy_view_board,
finalBoard: board_with_stones(0, 1)
}
}
]
end

describe 'final_board postcondition' do

context 'when the program returns a final board' do
let(:examples) {
[{
id: 0,
postconditions: {
final_board: dummy_gbb
}
}]
}

let(:compilation) { compilation_board }
context 'when the program returns a final board' do

context 'when passes with check_head_position=true' do
let(:examples) {
[{
id: 0,
postconditions: {
final_board: "GBB/1.0\r\nsize 3 3\r\nhead 1 0\r\n"
}
}]
let(:compilation) {
compilation_board board_with_stones 0, 1
}

it { expect(result[0][0]).to include :passed }
end

context 'when passes with check_head_position=false' do
let(:compilation) {
compilation_board board_with_stones 5, 5
}

let(:options) { { show_initial_board: false, check_head_position: false } }

let(:examples) {
[{
id: 0,
postconditions: {
final_board: "GBB/1.0\r\nsize 3 3\r\nhead 5 5\r\n"
}
}]
it { expect(result[0][0]).to include :passed }
end

context 'when fails by different boards (header)' do
let(:compilation) {
compilation_board board_with_stones 2, 2
}

it { expect(result[0][0]).to include :passed }
it { expect(result[0][0]).to include :failed }
it { expect(result[0][0][2]).to include "Expected final board" }
end

context 'when fails by different boards' do
let(:examples) {
[{
id: 0,
postconditions: {
final_board: "GBB/1.0\r\nsize 3 3\r\nhead 2 2\r\n"
}
}]
context 'when fails by different boards (stones)' do
let(:compilation) {
compilation_board board_with_stones 0, 1, { blue: 9 }
}

it { expect(result[0][0]).to include :failed }
Expand All @@ -113,23 +125,10 @@
end

context 'when the program does boom' do

let(:compilation) { compilation_boom }

context 'when fails because the program did boom' do
let(:examples) {
[{
id: 0,
postconditions: {
final_board: "GBB/1.0\r\nsize 3 3\r\nhead 1 0\r\n"
}
}]
}

it { expect(result[0][0]).to include :failed }
it { expect(result[0][0][2]).to include "The program did BOOM." }
end

it { expect(result[0][0]).to include :failed }
it { expect(result[0][0][2]).to include "The program did BOOM." }
end

end
Expand All @@ -153,7 +152,6 @@
end

context 'when the program does boom' do

let(:compilation) { compilation_boom }

context 'with the same reason as expected' do
Expand Down Expand Up @@ -190,7 +188,6 @@
}

context 'when the program returns a final board' do

let(:compilation) { compilation_board }

context 'when passes with equal value' do
Expand Down

0 comments on commit a176a98

Please sign in to comment.