Sha256: 9a10bb2defd172a2b7ac780bb28d450bb6d43d4da27cdc69a1b2bbc26b72eae0

Contents?: true

Size: 981 Bytes

Versions: 4

Compression:

Stored size: 981 Bytes

Contents

require 'spec_helper'

describe EbisuConnection::GreatestCommonDivisor do
  before(:all) do
    @g = EbisuConnection::GreatestCommonDivisor
  end

  context ".calc" do
    it "return nil if set is empty" do
      expect(@g.calc([])).to be_nil
    end

    it "return first element if set has one element" do
      expect(@g.calc([1])).to eq(1)
    end

    it "return first element if set has elements that is all same" do
      set = [1] * 100
      expect(@g.calc(set)).to eq(1)
    end

    it "return 1 if set includes 1 in elements" do
      set = (1..100).to_a
      expect(@g.calc(set)).to eq(1)
    end

    it "return gcd" do
      expect(@g.calc([2,4])).to eq(2)
      expect(@g.calc([2,4,6])).to eq(2)
      expect(@g.calc([4,6])).to eq(2)
      expect(@g.calc([3,4,6])).to eq(1)
      expect(@g.calc([3,6])).to eq(3)
      expect(@g.calc([10,10,2])).to eq(2)
      expect(@g.calc([10,10,2,10,5])).to eq(1)
      expect(@g.calc([10,10,10,5])).to eq(5)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ebisu_connection-0.3.0 spec/unit/greatest_common_divisor_spec.rb
ebisu_connection-0.2.0 spec/unit/greatest_common_divisor_spec.rb
ebisu_connection-0.1.1 spec/unit/greatest_common_divisor_spec.rb
ebisu_connection-0.1.0 spec/unit/greatest_common_divisor_spec.rb