I'm in the final stage of a simple project and I need my tests to start working. Basically, I am testing a function that sorts an array, and none of my tests are asserting. I'm using the test-unit gem in Ruby.
So I have three files:
program.rb (where the method is invoked and passed an array)
plant_methods.rb (where the class is defined with its class method)
tc_test_plant_methods.rb (where the test should be run)
Heres what's in each file:
plant_methods.rb
The purpose of plant_sort is to sort each sub-array alphabetically, using the first plant in the sub-array.
class Plant_Methods
def initialize
end
def self.plant_sort(array)
array.sort! { |sub_array1, sub_array2|
sub_array1[0] <=> sub_array2[0] }
end
end
Here's the program file.
program.rb
require_relative 'plant_methods'
plant_array = [['Rose', 'Lily', 'Daisy'], ['Willow', 'Oak', 'Palm'], ['Corn', 'Cabbage', 'Potato']]
Plant_Methods.plant_sort(plant_array)
And here's the test unit.
tc_test_plant_methods.rb
require_relative "plant_methods"
require "test/unit"
class Test_Plant_Methods < Test::Unit::TestCase
def test_plant_sort
puts " it sorts the plant arrays alphabetically based on the first plant"
assert_equal([["Gingko", "Beech"], ["Rice", "Wheat"], ["Violet", "Sunflower"]], Plant_Methods.new([["Violet", "Sunflower"], ["Gingko", "Beech"], ["Rice", "Wheat"]]).plant_sort([["Violet", "Sunflower"], ["Gingko", "Beech"], ["Rice", "Wheat"]]))
end
end
However, when I run tc_test_plant_methods.rb, I get the following errors:
$ ruby tc_plant_methods.rb
Run options:
# Running tests:
[1/1] Test_Plant_Methods#test_plant_sort it sorts the plant arrays alphabetically based on the first plant
= 0.00 s
1) Error:
test_plant_sort(Test_Plant_Methods):
ArgumentError: wrong number of arguments (1 for 0)
And
Finished tests in 0.003687s, 271.2232 tests/s, 0.0000 assertions/s.
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
So basically the test runs, but it doesn't return any assertions. Can anyone point me in the right direction as to what I'm doing wrong, or how to fix this?
Aucun commentaire:
Enregistrer un commentaire