Created
October 10, 2012 15:41
-
-
Save gotar/3866431 to your computer and use it in GitHub Desktop.
test for pmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Array do | |
describe '#pmap' do | |
context "without timeout" do | |
it "should not raise error" do | |
expect { | |
[].pmap{|x| x} | |
}.not_to raise_error | |
end | |
it "should return proper values" do | |
[1,2,3].pmap{|x| x+1}.should == [2,3,4] | |
end | |
end | |
context "with timeout" do | |
it "should not raise error" do | |
expect { | |
[].pmap(1){|x| x} | |
}.not_to raise_error | |
end | |
it "should not set timeout if timeout is nil" do | |
[1,2,3].pmap(nil){|x| sleep(0.1); x+1}.should == [2,3,4] | |
end | |
it "should return proper values" do | |
[1,2,3].pmap(1){|x| x+1}.should == [2,3,4] | |
end | |
it "should return proper values if it was faster then timeout " do | |
[1,2,3].pmap(0.2){|x| sleep(0.1); x+1}.should == [2,3,4] | |
end | |
it "should return nil for timeout elements" do | |
[1,2,3].pmap(0.1){|x| sleep(1); x+1}.should be_empty | |
end | |
it "should return value of non timeouted elements" do | |
[1,2,3].pmap(0.1){|x| sleep(1) if x == 2; x+1}.should == [2, 4] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment