Sha256: 656d2d1d3b91b846c8aed23a2369bf5608881023d031d91815ca244765d70754

Contents?: true

Size: 705 Bytes

Versions: 9

Compression:

Stored size: 705 Bytes

Contents

$:.unshift 'lib'

require 'caruby/util/cache'
require "test/unit"

class CacheTest < Test::Unit::TestCase

  def test_cache
    cache = CaRuby::Cache.new { |n| n % 2 }
    assert_nil(cache[1], "Value mistakenly cached")
    cache.add(1)
    assert_equal(1, cache[1], "Cached value not found")
    assert_nil(cache[2], "Uncached value found")
    assert_equal(1, cache[3], "Cached equivalent not found")
  end

  def test_cache_factory
    cache = CaRuby::Cache.new(Proc.new { |n| n * 4 }) { |n| n % 2 }
    assert_equal(4, cache[1], "Cached factory value not found")
    assert_equal(8, cache[2], "Cached factory value found")
    assert_equal(4, cache[3], "Cached factory equivalent not found")
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
caruby-core-1.5.5 test/lib/caruby/util/cache_test.rb
caruby-core-1.5.4 test/lib/caruby/util/cache_test.rb
caruby-core-1.5.3 test/lib/caruby/util/cache_test.rb
caruby-core-1.5.2 test/lib/caruby/util/cache_test.rb
caruby-core-1.5.1 test/lib/caruby/util/cache_test.rb
caruby-core-1.4.9 test/lib/caruby/util/cache_test.rb
caruby-core-1.4.7 test/lib/caruby/util/cache_test.rb
caruby-core-1.4.6 test/lib/caruby/util/cache_test.rb
caruby-core-1.4.5 test/lib/caruby/util/cache_test.rb