spec/interpreter/interpreter_spec.rb in nudge-0.1.3 vs spec/interpreter/interpreter_spec.rb in nudge-0.2.0
- old
+ new
@@ -43,17 +43,35 @@
@ii.steps = 100
@ii.reset("channel x")
@ii.steps.should == 0
end
+ it "#reset should reset the start_time counter to 0" do
+ @ii.start_time = 999999999999
+ @ii.reset
+ @ii.start_time.should be_a_kind_of(Time)
+ end
+
it "#reset should reset the #sensors Hash" do
@ii.register_sensor("z") {1201}
@ii.reset
@ii.sensors["z"].should == nil
end
+ it "should have a code_char_limit" do
+ lambda{@ii.code_char_limit}.should_not raise_error
+ end
+ it "should have a default code_char_limit of 2000 characters" do
+ @ii.code_char_limit.should == 2000
+ end
+
+ it "should be possible to set code_char_limit with an option" do
+ Interpreter.new("block {}",code_char_limit:171).code_char_limit.should == 171
+ end
+
+
it "should load a complex CodeBlock as a single item on the exec stack" do
myCode = "block {\ndo foo\n do bar\n block {\ndo baz}}"
@ii.reset(myCode)
@ii.stacks.should include(:exec)
@ii.stacks[:exec].depth.should == 1
@@ -419,10 +437,17 @@
@ii.steps.should == 11
11.times {@ii.step}
@ii.steps.should == 20
end
+ it "should step only until its time_limit is reached or exceeded" do
+ @ii.reset("block {}")
+ @ii.start_time = (Time.now - 10000)
+ @ii.run
+ @ii.steps.should == 1
+ end
+
end
describe "running" do
before(:each) do
@ii = Interpreter.new()
@@ -487,10 +512,10 @@
ii.reset
ii.program.should == nil
end
it "should not affect variable bindings" do
- ii = Interpreter.new
+ ii = Interpreter.new("block {}")
ii.bind_variable("a", ValuePoint.new("int",3))
ii.variables.keys.should == ["a"]
ii.reset
ii.variables.keys.should == ["a"]
end
\ No newline at end of file