创建一个空扫描功能

时间:2014-10-25 17:16:15

标签: ruby file

如何创建空扫描功能?这是我的lexicon.rb文件

    require 'ex48/lexicon.rb'
    require "test/unit"

    class TestNAME < Test::Unit::TestCase
      def test_directions()
        assert_equal(Lexicon.scan("north"), [['direction', 'north']])
        result = Lexicon.scan("north south east")

        assert_equal(result, [['direction', 'north'],
               ['direction', 'south'],
               ['direction', 'east']])
      end

      def test_verbs()
        assert_equal(Lexicon.scan("go"), [['verb', 'go']])
        result = Lexicon.scan("go kill eat")
        assert_equal(result, [['verb', 'go'],
               ['verb', 'kill'],
               ['verb', 'eat']])
      end


      def test_stops()
        assert_equal(Lexicon.scan("the"), [['stop', 'the']])
        result = Lexicon.scan("the in of")
        assert_equal(result, [['stop', 'the'],
               ['stop', 'in'],
               ['stop', 'of']])
      end


      def test_nouns()
       assert_equal(Lexicon.scan("bear"), [['noun', 'bear']])
       result = Lexicon.scan("bear princess")
       assert_equal(result, [['noun', 'bear'],
               ['noun', 'princess']])
      end

      def test_numbers()
        assert_equal(Lexicon.scan("1234"), [['number', 1234]])
        result = Lexicon.scan("3 91234")
        assert_equal(result, [['number', 3],
               ['number', 91234]])
      end


      def test_errors()
        assert_equal(Lexicon.scan("ASDFADFASDF"), [['error', 'ASDFADFASDF']])
        result = Lexicon.scan("bear IAS princess")
        assert_equal(result, [['noun', 'bear'],
               ['error', 'IAS'],
               ['noun', 'princess']])
      end

    end

以下是步骤:

  1. 在顶部写下要求。让它工作。
  2. 创建第一个测试用例test_directions的空版本。确保运行。
  3. 编写test_directions测试用例的第一行。让它失败。
  4. 转到lexicon.rb文件,创建一个空扫描功能。
  5. 运行测试,确保扫描至少正在运行,即使它失败了。
  6. 填写psuedo代码注释,了解扫描应该如何使test_directions通过。
  7. 编写与注释匹配的代码,直到test_directions通过。
  8. 返回test_directions并编写其余行。
  9. 返回扫描lexicon.rb并对其进行处理以使此新测试代码通过。
  10. 完成后,您将完成首次通过测试,然后继续进行下一次测试。
  11. 无论如何,如何创建空扫描功能?任何答案都没问题。

5 个答案:

答案 0 :(得分:2)

添加代码

     def
      scan()
     end

答案 1 :(得分:2)

功能

    def
      (your code)
    end

所以扫描功能是

    def
      scan ()
    end

答案 2 :(得分:1)

def扫描 端

将上述功能添加到文件中。

答案 3 :(得分:1)

require 'ex48/lexicon.rb'
require "test/unit"

class TestNAME < Test::Unit::TestCase
  def test_directions()
    assert_equal(Lexicon.scan("north"), [['direction', 'north']])
    result = Lexicon.scan("north south east")

    assert_equal(result, [['direction', 'north'],
           ['direction', 'south'],
           ['direction', 'east']])
  end

  def test_verbs()
    assert_equal(Lexicon.scan("go"), [['verb', 'go']])
    result = Lexicon.scan("go kill eat")
    assert_equal(result, [['verb', 'go'],
           ['verb', 'kill'],
           ['verb', 'eat']])
  end


  def test_stops()
    assert_equal(Lexicon.scan("the"), [['stop', 'the']])
    result = Lexicon.scan("the in of")
    assert_equal(result, [['stop', 'the'],
           ['stop', 'in'],
           ['stop', 'of']])
  end


  def test_nouns()
   assert_equal(Lexicon.scan("bear"), [['noun', 'bear']])
   result = Lexicon.scan("bear princess")
   assert_equal(result, [['noun', 'bear'],
           ['noun', 'princess']])
  end

  def test_numbers()
    assert_equal(Lexicon.scan("1234"), [['number', 1234]])
    result = Lexicon.scan("3 91234")
    assert_equal(result, [['number', 3],
           ['number', 91234]])
  end


  def test_errors()
    assert_equal(Lexicon.scan("ASDFADFASDF"), [['error', 'ASDFADFASDF']])
    result = Lexicon.scan("bear IAS princess")
    assert_equal(result, [['noun', 'bear'],
           ['error', 'IAS'],
           ['noun', 'princess']])
  end
   def scan()
   end

end

我明白了。我添加了

      def 
       scan()
      end

答案 4 :(得分:1)

添加 def scan()结束 希望有所帮助