Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8726611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:17:06+00:00 2026-06-13T08:17:06+00:00

I am trying to do a simple test case with Test Unit, in Ruby

  • 0

I am trying to do a simple test case with Test Unit, in Ruby 1.9.1 (Ubuntu Linux 12.04 64 bits) : but it says me that the initialize method of my TestCase is missing arguments. And when I look further at the error, it says me that it tried to launch /usr/lib/ruby/1.9.1/minitest.

However, I installed the Test Unit gem before.

This is the first source file :
Run.rb

#!/usr/bin/env ruby

require "test/unit"
require_relative "NumbersSet.rb"

def draw_result
    the_drawn_result = nil
    loop do
        the_drawn_result = rand(1000)
        break if the_drawn_result >= 100
    end
    the_drawn_result
end

def do_operation(operation, number_1, number_2)
    return nil if number_1 < 1 or number_2 < 1
    number_1, number_2 = number_2, number_1 if  number_1 < number_2
    case operation
        when :add
            result = number_1 + number_2
            return "#{number_1} + #{number_2} = #{result}", result
        when :sub
            return nil if number_1 == number_2 # A zero result will not help us
            result = number_1 - number_2
            return "#{number_1} - #{number_2} = #{result}", result
        when :mul
            return nil if number_1 == 1 or number_2 == 1 # Otherwise, this would be identity operation
            result = number_1 * number_2
            return "#{number_1} * #{number_2} = #{result}", result
        when :div
            return nil if number_1 == 1 or number_2 == 1 # Otherwise, this could be identity operation
            return nil if number_1 % number_2 != 0
            result = number_1 / number_2
            return "#{number_1} / #{number_2} = #{result}", result
        else
            raise "Unknown operation #{operation} !"
    end
end

def play
    drawn_numbers = NumbersSet.draw
    puts drawn_numbers.inspect, draw_result
end

class DrawTest < Test::Unit::TestCase
    def draw_test

        assert_equal(nil, do_operation(:add, -3, 1))
        assert_equal(nil, do_operation(:add, 1, -1))
        assert_equal(nil, do_operation(:add, 5, 0))
        assert_equal(nil, do_operation(:add, 0, 5))
        assert_equal(nil, do_operation(:add, 3, 5))
        assert_equal(nil, do_operation(:add, 5, 3))

        assert_equal(nil, do_operation(:sub, 5, 3))
        assert_equal(nil, do_operation(:sub, 3, 5))
        assert_equal(nil, do_operation(:sub, 3, 3))

        assert_equal(nil, do_operation(:mul, 3, 5))
        assert_equal(nil, do_operation(:mul, 5, 3))
        assert_equal(nil, do_operation(:mul, 3, 1))
        assert_equal(nil, do_operation(:mul, 1, 3))

        assert_equal(nil, do_operation(:div, 20, 3))
        assert_equal(nil, do_operation(:div, 3, 20))
        assert_equal(nil, do_operation(:div, 20, 1))
        assert_equal(nil, do_operation(:div, 1, 20))
        assert_equal(nil, do_operation(:div, 20, 4))
        assert_equal(nil, do_operation(:div, 5, 20))

    end
end

OPERATIONS = [:add, :sub, :mul, :div]

DrawTest.new.draw_test

This is the second file : NumbersSet.rb

class NumbersSet

    def self.draw
        plaques = {}
        (1..10).each { |value| plaques[value] = 2}
        [25,50,75,100].each { |value| plaques[value] = 1}

        draw_possibilities = (1..10).to_a << 25 << 50 << 75 << 100
        the_draw = []
        6.times do |loop_index|
            drawn_number_index = nil
            loop do
                drawn_number_index = rand(draw_possibilities.size)
                break if plaques[draw_possibilities[drawn_number_index]] > 0
            end
            the_draw << draw_possibilities[drawn_number_index]
            plaques[draw_possibilities[drawn_number_index]] -= 1
        end
        the_draw
    end

end

And this this the terminal error :

