Class: TestMemoize

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/rip/memoize.rb

Defined Under Namespace

Classes: Encoder

Instance Method Summary collapse

Instance Method Details

#setupObject



74
75
76
# File 'lib/rip/memoize.rb', line 74

def setup
  @obj = Encoder.new
end

#test_memoizes_argless_methodsObject



100
101
102
103
104
# File 'lib/rip/memoize.rb', line 100

def test_memoizes_argless_methods
  @obj.simple
  @obj.simple
  assert_equal 1, @obj.encodes
end

#test_memoizes_methodObject



83
84
85
86
87
88
89
# File 'lib/rip/memoize.rb', line 83

def test_memoizes_method
  @obj.encode('chris')
  @obj.encode('chris')
  @obj.encode('chris')

  assert_equal 1, @obj.encodes
end

#test_memoizes_multiple_methodsObject



91
92
93
94
95
96
97
98
# File 'lib/rip/memoize.rb', line 91

def test_memoizes_multiple_methods
  @obj.encode('chris')
  @obj.encode('bob')
  @obj.encode('chris')
  @obj.encode('bob')

  assert_equal 2, @obj.encodes
end

#test_properly_executes_methodsObject



78
79
80
81
# File 'lib/rip/memoize.rb', line 78

def test_properly_executes_methods
  @obj.encode('chris')
  assert_equal '99/104/114/105/115', @obj.encode('chris')
end

#test_uses_simple_ivar_for_argless_methodsObject



106
107
108
109
# File 'lib/rip/memoize.rb', line 106

def test_uses_simple_ivar_for_argless_methods
  @obj.simple
  assert_equal 2, @obj.instance_variable_get(:@simple)
end