Permalink
Browse files

Fixed deciphering problem, added tests

  • Loading branch information...
1 parent 5fd12da commit 2ac385d22ed7e13dce7a36c35d36692700b2b56e @EricR committed Dec 30, 2011
Showing with 13 additions and 2 deletions.
  1. +2 −2 caesar.rb
  2. +11 −0 spec/caesar_spec.rb
View
@@ -10,9 +10,9 @@ def self.decipher(shift, message)
def self.apply_algorithm(direction, shift, message)
letters = %w{A B C D E F G H I J K L M N O P Q R S T U V W X Y Z}
- message.upcase.split(//).map do |letter|
+ shift = direction == :encipher ? shift : -shift
+ message.upcase.split(//).map do |letter|
if letters.include?(letter)
- shift = direction == :encipher ? shift : -shift
letters.rotate(shift)[letters.index(letter)]
else
letter
View
@@ -0,0 +1,11 @@
+require './caesar.rb'
+
+describe "caesar" do
+ it "should encipher a message" do
+ Caesar.encipher(2,"HELLO WORLD").should == "JGNNQ YQTNF"
+ end
+
+ it "should decipher a message" do
+ Caesar.decipher(2,"JGNNQ YQTNF").should == "HELLO WORLD"
+ end
+end

0 comments on commit 2ac385d

Please sign in to comment.