NameError: Uninitialized constant Linked_Test::Nill
NameError: Uninitialized constant Linked_Test::Nill
我正在尝试通过 minitest 创建一个测试来测试我的 class LinkedList。
我收到此错误消息:
1) Error:
Linked_ListTest#test_next_node_after_head_is_nil:
NameError: uninitialized constant Linked_ListTest::Nil
test/linked_list_test.rb:26:in `test_next_node_after_head_is_nil'
This is my test:
24 def test_next_node_after_head_is_nil
25 list = LinkedList.new
26 assert_equal Nil, head.next_node
27 end
我的预期行为是:
list.head.next_node
=> nil
这是我的链表class
class LinkedList
attr_reader :head
def initialized(data = nil)
@head = Node.new(data)
end
def append(sound)
"doop"
end
def next_node
nil
end
end
我不确定该错误对第 26 行意味着什么。
记住大小写很重要,nil
存在于 ruby 中(代表 NULL),但 Nil
不存在;所以在你的断言中使用 nil
而不是 Nil
:
assert_equal nil, head.next_node
我正在尝试通过 minitest 创建一个测试来测试我的 class LinkedList。
我收到此错误消息:
1) Error:
Linked_ListTest#test_next_node_after_head_is_nil:
NameError: uninitialized constant Linked_ListTest::Nil
test/linked_list_test.rb:26:in `test_next_node_after_head_is_nil'
This is my test:
24 def test_next_node_after_head_is_nil
25 list = LinkedList.new
26 assert_equal Nil, head.next_node
27 end
我的预期行为是:
list.head.next_node => nil
这是我的链表class
class LinkedList
attr_reader :head
def initialized(data = nil)
@head = Node.new(data)
end
def append(sound)
"doop"
end
def next_node
nil
end
end
我不确定该错误对第 26 行意味着什么。
记住大小写很重要,nil
存在于 ruby 中(代表 NULL),但 Nil
不存在;所以在你的断言中使用 nil
而不是 Nil
:
assert_equal nil, head.next_node