Alpha Chen 2 years ago
parent 7bc04b20e2
commit 34dce8f404
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -327,16 +327,16 @@ module Minitest
# We enter the choices made in a tree. # We enter the choices made in a tree.
node = @tree node = @tree
test_case.choices.each.with_index do |c, i| *rest, last = test_case.choices
if i + 1 < test_case.choices.length || test_case.status == Status::OVERRUN rest.each do |c|
if node.has_key?(c) node = if node.has_key?(c)
node = node[c] node[c]
else else
node = node[c] = {} node[c] = {}
end end
else
node[c] = test_case.status
end end
unless last.nil?
node[last] = test_case.status == Status::OVERRUN ? {} : test_case.status
end end
test_case.status test_case.status

@ -471,6 +471,49 @@ class Minitest::ThesisTest < Minitest::Thesis
end end
end end
def test_refactoring_cache
old = ->(node, choices, status) {
choices.each.with_index do |c, i|
if i + 1 < choices.length || status == Status::OVERRUN
node = if node.has_key?(c)
node[c]
else
node[c] = {}
end
else
node[c] = status
end
end
}
new = ->(node, choices, status) {
*rest, last = choices
rest.each do |c|
node = if node.has_key?(c)
node[c]
else
node[c] = {}
end
end
unless last.nil?
node[last] = status == Status::OVERRUN ? {} : status
end
}
run_test("refactoring_cache", database: {}) do |tc|
old_tree = {}
new_tree = {}
choices = tc.any(lists(integers(0, 10)))
status = Status.new(tc.choice(4))
old.(old_tree, choices, status)
new.(new_tree, choices, status)
assert_equal old_tree, new_tree
end
end
private private
def suppress_warnings def suppress_warnings

Loading…
Cancel
Save