automata 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/examples/{nfa_sample.yml → nfa_1.yml} +0 -0
- data/lib/automata/nfa.rb +18 -10
- data/lib/automata/version.rb +1 -1
- data/spec/nfa_spec.rb +19 -13
- metadata +8 -8
| 
            File without changes
         | 
    
        data/lib/automata/nfa.rb
    CHANGED
    
    | @@ -22,18 +22,16 @@ module Automata | |
| 22 22 | 
             
                #
         | 
| 23 23 | 
             
                def accepts?(string)
         | 
| 24 24 | 
             
                  heads = [@start]
         | 
| 25 | 
            +
                  
         | 
| 26 | 
            +
                  #--
         | 
| 27 | 
            +
                  # Move any initial e-transitions
         | 
| 28 | 
            +
                  if has_transition?(@start, '&')
         | 
| 29 | 
            +
                    transition(@start, '&').each { |h| heads << h } 
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                  
         | 
| 25 32 | 
             
                  string.each_char do |symbol|
         | 
| 26 33 | 
             
                    newHeads, eTrans = [], []
         | 
| 27 | 
            -
             | 
| 28 | 
            -
                    #--
         | 
| 29 | 
            -
                    # Move any e-transitions
         | 
| 30 | 
            -
                    heads.each do |head|
         | 
| 31 | 
            -
                      if has_transition?(head, '&')
         | 
| 32 | 
            -
                        transition(head, '&').each { |t| eTrans << t }
         | 
| 33 | 
            -
                      end
         | 
| 34 | 
            -
                    end
         | 
| 35 | 
            -
                    eTrans.each { |h| heads << h }
         | 
| 36 | 
            -
                    
         | 
| 34 | 
            +
                            
         | 
| 37 35 | 
             
                    heads.each do |head|
         | 
| 38 36 | 
             
                      #--
         | 
| 39 37 | 
             
                      # Check if head can transition read symbol
         | 
| @@ -42,6 +40,16 @@ module Automata | |
| 42 40 | 
             
                        transition(head, symbol).each { |t| newHeads << t }
         | 
| 43 41 | 
             
                      end
         | 
| 44 42 | 
             
                    end
         | 
| 43 | 
            +
                    
         | 
| 44 | 
            +
                    #--
         | 
| 45 | 
            +
                    # Move any e-transitions
         | 
| 46 | 
            +
                    newHeads.each do |head|
         | 
| 47 | 
            +
                      if has_transition?(head, '&')
         | 
| 48 | 
            +
                        transition(head, '&').each { |t| eTrans << t }
         | 
| 49 | 
            +
                      end
         | 
| 50 | 
            +
                    end
         | 
| 51 | 
            +
                    eTrans.each { |t| newHeads << t }
         | 
| 52 | 
            +
                    
         | 
| 45 53 | 
             
                    heads = newHeads
         | 
| 46 54 | 
             
                    break if heads.empty?
         | 
| 47 55 | 
             
                  end
         | 
    
        data/lib/automata/version.rb
    CHANGED
    
    
    
        data/spec/nfa_spec.rb
    CHANGED
    
    | @@ -2,37 +2,40 @@ require 'spec_helper' | |
| 2 2 |  | 
| 3 3 | 
             
            describe Automata::NFA do
         | 
| 4 4 |  | 
| 5 | 
            +
              ##
         | 
| 6 | 
            +
              # NFA with e-transitions
         | 
| 7 | 
            +
              #
         | 
| 5 8 | 
             
              context "Initializing from a valid file" do
         | 
| 6 9 | 
             
                before do
         | 
