Reputation: 293
I have simple ruby app that parses a string and counts the number of Xs and Os, and returns true if there is an equal number, otherwise false.
I want to know why my test isn't working.
When I run the test, the app gets called, and the test runs, but there are 0 runs, 0 assertion...etc. Why?
The app:
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")
The test:
require_relative "task"
require "minitest/autorun"
class Test < MiniTest::Test
def zeetest
@calc = Calc.new
assert_equal( true, @calc.xo("xoxo"))
end
end
Upvotes: 0
Views: 386
Reputation: 1335
Try this:
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
Upvotes: 1