Class: TC_SolitaireCipher

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb

Defined Under Namespace

Classes: MockAlgorithm, MockAlgorithms, MockDeck

Instance Method Summary collapse

Instance Method Details

#setupObject



28
29
30
31
32
# File 'lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb', line 28

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

#test_decrypt_badObject



46
47
48
49
50
51
52
53
54
# File 'lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb', line 46

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

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

#test_decrypt_goodObject



56
57
58
59
60
61
62
63
64
# File 'lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb', line 56

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

#test_encryptObject



40
41
42
43
44
# File 'lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb', line 40

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

#test_use_algorithmObject



34
35
36
37
38
# File 'lib/quiz1/t/solutions/Jamis Buck/test/tc_solitaire-cipher.rb', line 34

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