blob: 362f8a51bd627a7046e446d8e8b18b990f892254 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
require_relative '../../spec_helper'
describe "Integer#gcdlcm" do
it "returns [self, self] if self is equal to the argument" do
1.gcdlcm(1).should == [1, 1]
398.gcdlcm(398).should == [398, 398]
end
it "returns an Array" do
36.gcdlcm(6).should be_kind_of(Array)
4.gcdlcm(20981).should be_kind_of(Array)
end
it "returns a two-element Array" do
36.gcdlcm(876).size.should == 2
29.gcdlcm(17).size.should == 2
end
it "returns the greatest common divisor of self and argument as the first element" do
10.gcdlcm(5)[0].should == 10.gcd(5)
200.gcdlcm(20)[0].should == 200.gcd(20)
end
it "returns the least common multiple of self and argument as the last element" do
10.gcdlcm(5)[1].should == 10.lcm(5)
200.gcdlcm(20)[1].should == 200.lcm(20)
end
it "accepts a Bignum argument" do
bignum = 91999**99
bignum.should be_kind_of(Bignum)
99.gcdlcm(bignum).should == [99.gcd(bignum), 99.lcm(bignum)]
end
it "works if self is a Bignum" do
bignum = 9999**89
bignum.should be_kind_of(Bignum)
bignum.gcdlcm(99).should == [bignum.gcd(99), bignum.lcm(99)]
end
it "raises an ArgumentError if not given an argument" do
lambda { 12.gcdlcm }.should raise_error(ArgumentError)
end
it "raises an ArgumentError if given more than one argument" do
lambda { 12.gcdlcm(30, 20) }.should raise_error(ArgumentError)
end
it "raises a TypeError unless the argument is an Integer" do
lambda { 39.gcdlcm(3.8) }.should raise_error(TypeError)
lambda { 45872.gcdlcm([]) }.should raise_error(TypeError)
end
end
|