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-0.1.70 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.61 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.60 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.59 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.58 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.57 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.56 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.55 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.54 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.53 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.52 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb
harbr-0.1.50 vendor/bundle/ruby/3.2.0/gems/citrus-3.0.2/test/memoized_input_test.rb