Sha256: e0da08f06ef5fd5ff435cb58730ba5b753870899a3b11744470a70657e8dc676

Contents?: true

Size: 1.01 KB

Versions: 20

Compression:

Stored size: 1.01 KB

Contents

# coding: utf-8
describe Integer, "#mobius" do
  # A008683
  @seq = [1,-1,-1,0,-1,1,-1,0,0,1,-1,0,-1,1,1,0,-1,0,-1,0,
          1,1,-1,0,0,1,0,0,-1,-1,-1,0,1,1,1,0,-1,1,1,0,-1,
          -1,-1,0,0,1,-1,0,0,0,1,0,-1,0,1,0,1,1,-1,0,-1,1,0,
          0,1,-1,-1,0,1,-1,-1,0,-1,1,0,0,1].to_seq

  @seq.each_with_index do |i, n|
    it "should return #{i} for #{n}" do
      n.succ.mobius.should == i
    end

    it "should return nil for negative number #{-n}" do
      (-n.succ).mobius.should be_nil
    end
  end

  it "returns −1 if n is prime" do
    Prime.first(10).each do |n|
      n.mobius.should == -1
    end
  end

  
  # A013929
  @seq = [4,8,9,12,16,18,20,24,25,27,28,32,36,40,44,45,48,
          49,50,52,54,56,60,63,64,68,72,75,76,80,81,84,88,
          90,92,96,98,99,100,104,108,112,116,117,120,121,
          124,125,126,128,132,135,136,140,144,147,148,150,
          152,153,156,160]
  @seq.sample(10).each do |n|
    it "should return 0 for non-square-free number #{n}" do
      n.mobius.should == 0
     end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
numb-0.186.0 spec/numb/mobius_spec.rb
numb-0.185.0 spec/numb/mobius_spec.rb
numb-0.184.0 spec/numb/mobius_spec.rb
numb-0.181.0 spec/numb/mobius_spec.rb
numb-0.170.0 spec/numb/mobius_spec.rb
numb-0.152.0 spec/numb/mobius_spec.rb
numb-0.138.0 spec/numb/mobius_spec.rb
numb-0.125.0 spec/numb/mobius_spec.rb
numb-0.114.0 spec/numb/mobius_spec.rb
numb-0.111.0 spec/numb/mobius_spec.rb
numb-0.109.0 spec/numb/mobius_spec.rb
numb-0.99.0 spec/numb/mobius_spec.rb
numb-0.96.0 spec/numb/mobius_spec.rb
numb-0.89.0 spec/numb/mobius_spec.rb
numb-0.84.0 spec/mobius_spec.rb
numb-0.77.0 spec/mobius_spec.rb
numb-0.72.1 spec/mobius_spec.rb
numb-0.72.0 spec/mobius_spec.rb
numb-0.68.0 spec/mobius_spec.rb
numb-0.63.0 spec/mobius_spec.rb