Skip to content

Commit

Permalink
Add ability to compare a display service vs 'perfect' results
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgibbs committed Nov 24, 2023
1 parent 68514a5 commit 906c305
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,10 @@ task "local-compare" do
end
end

task "perfect-compare" do
compare_vs_perfect(display: "scarpe-webview", config: "local-tiranti")
compare_vs_perfect(display: "scarpe-wasm", config: "wasm")
compare_vs_perfect(display: "niente", config: "local")
end

task default: "shoes-spec"
36 changes: 24 additions & 12 deletions lib/shoes-spec/report_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,7 @@ def results_filename(config)
"results-#{config}.yaml"
end

def compare_results(display:, config:)
dir = results_dir(display)
filename = results_filename(config)

expected = YAML.load(File.read "#{dir}/expected/#{filename}")
actual = YAML.load(File.read "#{dir}/#{filename}")

expected_items = expected[:results]
actual_items = actual[:results]

def compare_expected_actual(name, expected_items, actual_items)
unexpected_items = []
incorrect_items = []
not_present_items = []
Expand Down Expand Up @@ -92,11 +83,11 @@ def compare_results(display:, config:)
end

if unexpected_items.empty? && incorrect_items.empty? && not_present_items.empty?
puts "Results for #{display}-#{config} are exactly as expected."
puts "Results for #{name} are exactly as expected."
puts "-------"
true
else
puts "For #{display}-#{config}:"
puts "For #{name}:"
puts " Tests with no expected result:" unless unexpected_items.empty?
unexpected_items.each do |cat, test, res|
puts " * #{cat} / #{test}: #{res}"
Expand All @@ -113,4 +104,25 @@ def compare_results(display:, config:)
false
end
end

def compare_results(display:, config:)
dir = results_dir(display)
filename = results_filename(config)

expected = YAML.load(File.read "#{dir}/expected/#{filename}")
actual = YAML.load(File.read "#{dir}/#{filename}")

compare_expected_actual("#{display}-#{config}", expected[:results], actual[:results])
end

def compare_vs_perfect(display:, config:, compare_expected: true)
dir = results_dir(display)
ideal_dir = results_dir("ideal")
filename = results_filename(config)

expected = YAML.load(File.read "#{ideal_dir}/results-perfect.yaml")
actual = YAML.load(File.read "#{dir}/#{compare_expected ? "expected/" : ""}#{filename}")

compare_expected_actual("#{display}-#{config}", expected[:results], actual[:results])
end
end

0 comments on commit 906c305

Please sign in to comment.