From: Shashank Date Date: 2002-12-25T10:01:17+09:00 Subject: test/unit question I am learning to use test/unit framework included in ruby 1.7.3 (2002-11-17) [i386-mswin32] So downloaded the latest relase of Test::Unit. Here is my first attempt which does not work :-(| Please help! -- shanko # ------------------- MyClasses.rb -------------------------- class Find_Matching def initialize(lyst) p lyst if $DEBUG @lyst = lyst end def find_matching_paran(from=0) # finds the position of a closing paranthesis in the list/array for the opening paran at 'from' puts 'from = ' + from.to_s if $DEBUG list = @lyst.slice(from..-1) p list if $DEBUG m = level = 0 if (list[0] == '(') list.each_index { |i| level += 1 if (list[i] == '(') level -= 1 if (list[i] == ')') (m = i; break) if (level == 0) } end m end end if $0 == __FILE__ fmp1 = Find_Matching.new("( a ( b c ) d ) e".split) p fmp1.find_matching_paran # => 7 fmp2 = Find_Matching.new("( a ( b ( c ) d ) e )".split) p fmp2.find_matching_paran # => 10 fmp3 = Find_Matching.new(" h ( a ( b ( c ) d ) e f ) g".split) p fmp3.find_matching_paran(1) # => 11 end #----------------------- tc_MyClasses.rb ------------------------------------ # Modelled after the adder example that comes with Test::Unit require 'test/unit' require 'MyClasses.rb' class TC_Find_Matching < Test::Unit::TestCase def set_up @fm = Find_Matching.new("( a ( b c ) d ) e".split) end def test_matching_paran assert_equal(7, @fm.find_matching_paran, "Should have found correctly") end def tear_down @fm = nil end end # I get the following error when I run this test script: # NoMethodError: undefined method `find_matching_paran' for nil # C:/Documents and Settings/Shashank/My Documents/tc_MyClasses.rb:13:in `test_matching_paran'