| 7 | 
            -
                  @nfa = Automata::NFA.new(file: 'examples/ | 
| 10 | 
            +
                  @nfa = Automata::NFA.new(file: 'examples/nfa_2.yml')
         | 
| 8 11 | 
             
                end
         | 
| 9 12 |  | 
| 10 | 
            -
                it "should accept ' | 
| 11 | 
            -
                  @nfa.accepts?(' | 
| 13 | 
            +
                it "should accept '0'" do
         | 
| 14 | 
            +
                  @nfa.accepts?('0').should == true
         | 
| 12 15 | 
             
                end
         | 
| 13 16 |  | 
| 14 | 
            -
                it "should accept ' | 
| 15 | 
            -
                  @nfa.accepts?(' | 
| 17 | 
            +
                it "should accept '1'" do
         | 
| 18 | 
            +
                  @nfa.accepts?('1').should == true
         | 
| 16 19 | 
             
                end
         | 
| 17 20 |  | 
| 18 21 | 
             
                it "should accept the empty string" do
         | 
| 19 22 | 
             
                  @nfa.accepts?('').should == true
         | 
| 20 23 | 
             
                end
         | 
| 21 24 |  | 
| 22 | 
            -
                it "should not accept ' | 
| 23 | 
            -
                  @nfa.accepts?(' | 
| 25 | 
            +
                it "should not accept '01'" do
         | 
| 26 | 
            +
                  @nfa.accepts?('01').should == false
         | 
| 24 27 | 
             
                end
         | 
| 25 28 |  | 
| 26 | 
            -
                it "should accept ' | 
| 27 | 
            -
                  @nfa.accepts?(' | 
| 29 | 
            +
                it "should accept '10'" do
         | 
| 30 | 
            +
                  @nfa.accepts?('10').should == true
         | 
| 28 31 | 
             
                end
         | 
| 29 32 |  | 
| 30 | 
            -
                it "should accept ' | 
| 31 | 
            -
                  @nfa.accepts?(' | 
| 33 | 
            +
                it "should accept '11'" do
         | 
| 34 | 
            +
                  @nfa.accepts?('11').should == true
         | 
| 32 35 | 
             
                end
         | 
| 33 36 |  | 
| 34 | 
            -
                it "should accept ' | 
| 35 | 
            -
                  @nfa.accepts?(' | 
| 37 | 
            +
                it "should accept '110'" do
         | 
| 38 | 
            +
                  @nfa.accepts?('110').should == true
         | 
| 36 39 | 
             
                end
         | 
| 37 40 | 
             
              end
         | 
| 38 41 |  | 
| @@ -46,6 +49,9 @@ describe Automata::NFA do | |
| 46 49 | 
             
                end
         | 
| 47 50 | 
             
              end
         | 
| 48 51 |  | 
| 52 | 
            +
              ##
         | 
| 53 | 
            +
              # NFA without e-transitions
         | 
| 54 | 
            +
              #
         | 
| 49 55 | 
             
              context "Initializing a NFA by params" do
         | 
| 50 56 | 
             
                before do
         | 
| 51 57 | 
             
                  states = ['q1','q2','q3','q4']
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: automata
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.6
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -13,7 +13,7 @@ date: 2012-04-25 00:00:00.000000000 Z | |
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: rake
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &70295152631100 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ! '>='
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: '0'
         | 
| 22 22 | 
             
              type: :development
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *70295152631100
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: rspec
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &70295152630000 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ~>
         | 
| @@ -32,7 +32,7 @@ dependencies: | |
| 32 32 | 
             
                    version: 2.9.0
         | 
| 33 33 | 
             
              type: :development
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *70295152630000
         | 
| 36 36 | 
             
            description: Create and simulate automaton.
         | 
| 37 37 | 
             
            email:
         | 
| 38 38 | 
             
            - jico@baligod.com
         | 
| @@ -48,8 +48,8 @@ files: | |
| 48 48 | 
             
            - Rakefile
         | 
| 49 49 | 
             
            - automata.gemspec
         | 
| 50 50 | 
             
            - examples/dfa_sample.yml
         | 
| 51 | 
            +
            - examples/nfa_1.yml
         | 
| 51 52 | 
             
            - examples/nfa_2.yml
         | 
| 52 | 
            -
            - examples/nfa_sample.yml
         | 
| 53 53 | 
             
            - lib/automata.rb
         | 
| 54 54 | 
             
            - lib/automata/dfa.rb
         | 
| 55 55 | 
             
            - lib/automata/nfa.rb
         | 
| @@ -72,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 72 72 | 
             
                  version: '0'
         | 
| 73 73 | 
             
                  segments:
         | 
| 74 74 | 
             
                  - 0
         | 
| 75 | 
            -
                  hash:  | 
| 75 | 
            +
                  hash: 830920834745777469
         | 
| 76 76 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 77 77 | 
             
              none: false
         | 
| 78 78 | 
             
              requirements:
         | 
| @@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 81 81 | 
             
                  version: '0'
         | 
| 82 82 | 
             
                  segments:
         | 
| 83 83 | 
             
                  - 0
         | 
| 84 | 
            -
                  hash:  | 
| 84 | 
            +
                  hash: 830920834745777469
         | 
| 85 85 | 
             
            requirements: []
         | 
| 86 86 | 
             
            rubyforge_project: 
         | 
| 87 87 | 
             
            rubygems_version: 1.8.17
         |