From 6291431b49fc853e44277b1c78cd25315211a63d Mon Sep 17 00:00:00 2001 From: Run Paint Run Run Date: Wed, 17 Mar 2010 04:35:25 +0000 Subject: [PATCH] Integer#gnomonic?: Add --- lib/numb/gnomonic.rb | 4 ++++ spec/numb/gnomonic_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/numb/gnomonic.rb create mode 100644 spec/numb/gnomonic_spec.rb diff --git a/lib/numb/gnomonic.rb b/lib/numb/gnomonic.rb new file mode 100644 index 0000000..0740c32 --- /dev/null +++ b/lib/numb/gnomonic.rb @@ -0,0 +1,4 @@ +# coding: utf-8 +class Integer + alias :gnomonic? :odd? +end diff --git a/spec/numb/gnomonic_spec.rb b/spec/numb/gnomonic_spec.rb new file mode 100644 index 0000000..b6ed427 --- /dev/null +++ b/spec/numb/gnomonic_spec.rb @@ -0,0 +1,21 @@ +# coding: utf-8 +describe Integer, "#gnomonic?" do + # A005408 + @seq = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35, + 37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67, + 69,71,73,75,77,79,81,83,85,87,89,91,93,95,97,99, + 101,103,105,107,109,111,113,115,117,119,121,123, + 125,127,129,131] + + @seq.each do |n| + it "returns true for gnomonic number #{n}" do + n.should be_gnomonic + end + end + + @seq.to_seq.invert.each do |n| + it "returns false for non-gnomonic number #{n}" do + n.should_not be_gnomonic + end + end +end