$ ./Run.rb 
/usr/lib/ruby/1.9.1/minitest/unit.rb:971:in `initialize': wrong number of arguments (0 for 1) (ArgumentError)
    from ./Run.rb:77:in `new'
    from ./Run.rb:77:in `<main>'

So, is this really a bad coding from myself, or an installation issue ?
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:17:07+00:00Added an answer on June 13, 2026 at 8:17 am

    I found what went bad :

    In file Run.rb, where I defined my TestCase subclass :

    1. The DrawTest class, as a subclass of Test::Unit::TestCase must define its tests methods with a name that begins with test => So was not draw_test.
    2. I must not create an instance of DrawTest class, as I did in the previous version

    So this source file is better :

    #!/usr/bin/env ruby
    
    require "test/unit"
    require_relative "NumbersSet.rb"
    
    def draw_result
        the_drawn_result = nil
        loop do
            the_drawn_result = rand(1000)
            break if the_drawn_result >= 100
        end
        the_drawn_result
    end
    
    def do_operation(operation, number_1, number_2)
        return nil if number_1 < 1 or number_2 < 1
        number_1, number_2 = number_2, number_1 if  number_1 < number_2
        case operation
            when :add
                result = number_1 + number_2
                return "#{number_1} + #{number_2} = #{result}", result
            when :sub
                return nil if number_1 == number_2 # A zero result will not help us
                result = number_1 - number_2
                return "#{number_1} - #{number_2} = #{result}", result
            when :mul
                return nil if number_1 == 1 or number_2 == 1 # Otherwise, this would be identity operation
                result = number_1 * number_2
                return "#{number_1} * #{number_2} = #{result}", result
            when :div
                return nil if number_1 == 1 or number_2 == 1 # Otherwise, this could be identity operation
                return nil if number_1 % number_2 != 0
                result = number_1 / number_2
                return "#{number_1} / #{number_2} = #{result}", result
            else
                raise "Unknown operation #{operation} !"
        end
    end
    
    def play
        drawn_numbers = NumbersSet.draw
        puts drawn_numbers.inspect, draw_result
    end
    
    class DrawTest < Test::Unit::TestCase
        def test_draw
    
            assert_equal(nil, do_operation(:add, -3, 1))
            assert_equal(nil, do_operation(:add, 1, -1))
            assert_equal(nil, do_operation(:add, 5, 0))
            assert_equal(nil, do_operation(:add, 0, 5))
    
            assert_equal(nil, do_operation(:sub, -3, 1))
            assert_equal(nil, do_operation(:sub, 1, -1))
            assert_equal(nil, do_operation(:sub, 5, 0))
            assert_equal(nil, do_operation(:sub, 0, 5))
    
            assert_equal(nil, do_operation(:mul, -3, 1))
            assert_equal(nil, do_operation(:mul, 1, -1))
            assert_equal(nil, do_operation(:mul, 5, 0))
            assert_equal(nil, do_operation(:mul, 0, 5))
    
            assert_equal(nil, do_operation(:div, -3, 1))
            assert_equal(nil, do_operation(:div, 1, -1))
            assert_equal(nil, do_operation(:div, 5, 0))
            assert_equal(nil, do_operation(:div, 0, 5))
    
            assert_equal(nil, do_operation(:add, 3, 5))
            assert_equal(nil, do_operation(:add, 5, 3))
    
            assert_equal(nil, do_operation(:sub, 5, 3))
            assert_equal(nil, do_operation(:sub, 3, 5))
            assert_equal(nil, do_operation(:sub, 3, 3))
    
            assert_equal(nil, do_operation(:mul, 3, 5))
            assert_equal(nil, do_operation(:mul, 5, 3))
            assert_equal(nil, do_operation(:mul, 3, 1))
            assert_equal(nil, do_operation(:mul, 1, 3))
    
            assert_equal(nil, do_operation(:div, 20, 3))
            assert_equal(nil, do_operation(:div, 3, 20))
            assert_equal(nil, do_operation(:div, 20, 1))
            assert_equal(nil, do_operation(:div, 1, 20))
            assert_equal(nil, do_operation(:div, 20, 4))
            assert_equal(nil, do_operation(:div, 5, 20))
    
        end
    end
    
    OPERATIONS = [:add, :sub, :mul, :div]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to unit test a simple EJBModule project under NetBeans 7.1, but I
This is for Play! Framework 2.0. I'm trying to write a simple test case
When trying to build a simple test program that uses atomic operations, I get
I'm trying to use the UI-Thread, so I've written a simple test activity. But
I'm trying to make a very simple OSGi test but I can't get it
I'm new to C# and trying to write a simple GUI Unit Test with
I've been trying to set my application up so that I can unit test
I'm trying to create a simple Eclipse project to test my code that uses
I'm trying to set up a simple test case of pushing to a TraceListener
I am trying to build a very simple C++ unit test project. The setup

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.