Skip to content

Instantly share code, notes, and snippets.

@gotar
Created October 10, 2012 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotar/3866431 to your computer and use it in GitHub Desktop.
Save gotar/3866431 to your computer and use it in GitHub Desktop.
test for pmap
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