nudge 0.2.1 → 0.2.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.
- data/VERSION +1 -1
- data/spec/instructions/bool/bool_duplicate_spec.rb +50 -0
- data/spec/instructions/bool/bool_from_float_spec.rb +41 -0
- data/spec/instructions/bool/bool_from_int_spec.rb +41 -0
- data/spec/instructions/bool/bool_pop_spec.rb +47 -0
- data/spec/instructions/bool/bool_rotate_spec.rb +60 -0
- data/spec/instructions/bool/bool_swap_spec.rb +64 -0
- data/spec/instructions/code/code_depth_spec.rb +39 -0
- data/spec/instructions/code/code_duplicate_spec.rb +50 -0
- data/spec/instructions/code/code_flush_spec.rb +37 -0
- data/spec/instructions/code/code_from_bool_spec.rb +37 -0
- data/spec/instructions/code/code_from_float_spec.rb +37 -0
- data/spec/instructions/code/code_from_int_spec.rb +37 -0
- data/spec/instructions/code/code_pop_spec.rb +47 -0
- data/spec/instructions/code/code_rotate_spec.rb +60 -0
- data/spec/instructions/code/code_swap_spec.rb +58 -0
- data/spec/instructions/float/float_duplicate_spec.rb +50 -0
- data/spec/instructions/float/float_from_bool_spec.rb +42 -0
- data/spec/instructions/float/float_from_int_spec.rb +37 -0
- data/spec/instructions/float/float_pop_spec.rb +47 -0
- data/spec/instructions/float/float_rotate_spec.rb +60 -0
- data/spec/instructions/float/float_swap_spec.rb +64 -0
- data/spec/instructions/int/int_duplicate_spec.rb +50 -0
- data/spec/instructions/int/int_from_bool_spec.rb +43 -0
- data/spec/instructions/int/int_from_float_spec.rb +37 -0
- data/spec/instructions/int/int_pop_spec.rb +47 -0
- data/spec/instructions/int/int_rotate_spec.rb +60 -0
- data/spec/instructions/int/int_swap_spec.rb +64 -0
- data/spec/instructions/name/name_duplicate_spec.rb +50 -0
- data/spec/instructions/name/name_pop_spec.rb +47 -0
- data/spec/instructions/name/name_rotate_spec.rb +60 -0
- data/spec/instructions/name/name_swap_spec.rb +58 -0
- data/spec/interpreter/interpreter_spec.rb +0 -2
- metadata +66 -16
- data/spec/instructions/code/code_stack_spec.rb +0 -386
- data/spec/instructions/split_these/bool_stack_spec.rb +0 -95
- data/spec/instructions/split_these/conversions_spec.rb +0 -103
- data/spec/instructions/split_these/float_stack_spec.rb +0 -92
- data/spec/instructions/split_these/int_stack_spec.rb +0 -81
- data/spec/instructions/split_these/name_stack_spec.rb +0 -84
- /data/spec/instructions/code/{code_fromname_spec.rb → code_from_name_spec.rb} +0 -0
@@ -1,81 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "../../spec_helper")
|
2
|
-
include Nudge
|
3
|
-
|
4
|
-
theseInstructions = [
|
5
|
-
IntPopInstruction,
|
6
|
-
IntSwapInstruction,
|
7
|
-
IntDuplicateInstruction,
|
8
|
-
IntRotateInstruction]
|
9
|
-
|
10
|
-
intsTheyNeed = {
|
11
|
-
IntPopInstruction => 1,
|
12
|
-
IntSwapInstruction => 2,
|
13
|
-
IntDuplicateInstruction => 1,
|
14
|
-
IntRotateInstruction => 3 }
|
15
|
-
|
16
|
-
resultTuples = {
|
17
|
-
IntPopInstruction => {[1,2]=>[1]},
|
18
|
-
IntSwapInstruction => {[1,2]=>[2,1]},
|
19
|
-
IntDuplicateInstruction => {[33] => [33,33]},
|
20
|
-
IntRotateInstruction => {[1,2,3] => [2,3,1]} }
|
21
|
-
|
22
|
-
theseInstructions.each do |instName|
|
23
|
-
describe instName do
|
24
|
-
before(:each) do
|
25
|
-
@context = Interpreter.new
|
26
|
-
@i1 = instName.new(@context)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "should have its context right" do
|
30
|
-
@i1.context.should == @context
|
31
|
-
end
|
32
|
-
|
33
|
-
[:preconditions?, :setup, :derive, :cleanup].each do |methodName|
|
34
|
-
it "should respond to \##{methodName}" do
|
35
|
-
@i1 = instName.new(@context)
|
36
|
-
@i1.should respond_to(methodName)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "\#go" do
|
41
|
-
before(:each) do
|
42
|
-
@i1 = instName.new(@context)
|
43
|
-
@context.clear_stacks
|
44
|
-
@int1 = ValuePoint.new("int", 1)
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "\#preconditions?" do
|
48
|
-
it "should check that there are enough parameters" do
|
49
|
-
10.times {@context.stacks[:int].push(@int1)}
|
50
|
-
@i1.preconditions?.should == true
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should raise an error if the preconditions aren't met" do
|
54
|
-
@context.clear_stacks # there are no params at all
|
55
|
-
lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should successfully run #go only if all preconditions are met" do
|
59
|
-
5.times {@context.stacks[:int].push(@int1)}
|
60
|
-
@i1.should_receive(:cleanup)
|
61
|
-
@i1.go
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "\#cleanup" do
|
66
|
-
describe "should restructure the stack" do
|
67
|
-
examples = resultTuples[instName]
|
68
|
-
examples.each do |inputs, finalStackState|
|
69
|
-
params = inputs.inspect
|
70
|
-
expected = finalStackState.inspect
|
71
|
-
it "should end up with #{expected} on the \:int stack, starting with #{params}" do
|
72
|
-
inputs.each {|i| @context.stacks[:int].push(ValuePoint.new("int", i))}
|
73
|
-
@i1.go
|
74
|
-
finalStackState.reverse.each {|i| @context.stacks[:int].pop.value.should == i}
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), "../../spec_helper")
|
2
|
-
include Nudge
|
3
|
-
|
4
|
-
theseInstructions = [
|
5
|
-
NamePopInstruction,
|
6
|
-
NameSwapInstruction,
|
7
|
-
NameDuplicateInstruction,
|
8
|
-
NameRotateInstruction
|
9
|
-
]
|
10
|
-
|
11
|
-
namesTheyNeed = {
|
12
|
-
NamePopInstruction => 1,
|
13
|
-
NameSwapInstruction => 2,
|
14
|
-
NameDuplicateInstruction => 1,
|
15
|
-
NameRotateInstruction => 3
|
16
|
-
}
|
17
|
-
|
18
|
-
resultTuples = {
|
19
|
-
NamePopInstruction => {["a", "b"]=>["a"]},
|
20
|
-
NameSwapInstruction => {["a", "b"]=>["b", "a"]},
|
21
|
-
NameDuplicateInstruction => {["a"] => ["a", "a"]},
|
22
|
-
NameRotateInstruction => {["a", "b", "c"] => ["b", "c", "a"]}
|
23
|
-
}
|
24
|
-
|
25
|
-
theseInstructions.each do |instName|
|
26
|
-
describe instName do
|
27
|
-
before(:each) do
|
28
|
-
@context = Interpreter.new
|
29
|
-
@i1 = instName.new(@context)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should have its context right" do
|
33
|
-
@i1.context.should == @context
|
34
|
-
end
|
35
|
-
|
36
|
-
[:preconditions?, :setup, :derive, :cleanup].each do |methodName|
|
37
|
-
it "should respond to \##{methodName}" do
|
38
|
-
@i1 = instName.new(@context)
|
39
|
-
@i1.should respond_to(methodName)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "\#go" do
|
44
|
-
before(:each) do
|
45
|
-
@i1 = instName.new(@context)
|
46
|
-
@context.clear_stacks
|
47
|
-
@name1 = ReferencePoint.new("a")
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "\#preconditions?" do
|
51
|
-
it "should check that there are enough parameters" do
|
52
|
-
8.times {@context.stacks[:name].push(@name1)}
|
53
|
-
@i1.preconditions?.should == true
|
54
|
-
end
|
55
|
-
|
56
|
-
it "should raise an error if the preconditions aren't met" do
|
57
|
-
@context.clear_stacks # there are no params at all
|
58
|
-
lambda{@i1.preconditions?}.should raise_error(Instruction::NotEnoughStackItems)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should successfully run #go only if all preconditions are met" do
|
62
|
-
7.times {@context.stacks[:name].push(@name1)}
|
63
|
-
@i1.should_receive(:cleanup)
|
64
|
-
@i1.go
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "\#cleanup" do
|
69
|
-
describe "should restructure the stack" do
|
70
|
-
examples = resultTuples[instName]
|
71
|
-
examples.each do |inputs, finalStackState|
|
72
|
-
params = inputs.inspect
|
73
|
-
expected = finalStackState.inspect
|
74
|
-
it "should end up with #{expected} on the \:name stack, starting with #{params}" do
|
75
|
-
inputs.each {|i| @context.stacks[:name].push(ReferencePoint.new(i))}
|
76
|
-
@i1.go
|
77
|
-
finalStackState.reverse.each {|i| @context.stacks[:name].pop.value.should == i}
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
File without changes
|