<commit_before>#!/usr/bin/ruby

require 'test/unit'
require 'test/mock_rand'
require 'lib/attribute_grammar'
require 'lib/abnf_file'

class TC_AttributeGrammar < Test::Unit::TestCase

  def setup
    @grammar = Semantic::AttributeGrammar.new 'test/data/knapsack.abnf'
    @grammar.semantic = 'test/data/knapsack.yaml'   
  end

  def test_basic

    m = Semantic::AttrGrDepthFirst.new( @grammar )

    assert_equal( 'i3i1i2', m.phenotype( [0, 1, 2, 1, 0, 0, 1] ) )
    assert_equal( 7, m.used_length )

    assert_equal( 'i3i1i2', m.phenotype( [1, 1, 2, 1, 2, 1, 0] ) )
    assert_equal( 7, m.used_length )
   
  end

  def XXXXXXXXXtest_generate
    m = Semantic::AttrGrDepthFirst.new( @grammar )
    m.consume_trivial_codons = true

    r = MockRand.new [{1=>0},0, {2=>1},0, {3=>2},0, {2=>1},0, {3=>2},0, {3=>0},0, {2=>0},0, {3=>0},0, {3=>2},0, {3=>1},0 ]
    m.random = r   

    gen = [0, 1, 2, 1, 2, 0, 0, 0, 2, 1]
    assert_equal( gen, m.generate_grow( 5 ) )
  end


end
<commit_msg>generation tested<commit_after>#!/usr/bin/ruby

require 'test/unit'
require 'test/mock_rand'
require 'lib/attribute_grammar'
require 'lib/abnf_file'

class TC_AttributeGrammar < Test::Unit::TestCase

  def setup
    @grammar = Semantic::AttributeGrammar.new 'test/data/knapsack.abnf'
    @grammar.semantic = 'test/data/knapsack.yaml'   
  end

  def test_basic

    m = Semantic::AttrGrDepthFirst.new( @grammar )

    assert_equal( 'i3i1i2', m.phenotype( [0, 1, 2, 1, 0, 0, 0] ) )
    assert_equal( 7, m.used_length )

    assert_equal( 'i3i1i2', m.phenotype( [1, 1, 2, 1, 2, 1, 0] ) )
    assert_equal( 7, m.used_length )
   
  end

  def test_generate
    m = Semantic::AttrGrDepthFirst.new( @grammar )
    m.consume_trivial_codons = true

    r = MockRand.new [{1=>0},0, {2=>1},0, {3=>2},0, {2=>1},0, {2=>0},0, {1=>0},0, {1=>0},0 ]
    m.random = r   

    gen = [0, 1, 2, 1, 0, 0, 0]
    assert_equal( gen, m.generate_grow( 5 ) )
  end


end

{'fraction_non_alphanumeric': 0.1771694214876033, 'fraction_numerical': 0.058884297520661155, 'mean_word_length': 3.422374429223744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3369703', 'n_tokens_mistral': 902, 'n_tokens_neox': 823, 'n_words': 175}