gobstones 0.0.1.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -3
- data/.ruby-version +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG +22 -2
- data/Gemfile +3 -3
- data/Gemfile.lock +32 -27
- data/bin/gobstones +1 -1
- data/examples/.gitkeep +0 -0
- data/gobstones.gemspec +2 -2
- data/lib/gobstones/cli/board_template +1 -1
- data/lib/gobstones/cli/printer.rb +1 -1
- data/lib/gobstones/cli/runner.rb +8 -2
- data/lib/gobstones/extensions/all.rb +2 -1
- data/lib/gobstones/extensions/boolean.rb +1 -1
- data/lib/gobstones/extensions/fixnum.rb +1 -1
- data/lib/gobstones/extensions/string.rb +9 -0
- data/lib/gobstones/lang/all.rb +1 -1
- data/lib/gobstones/lang/commands/all.rb +3 -2
- data/lib/gobstones/lang/commands/boom_cmd.rb +6 -3
- data/lib/gobstones/lang/commands/command_block.rb +1 -1
- data/lib/gobstones/lang/commands/conditional_cmd.rb +5 -1
- data/lib/gobstones/lang/commands/ir_al_origen_cmd.rb +1 -1
- data/lib/gobstones/lang/commands/mover_cmd.rb +4 -2
- data/lib/gobstones/lang/commands/multiple_assignment.rb +35 -0
- data/lib/gobstones/lang/commands/poner_cmd.rb +8 -4
- data/lib/gobstones/lang/commands/procedure_call.rb +1 -9
- data/lib/gobstones/lang/commands/repeat_with_cmd.rb +10 -6
- data/lib/gobstones/lang/commands/sacar_cmd.rb +9 -7
- data/lib/gobstones/lang/commands/{assignments.rb → single_assignment.rb} +5 -3
- data/lib/gobstones/lang/commands/skip_cmd.rb +2 -2
- data/lib/gobstones/lang/commands/vaciar_tablero_cmd.rb +1 -1
- data/lib/gobstones/lang/commands/while_cmd.rb +1 -1
- data/lib/gobstones/lang/definitions/all.rb +1 -1
- data/lib/gobstones/lang/definitions/definition.rb +47 -5
- data/lib/gobstones/lang/definitions/definition_call.rb +17 -5
- data/lib/gobstones/lang/definitions/function.rb +9 -0
- data/lib/gobstones/lang/definitions/main.rb +1 -1
- data/lib/gobstones/lang/definitions/no_return_statement.rb +7 -3
- data/lib/gobstones/lang/definitions/procedure.rb +5 -20
- data/lib/gobstones/lang/definitions/return_from_function.rb +12 -2
- data/lib/gobstones/lang/definitions/return_from_main.rb +5 -1
- data/lib/gobstones/lang/definitions/var_tuple.rb +13 -1
- data/lib/gobstones/lang/expressions/all.rb +1 -1
- data/lib/gobstones/lang/expressions/arithmetic_expressions.rb +1 -1
- data/lib/gobstones/lang/expressions/boolean_expressions.rb +3 -2
- data/lib/gobstones/lang/expressions/enclosed_by_parens_expression.rb +17 -0
- data/lib/gobstones/lang/expressions/function_call.rb +1 -1
- data/lib/gobstones/lang/expressions/one_arg_expression.rb +16 -4
- data/lib/gobstones/lang/expressions/primitive_functions.rb +18 -12
- data/lib/gobstones/lang/expressions/two_arg_expression.rb +7 -3
- data/lib/gobstones/lang/expressions/type_bound_functions.rb +1 -1
- data/lib/gobstones/lang/expressions/var_name.rb +9 -3
- data/lib/gobstones/lang/literals/all.rb +1 -1
- data/lib/gobstones/lang/literals/colors.rb +1 -1
- data/lib/gobstones/lang/literals/literal.rb +31 -21
- data/lib/gobstones/lang/literals/number.rb +1 -1
- data/lib/gobstones/lang/program.rb +13 -4
- data/lib/gobstones/modules/equal_by_class.rb +1 -1
- data/lib/gobstones/parser/ast/ast.rb +12 -8
- data/lib/gobstones/parser/grammar/gobstones.treetop +4 -4
- data/lib/gobstones/parser/parse_error.rb +1 -1
- data/lib/gobstones/runner/all.rb +1 -2
- data/lib/gobstones/runner/board.rb +13 -4
- data/lib/gobstones/runner/cell.rb +10 -0
- data/lib/gobstones/runner/errors/all.rb +1 -1
- data/lib/gobstones/runner/errors/definition_not_found_error.rb +1 -1
- data/lib/gobstones/runner/execution_context.rb +66 -16
- data/lib/gobstones/runner/head.rb +17 -3
- data/spec/gobstones_lang_test_objects.rb +75 -0
- data/spec/lang/commands/boom_cmd_spec.rb +3 -3
- data/spec/lang/commands/cmd_block_spec.rb +14 -14
- data/spec/lang/commands/if_cmd_spec.rb +21 -20
- data/spec/lang/commands/ir_al_origen_cmd_spec.rb +3 -3
- data/spec/lang/commands/mover_cmd_spec.rb +12 -14
- data/spec/lang/commands/multiple_assignment_spec.rb +37 -0
- data/spec/lang/commands/poner_cmd_spec.rb +13 -14
- data/spec/lang/commands/procedure_call_spec.rb +19 -24
- data/spec/lang/commands/procedure_spec.rb +32 -36
- data/spec/lang/commands/repeat_with_cmd_spec.rb +39 -20
- data/spec/lang/commands/sacar_cmd_spec.rb +17 -16
- data/spec/lang/commands/single_assignment_spec.rb +13 -0
- data/spec/lang/commands/skip_cmd_spec.rb +2 -2
- data/spec/lang/commands/vaciar_tablero_cmd_spec.rb +7 -6
- data/spec/lang/commands/while_cmd_spec.rb +21 -15
- data/spec/lang/definitions/no_return_statement_spec.rb +10 -0
- data/spec/lang/definitions/var_tuple_spec.rb +16 -0
- data/spec/lang/expressions/arithmetic_expressions_spec.rb +15 -15
- data/spec/lang/expressions/boolean_expressions_spec.rb +35 -25
- data/spec/lang/expressions/comparison_expressions_spec.rb +25 -28
- data/spec/lang/expressions/enclosed_by_parens_expression_spec.rb +11 -0
- data/spec/lang/expressions/function_call_spec.rb +29 -0
- data/spec/lang/expressions/primitive_functions_spec.rb +60 -62
- data/spec/lang/expressions/type_bound_functions_spec.rb +13 -13
- data/spec/lang/expressions/var_name_spec.rb +20 -8
- data/spec/lang/literals/booleans_spec.rb +5 -7
- data/spec/lang/literals/colors_spec.rb +4 -4
- data/spec/lang/literals/directions_spec.rb +12 -12
- data/spec/lang/literals/numbers_spec.rb +2 -2
- data/spec/matchers/parse_matcher.rb +9 -10
- data/spec/parser/arithmetic_expressions_spec.rb +19 -19
- data/spec/parser/assignments_spec.rb +24 -10
- data/spec/parser/boolean_expressions_spec.rb +18 -18
- data/spec/parser/command_block_spec.rb +17 -19
- data/spec/parser/data_types_spec.rb +23 -23
- data/spec/parser/function_calls_spec.rb +13 -12
- data/spec/parser/function_definitions_spec.rb +13 -18
- data/spec/parser/gobstones_program_spec.rb +15 -15
- data/spec/parser/if_command_spec.rb +13 -12
- data/spec/parser/main_definition_spec.rb +12 -12
- data/spec/parser/nested_expressions_spec.rb +16 -20
- data/spec/parser/primitive_expressions_spec.rb +27 -33
- data/spec/parser/procedure_calls_spec.rb +12 -12
- data/spec/parser/procedure_definitions_spec.rb +10 -16
- data/spec/parser/repeat_with_command_spec.rb +7 -10
- data/spec/parser/simple_commands_spec.rb +10 -10
- data/spec/parser/treetop_parser_spec.rb +11 -10
- data/spec/parser/var_tuple_spec.rb +7 -11
- data/spec/parser/while_command_spec.rb +9 -9
- data/spec/runner/board_spec.rb +23 -27
- data/spec/runner/cell_spec.rb +34 -38
- data/spec/runner/execution_context_spec.rb +38 -24
- data/spec/runner/head_spec.rb +54 -63
- data/spec/spec_helper.rb +4 -1
- data/spec/type_checker_spec.rb +13 -13
- metadata +33 -18
- data/lib/gobstones/lang/expressions/parentheses_expression.rb +0 -13
- data/spec/lang/commands/assignments_spec.rb +0 -13
data/spec/runner/cell_spec.rb
CHANGED
@@ -1,72 +1,68 @@
|
|
1
1
|
describe Cell do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:blue) { Azul.new }
|
5
|
-
let(:green) { Verde.new }
|
6
|
-
let(:red) { Rojo.new }
|
7
|
-
let(:colors) { [blue, black, red, green] }
|
3
|
+
let(:colors) { [azul, negro, rojo, verde] }
|
8
4
|
let(:cell) { Cell.new }
|
9
5
|
|
10
|
-
it "
|
11
|
-
expect(cell.are_there_balls?(
|
12
|
-
expect(cell.are_there_balls?(
|
13
|
-
expect(cell.are_there_balls?(
|
14
|
-
expect(cell.are_there_balls?(
|
6
|
+
it "answers that there are no balls of a given color" do
|
7
|
+
expect(cell.are_there_balls?(azul)).to be false
|
8
|
+
expect(cell.are_there_balls?(negro)).to be false
|
9
|
+
expect(cell.are_there_balls?(rojo)).to be false
|
10
|
+
expect(cell.are_there_balls?(verde)).to be false
|
15
11
|
end
|
16
12
|
|
17
|
-
it "
|
18
|
-
cell.put
|
19
|
-
cell.put
|
13
|
+
it "answers that there are balls of a given color when adding some" do
|
14
|
+
cell.put azul
|
15
|
+
cell.put rojo
|
20
16
|
|
21
|
-
expect(cell.are_there_balls?(
|
22
|
-
expect(cell.are_there_balls?(
|
23
|
-
expect(cell.are_there_balls?(
|
24
|
-
expect(cell.are_there_balls?(
|
17
|
+
expect(cell.are_there_balls?(azul)).to be true
|
18
|
+
expect(cell.are_there_balls?(negro)).to be false
|
19
|
+
expect(cell.are_there_balls?(rojo)).to be true
|
20
|
+
expect(cell.are_there_balls?(verde)).to be false
|
25
21
|
end
|
26
22
|
|
27
|
-
it "
|
28
|
-
5.times { cell.put
|
23
|
+
it "answers the number of balls of a given color" do
|
24
|
+
5.times { cell.put verde }
|
29
25
|
|
30
|
-
expect(cell.number_of_balls(
|
31
|
-
expect(cell.number_of_balls(
|
32
|
-
expect(cell.number_of_balls(
|
33
|
-
expect(cell.number_of_balls(
|
26
|
+
expect(cell.number_of_balls(azul)).to eq(0)
|
27
|
+
expect(cell.number_of_balls(negro)).to eq(0)
|
28
|
+
expect(cell.number_of_balls(rojo)).to eq(0)
|
29
|
+
expect(cell.number_of_balls(verde)).to eq(5)
|
34
30
|
end
|
35
31
|
|
36
|
-
it "
|
37
|
-
5.times { cell.put
|
38
|
-
3.times { cell.take_out
|
32
|
+
it "allows to take out some balls" do
|
33
|
+
5.times { cell.put azul }
|
34
|
+
3.times { cell.take_out azul }
|
39
35
|
|
40
|
-
expect(cell.are_there_balls?(
|
41
|
-
expect(cell.number_of_balls(
|
36
|
+
expect(cell.are_there_balls?(azul)).to be true
|
37
|
+
expect(cell.number_of_balls(azul)).to eq(2)
|
42
38
|
end
|
43
39
|
|
44
|
-
it "
|
45
|
-
expect { cell.take_out
|
40
|
+
it "raises an error if it's not possible to take out balls" do
|
41
|
+
expect { cell.take_out rojo }.to raise_error(EmptyCellError)
|
46
42
|
end
|
47
43
|
|
48
|
-
it "
|
44
|
+
it "fails passing something that is not a color" do
|
49
45
|
expect { cell.put("not a color") }.to raise_error
|
50
46
|
expect { cell.take_out(42) }.to raise_error
|
51
47
|
expect { cell.are_there_balls?(Norte) }.to raise_error
|
52
48
|
expect { cell.number_of_balls(nil) }.to raise_error
|
53
49
|
end
|
54
50
|
|
55
|
-
it "
|
51
|
+
it "clears its contents" do
|
56
52
|
colors.each { |color| cell.put color }
|
57
53
|
|
58
54
|
cell.empty!
|
59
55
|
|
60
|
-
colors.each { |color| expect(cell.are_there_balls?(color)).to
|
56
|
+
colors.each { |color| expect(cell.are_there_balls?(color)).to be false }
|
61
57
|
end
|
62
58
|
|
63
|
-
it "
|
64
|
-
expect(cell.empty?).to
|
59
|
+
it "is empty if it doesn't have any balls" do
|
60
|
+
expect(cell.empty?).to be true
|
65
61
|
end
|
66
62
|
|
67
|
-
it "
|
63
|
+
it "is not empty it it has some balls" do
|
68
64
|
colors.each { |color| cell.put color }
|
69
|
-
expect(cell.empty?).to
|
65
|
+
expect(cell.empty?).to be false
|
70
66
|
end
|
71
67
|
|
72
|
-
end
|
68
|
+
end
|
@@ -1,48 +1,40 @@
|
|
1
1
|
describe ExecutionContext do
|
2
2
|
|
3
|
-
let(:context) {
|
3
|
+
let(:context) { clean_context }
|
4
4
|
|
5
5
|
describe "variables context" do
|
6
6
|
|
7
|
-
|
8
|
-
let(:norte) { Norte.new }
|
9
|
-
|
10
|
-
it "should allow to set & get a variable" do
|
7
|
+
it "allows to set/get a variable" do
|
11
8
|
context.set 'myColor', negro
|
12
9
|
|
13
10
|
expect(context.get('myColor')).to eq(negro)
|
14
11
|
end
|
15
12
|
|
16
|
-
it "
|
13
|
+
it "allows to set/get more than one variable" do
|
17
14
|
context.set 'dir', norte
|
18
|
-
context.set 'bool',
|
15
|
+
context.set 'bool', true_value
|
19
16
|
|
20
17
|
expect(context.get('dir')).to eq(norte)
|
21
|
-
expect(context.get('bool')).to eq(
|
18
|
+
expect(context.get('bool')).to eq(true_value)
|
22
19
|
end
|
23
20
|
|
24
|
-
it "
|
25
|
-
expect {
|
26
|
-
context.get('undefined')
|
27
|
-
}.to raise_error(UndefinedVariableError)
|
21
|
+
it "raises an error when trying to get an undefined variable" do
|
22
|
+
expect { context.get('undefined') }.to raise_error(UndefinedVariableError)
|
28
23
|
end
|
29
24
|
|
30
25
|
end
|
31
26
|
|
32
27
|
describe ProgramExecutionContext do
|
33
28
|
|
34
|
-
|
35
|
-
let(:program) { Program.new [], nil }
|
36
|
-
|
37
|
-
it "should return self as program_context" do
|
29
|
+
it "is the program context itself" do
|
38
30
|
expect(context.program_context).to eq(context)
|
39
31
|
end
|
40
32
|
|
41
|
-
it "
|
33
|
+
it "has a head" do
|
42
34
|
expect(context.head).to be_a Head
|
43
35
|
end
|
44
36
|
|
45
|
-
it "
|
37
|
+
it "has a board" do
|
46
38
|
expect(context.board).to be_a Board
|
47
39
|
end
|
48
40
|
|
@@ -50,15 +42,37 @@ describe ExecutionContext do
|
|
50
42
|
|
51
43
|
describe ProcedureExecutionContext do
|
52
44
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
procedure_context
|
45
|
+
let(:procedure_context) { ProcedureExecutionContext.based_on context }
|
46
|
+
|
47
|
+
it "returns the program context in which it is based" do
|
48
|
+
expect(procedure_context.program_context).to eq(context)
|
49
|
+
end
|
57
50
|
|
58
|
-
|
51
|
+
it "shares the head with the outer context" do
|
52
|
+
expect(procedure_context.head).to eq(context.head)
|
59
53
|
end
|
60
54
|
|
61
55
|
end
|
62
56
|
|
63
|
-
|
57
|
+
describe FunctionExecutionContext do
|
58
|
+
|
59
|
+
it "returns the program context in which it is based" do
|
60
|
+
function_context = FunctionExecutionContext.based_on context
|
61
|
+
expect(function_context.program_context).to eq(context)
|
62
|
+
end
|
64
63
|
|
64
|
+
it "has a new head, a copy of the outer context's head" do
|
65
|
+
context.head.put azul
|
66
|
+
function_context = FunctionExecutionContext.based_on context
|
67
|
+
function_context.head.put verde
|
68
|
+
|
69
|
+
expect(function_context.head).not_to eq(context.head)
|
70
|
+
expect(context.head.are_there_balls?(azul)).to be true
|
71
|
+
expect(function_context.head.are_there_balls?(azul)).to be true
|
72
|
+
expect(context.head.are_there_balls?(verde)).to be false
|
73
|
+
expect(function_context.head.are_there_balls?(verde)).to be true
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
data/spec/runner/head_spec.rb
CHANGED
@@ -1,67 +1,61 @@
|
|
1
1
|
describe Head do
|
2
2
|
|
3
|
-
|
4
|
-
head = Head.new
|
3
|
+
let(:head) { Head.new }
|
5
4
|
|
5
|
+
it "has a position, default 0;0" do
|
6
6
|
expect(head.x_pos).to eq(0)
|
7
7
|
expect(head.y_pos).to eq(0)
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
10
|
+
it "answers the max size" do
|
11
11
|
expect(Head::MAX_ROWS).to eq(9)
|
12
12
|
expect(Head::MAX_COLS).to eq(9)
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
15
|
+
it "allows to be created at a random position" do
|
16
16
|
head = Head.at_random
|
17
17
|
|
18
|
-
100.times { expect(head.x_pos.between?(0, Head::MAX_ROWS-1)).to
|
19
|
-
100.times { expect(head.y_pos.between?(0, Head::MAX_COLS-1)).to
|
18
|
+
100.times { expect(head.x_pos.between?(0, Head::MAX_ROWS-1)).to be true }
|
19
|
+
100.times { expect(head.y_pos.between?(0, Head::MAX_COLS-1)).to be true }
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "movements" do
|
23
23
|
|
24
|
-
let(:head) { Head.new }
|
25
|
-
let(:north) { Norte.new }
|
26
|
-
let(:south) { Sur.new }
|
27
|
-
let(:east) { Este.new }
|
28
|
-
let(:west) { Oeste.new }
|
29
|
-
|
30
24
|
context "valid" do
|
31
25
|
|
32
|
-
it "
|
33
|
-
expect(head.can_move?(
|
34
|
-
expect { head.move(
|
26
|
+
it "moves north" do
|
27
|
+
expect(head.can_move?(norte)).to be true
|
28
|
+
expect { head.move(norte) }.to_not raise_error
|
35
29
|
expect(head.x_pos).to eq(0)
|
36
30
|
expect(head.y_pos).to eq(1)
|
37
31
|
end
|
38
32
|
|
39
|
-
it "
|
40
|
-
head.move
|
41
|
-
expect(head.can_move?(
|
42
|
-
expect { head.move(
|
33
|
+
it "moves south" do
|
34
|
+
head.move norte
|
35
|
+
expect(head.can_move?(sur)).to be true
|
36
|
+
expect { head.move(sur) }.to_not raise_error
|
43
37
|
expect(head.x_pos).to eq(0)
|
44
38
|
expect(head.y_pos).to eq(0)
|
45
39
|
end
|
46
40
|
|
47
|
-
it "
|
48
|
-
expect(head.can_move?(
|
49
|
-
expect { head.move(
|
41
|
+
it "moves east" do
|
42
|
+
expect(head.can_move?(este)).to be true
|
43
|
+
expect { head.move(este) }.to_not raise_error
|
50
44
|
expect(head.x_pos).to eq(1)
|
51
45
|
expect(head.y_pos).to eq(0)
|
52
46
|
end
|
53
47
|
|
54
|
-
it "
|
55
|
-
head.move
|
56
|
-
expect(head.can_move?(
|
57
|
-
expect { head.move(
|
48
|
+
it "moves west" do
|
49
|
+
head.move este
|
50
|
+
expect(head.can_move?(oeste)).to be true
|
51
|
+
expect { head.move(oeste) }.to_not raise_error
|
58
52
|
expect(head.x_pos).to eq(0)
|
59
53
|
expect(head.y_pos).to eq(0)
|
60
54
|
end
|
61
55
|
|
62
|
-
it "
|
63
|
-
head.move
|
64
|
-
head.move
|
56
|
+
it "goes to the origin" do
|
57
|
+
head.move este
|
58
|
+
head.move norte
|
65
59
|
head.go_to_origin
|
66
60
|
expect(head.x_pos).to eq(0)
|
67
61
|
expect(head.y_pos).to eq(0)
|
@@ -71,36 +65,36 @@ describe Head do
|
|
71
65
|
|
72
66
|
context "non valid" do
|
73
67
|
|
74
|
-
it "
|
75
|
-
(Head::MAX_COLS-1).times { head.move
|
68
|
+
it "fails moving north" do
|
69
|
+
(Head::MAX_COLS-1).times { head.move norte }
|
76
70
|
|
77
|
-
expect(head.can_move?(
|
78
|
-
expect { head.move
|
71
|
+
expect(head.can_move?(norte)).to be false
|
72
|
+
expect { head.move norte }.to raise_error(OutOfBoardError)
|
79
73
|
end
|
80
74
|
|
81
|
-
it "
|
82
|
-
expect(head.can_move?(
|
83
|
-
expect { head.move
|
75
|
+
it "fails moving south" do
|
76
|
+
expect(head.can_move?(sur)).to be false
|
77
|
+
expect { head.move sur }.to raise_error(OutOfBoardError)
|
84
78
|
end
|
85
79
|
|
86
|
-
it "
|
87
|
-
(Head::MAX_ROWS-1).times { head.move
|
80
|
+
it "fails moving east" do
|
81
|
+
(Head::MAX_ROWS-1).times { head.move este }
|
88
82
|
|
89
|
-
expect(head.can_move?(
|
90
|
-
expect { head.move
|
83
|
+
expect(head.can_move?(este)).to be false
|
84
|
+
expect { head.move este }.to raise_error(OutOfBoardError)
|
91
85
|
end
|
92
86
|
|
93
|
-
it "
|
94
|
-
expect(head.can_move?(
|
95
|
-
expect { head.move
|
87
|
+
it "fails moving west" do
|
88
|
+
expect(head.can_move?(oeste)).to be false
|
89
|
+
expect { head.move oeste }.to raise_error(OutOfBoardError)
|
96
90
|
end
|
97
91
|
|
98
|
-
it "
|
99
|
-
expect { head.move
|
92
|
+
it "fails if the argument is not a direction" do
|
93
|
+
expect { head.move azul }.
|
100
94
|
to raise_error(GobstonesTypeError, /is not a direction/)
|
101
95
|
expect { head.move "not a direction" }.
|
102
96
|
to raise_error(GobstonesTypeError, /is not a direction/)
|
103
|
-
expect { head.move
|
97
|
+
expect { head.move true_value }.
|
104
98
|
to raise_error(GobstonesTypeError, /is not a direction/)
|
105
99
|
expect { head.move 42 }.
|
106
100
|
to raise_error(GobstonesTypeError, /is not a direction/)
|
@@ -112,26 +106,23 @@ describe Head do
|
|
112
106
|
|
113
107
|
describe "board actions" do
|
114
108
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
expect(head.number_of_balls(
|
122
|
-
head.move
|
123
|
-
|
124
|
-
expect(head.number_of_balls(
|
125
|
-
head.move Este.new
|
126
|
-
5.times { head.put black }
|
127
|
-
expect(head.number_of_balls(black)).to eq(5)
|
109
|
+
it "puts balls across the board" do
|
110
|
+
3.times { head.put negro }
|
111
|
+
expect(head.are_there_balls?(negro)).to be true
|
112
|
+
expect(head.number_of_balls(negro)).to eq(3)
|
113
|
+
head.move norte
|
114
|
+
2.times { head.put negro }
|
115
|
+
expect(head.number_of_balls(negro)).to eq(2)
|
116
|
+
head.move este
|
117
|
+
5.times { head.put negro }
|
118
|
+
expect(head.number_of_balls(negro)).to eq(5)
|
128
119
|
end
|
129
120
|
|
130
|
-
it "
|
131
|
-
4.times { head.put
|
132
|
-
4.times { head.take_out
|
121
|
+
it "takes out balls across the board" do
|
122
|
+
4.times { head.put negro }
|
123
|
+
4.times { head.take_out negro }
|
133
124
|
|
134
|
-
expect(head.are_there_balls?(
|
125
|
+
expect(head.are_there_balls?(negro)).to be false
|
135
126
|
end
|
136
127
|
|
137
128
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/type_checker_spec.rb
CHANGED
@@ -4,34 +4,34 @@ describe Gobstones, "type checker" do
|
|
4
4
|
|
5
5
|
describe "puedeMover()" do
|
6
6
|
|
7
|
-
it "
|
8
|
-
[
|
7
|
+
it "allows a direction as argument" do
|
8
|
+
[norte, sur, este, oeste].each do |dir|
|
9
9
|
puede_mover_dir = PuedeMover.new dir
|
10
10
|
result = puede_mover_dir.type_check
|
11
|
-
expect(result.ok?).to
|
11
|
+
expect(result.ok?).to be true
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
16
|
-
puede_mover_number = PuedeMover.new
|
15
|
+
it "does not allow a number as argument" do
|
16
|
+
puede_mover_number = PuedeMover.new 42.to_gbs_num
|
17
17
|
result = puede_mover_number.type_check
|
18
|
-
expect(result.ok?).to
|
18
|
+
expect(result.ok?).to be false
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
22
|
-
puede_mover_color = PuedeMover.new
|
21
|
+
it "does not allow a color as argument" do
|
22
|
+
puede_mover_color = PuedeMover.new verde
|
23
23
|
result = puede_mover_color.type_check
|
24
|
-
expect(result.ok?).to
|
24
|
+
expect(result.ok?).to be false
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
28
|
-
puede_mover_bool = PuedeMover.new
|
27
|
+
it "does not allow a boolean as argument" do
|
28
|
+
puede_mover_bool = PuedeMover.new true_value
|
29
29
|
result = puede_mover_bool.type_check
|
30
|
-
expect(result.ok?).to
|
30
|
+
expect(result.ok?).to be false
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
34
34
|
|
35
35
|
end
|
36
36
|
|
37
|
-
end
|
37
|
+
end
|