Minitest不工作​​

时间:2015-10-07 21:07:21

标签: ruby minitest

我有一个简单的ruby应用程序,它解析一个字符串并计算X和Os的数量,如果有相同的数字则返回true,否则返回false。

我想知道为什么我的测试不起作用。

当我运行测试时,应用程序被调用,测试运行,但是有0次运行,0次断言等等。为什么呢?

该应用:

class Calc

  def xo(str)
    ex = 0
    oh = 0
    for i in (0...str.length)
      if str[i] == "x" || str[i] == "X"
        ex += 1
      elsif str[i] == "o" || str[i] == "O"
        oh += 1
      else
      end
    end
    if ex == oh
      puts "equal" 
      return true
    else
      puts "not equal"
      return false
    end
  end
end

Calc.new.xo("xoxoo")

测试:

require_relative "task"
require "minitest/autorun"

class Test < MiniTest::Test

  def zeetest
    @calc = Calc.new
    assert_equal( true, @calc.xo("xoxo"))
  end

end

1 个答案:

答案 0 :(得分:1)

试试这个:

require_relative "task"
require "minitest/autorun"

class TestCalc < MiniTest::Test

  def setup
    @calc = Calc.new
  end

  def test_xo
    assert_equal( true, @calc.xo("xoxo"))
  end

end