Sha256: 12cbc386b350fb05bf671cf3f1edb48f7029eef11e975cde74c082aa9a8c2222

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

describe Integer, "#square?" do
  @seq = [0,1,4,9,16,25,36,49,64,81,100,121,144,169,196,
          225,256,289,324,361,400,441,484,529,576,625,676,
          729,784,841,900,961,1024,1089,1156,1225,1296,1369,
          1444,1521,1600,1681,1764,1849]
  
  @seq.each do |n|
    it "returns true for square number #{n}" do
      n.should be_square
    end
  end

  @seq.to_seq.invert.each do |n|
    it "returns false for non-square number #{n}" do
      n.should_not be_square
    end
  end

  it "returns false for negative numbers" do
    [-1, -378, -9].each do |n|
      n.should_not be_square
    end
  end

  it "returns nil when the square root is infinite" do
    9999999880000000359859986946294623781838875946012712893365986548632235701967954558670969253503997913415008896487205684793069342787691170258832794954572186327945677037037154860793120217960493002317298159645342431034751955276791509386257991014312642060444444445753597283950617283950617283950617283950617283950617283950617283950617283950617284297678218281.square?.should be_nil
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
numb-0.186.0 spec/numb/square_spec.rb
numb-0.185.0 spec/numb/square_spec.rb
numb-0.184.0 spec/numb/square_spec.rb
numb-0.181.0 spec/numb/square_spec.rb
numb-0.170.0 spec/numb/square_spec.rb
numb-0.152.0 spec/numb/square_spec.rb