oh_my_method 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 905eeb3d2a3e0d615a7f017a20e413bebc300722
4
- data.tar.gz: 09a6f2550bbcb436b173cfa9d6a622dbfd8b7a41
3
+ metadata.gz: c6a3349cf27f8f96303f09d2e650b9b44b309751
4
+ data.tar.gz: 731c8d9472584bd7670c57e9d6f403c2133b0e0d
5
5
  SHA512:
6
- metadata.gz: de6c5d1be80889e5e531748f6f280a12ef465d8f0621aab1209ae0b98dfc0f7bd77d3afbd6e10f64b3af72b1a21ec92140d38cab11268d24ed543ae4281d2a6c
7
- data.tar.gz: 8003274bafa52dcbca25bb4992cc7b9d0c0f12451b0cd5cfe5d2030fbef11fb80d43da7a3e65a006d7ed92f22de509048463a4426c70eeb66ce4096910e6c310
6
+ metadata.gz: 2b72e363107442079ae5d25aa36d247569d09af35f479607f9318560fa8a5bfb775da1d1a136d92a64031a4fdda6832fe921795dac69402a5daaab32cda0e007
7
+ data.tar.gz: 701bd55d3e947527f290e2beffdc80f5d85f8af938fd395a736a495f96d20fcf82eb67ac599250f38cc39c04bf93c353d2dd2e0201303f67e6a3a52c8d53673d
@@ -6,4 +6,17 @@ class Integer
6
6
  def minus?
7
7
  self < 0
8
8
  end
9
+
10
+ def combination(k)
11
+ self.factorial/(k.factorial*(self-k).factorial)
12
+ end
13
+
14
+ def permutation(k)
15
+ self.factorial/(self-k).factorial
16
+ end
17
+
18
+ def factorial
19
+ return 1 if self.zero?
20
+ (1..self).inject(:*)
21
+ end
9
22
  end
@@ -1,3 +1,3 @@
1
1
  module OhMyMethod
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,17 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe "Integer" do
4
- it "plus?" do
3
+ describe "Integer Class" do
4
+ it "#plus?" do
5
5
  expect(-1.plus?).to eq false
6
6
  expect(0.plus?).to eq false
7
7
  expect(1.plus?).to eq true
8
8
  expect((1<<64).plus?).to eq true
9
9
  end
10
10
 
11
- it "minus?" do
11
+ it "#minus?" do
12
12
  expect(-1.minus?).to eq true
13
13
  expect(0.minus?).to eq false
14
14
  expect(1.minus?).to eq false
15
15
  expect((1<<64).minus?).to eq false
16
16
  end
17
+
18
+ it "#factorial" do
19
+ expect(0.factorial).to eq 1
20
+ expect(3.factorial).to eq 6
21
+ expect(10.factorial).to eq 3628800
22
+ end
23
+
24
+ it "#combination" do
25
+ expect(4.combination(1)).to eq 4
26
+ expect(4.combination(0)).to eq 1
27
+ expect(10.combination(5)).to eq 252
28
+ end
29
+
30
+ it "#permutation" do
31
+ expect(3.permutation(0)).to eq 1
32
+ expect(3.permutation(2)).to eq 6
33
+ expect(20.permutation(5)).to eq 1860480
34
+ end
17
35
  end
@@ -1,21 +1,21 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "String Class" do
4
- it "palindrome?" do
4
+ it "#palindrome?" do
5
5
  expect("hello".palindrome?).to eq false
6
6
  expect("heeeh".palindrome?).to eq true
7
7
  expect("Heeeh".palindrome?).to eq false
8
8
  expect("ABCBA".palindrome?).to eq true
9
9
  end
10
10
 
11
- it "middle_with?" do
11
+ it "#middle_with?" do
12
12
  expect("hello".middle_with?("ell")).to eq true
13
13
  expect("hello".middle_with?("ello")).to eq false
14
14
  expect("hello".middle_with?("hel")).to eq false
15
15
  expect("ABABA".middle_with?("BAB")).to eq true
16
16
  end
17
17
 
18
- it "sum_digit" do
18
+ it "#sum_digit" do
19
19
  expect("11111".sum_digit).to eq 5
20
20
  expect("12321".sum_digit).to eq 9
21
21
  expect("123456789".sum_digit).to eq 45
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oh_my_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - siman-man