Sha256: 9f3150519542392d6d5705fd75185c211b4ec79693678060f85099b339d75593

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

$: << File.join( File.dirname( __FILE__ ), "..", "lib" )
require 'test/unit'
require 'cipher'

class TC_SolitaireCipher < Test::Unit::TestCase

  class MockAlgorithms
    def get( name )
      MockAlgorithm.new
    end
  end

  class MockDeck
    def cipher_shuffle!
    end

    def cipher_letter
      "X"
    end
  end

  class MockAlgorithm
    def new_deck
      MockDeck.new
    end
  end

  def setup
    @cipher = SolitaireCipher.new( UnkeyedAlgorithm.new )
    @cipher.algorithms = MockAlgorithms.new
    @cipher.stream = KeyStream.new
  end

  def test_use_algorithm
    @cipher.use_algorithm "mock"
    assert_equal "FCJJM", @cipher.encrypt( "HELLO" )
    assert_equal "JGNNQ", @cipher.decrypt( "HELLO" )
  end

  def test_encrypt
    msg = "Code in Ruby! Live longer."
    expected = "GLNCQ MJAFF FVOMB JIYCB"
    assert_equal expected, @cipher.encrypt( msg )
  end

  def test_decrypt_bad
    assert_raise( RuntimeError ) do
      @cipher.decrypt( "not good" )
    end

    assert_raise( RuntimeError ) do
      @cipher.decrypt( "BOGUS 12345" )
    end
  end

  def test_decrypt_good
    msg = "CLEPK HHNIY CFPWH FDFEH"
    expected = "YOURCIPHERISWORKINGX"
    assert_equal expected, @cipher.decrypt( msg )

    msg = "ABVAW LWZSY OORYK DUPVH"
    expected = "WELCOMETORUBYQUIZXXX"
    assert_equal expected, @cipher.decrypt( msg )
  end

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
copland-1.0.0 examples/solitaire-cipher/test/tc_solitaire-cipher.rb
copland-0.8.0 examples/solitaire-cipher/test/tc_solitaire-cipher.rb
rubyzip-0.9.1 lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb