Sha256: 1cf1d49ff48f60352e633b01a5414a2596ab273cd20e2e7d3f607d3d04bd2082

Contents?: true

Size: 1.13 KB

Versions: 80

Compression:

Stored size: 1.13 KB

Contents

require File.expand_path('../helper', __FILE__)

class MemoizedInputTest < Test::Unit::TestCase
  def test_memoized?
    assert MemoizedInput.new('').memoized?
  end

  grammar :LetterA do
    rule :top do
      any(:three_as, :two_as, :one_a)
    end

    rule :three_as do
      rep(:one_a, 3, 3)
    end

    rule :two_as do
      rep(:one_a, 2, 2)
    end

    rule :one_a do
      "a"
    end
  end

  def test_cache_hits1
    input = MemoizedInput.new('a')
    input.exec(LetterA.rule(:top))
    assert_equal(3, input.cache_hits)
  end

  def test_cache_hits2
    input = MemoizedInput.new('aa')
    input.exec(LetterA.rule(:top))
    assert_equal(2, input.cache_hits)
  end

  def test_cache_hits3
    input = MemoizedInput.new('aaa')
    input.exec(LetterA.rule(:top))
    assert_equal(0, input.cache_hits)
  end
  
  grammar :LettersABC do
    rule :top do
      any(all(:a,:b,:c), all(:b,:a,:c), all(:b,:c,:a))
    end
    rule :a do
      "a"
    end
    rule :b do
      "b"
    end
    rule :c do
      "c"
    end
  end

  def test_memoization
    match = LettersABC.parse('bca',{:memoize=>true})
    assert_equal('bca',match)
  end 

end

Version data entries

80 entries across 80 versions & 2 rubygems

Version Path
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.93 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.91 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb