Ich bin in der Endphase eines einfachen Projekts und ich brauche meine Tests zu arbeiten. Im Grunde teste ich eine Funktion, die ein Array sortiert, und keiner meiner Tests behauptet. Ich benutze das Juwel in Ruby.Unit Tests funktioniert nicht - Ruby mit Test-Unit
So habe ich drei Dateien:
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, was in jeder Datei ist:
plant_methods.rb
Der Zweck plant_sort ist jeden Sub-Array alphabetisch zu sortieren, die erste Anlage in der Unter mit -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
Hier ist die Programmdatei.
program.rb
require_relative 'plant_methods'
plant_array = [['Rose', 'Lily', 'Daisy'], ['Willow', 'Oak', 'Palm'], ['Corn', 'Cabbage', 'Potato']]
Plant_Methods.plant_sort(plant_array)
Und hier ist die Testeinheit.
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
Allerdings, wenn ich tc_test_plant_methods.rb laufen lasse, erhalte ich folgende Fehler:
$ 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)
Und
Finished tests in 0.003687s, 271.2232 tests/s, 0.0000 assertions/s.
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
Also im Grunde die Testläufe, aber es nicht zurück jede Behauptungen. Kann mir jemand in die richtige Richtung weisen, was ich falsch mache oder wie ich das beheben kann?
Nur zur Erinnerung, Prinzessin @Leia_Organa, sind Tests nicht für Endstadium nennen sollte! Sie sind am Anfang. Schreiben Sie zuerst Tests, schreiben Sie später Code! –