Testing(CodeEval)

文字列の差を求める問題。

CHALLENGE DESCRIPTION:

In many teams, there is a person who tests a project, finds bugs and errors, and prioritizes them. Now, you have the unique opportunity to try yourself as a tester and test a product. Here, you have two strings - the first one is provided by developers, and the second one is mentioned in design. You have to find and count the number of bugs, and also prioritize them for fixing using the following statuses: ‘Low’, ‘Medium’, ‘High’, ‘Critical’ or ‘Done’.

INPUT SAMPLE:

The first argument is a path to a file. Each line includes a test case with two strings separated by a pipeline ‘|’. The first string is the one the developers provided to you for testing, and the second one is from design.

Heelo Codevval | Hello Codeeval
hELLO cODEEVAL | Hello Codeeval
Hello Codeeval | Hello Codeeval

OUTPUT SAMPLE:

Write a program that counts the number of bugs and prioritizes them for fixing using the following statuses:
‘Low’ - 2 or fewer bugs;
‘Medium’ - 4 or fewer bugs;
‘High’ - 6 or fewer bugs;
‘Critical’ - more than 6 bugs;
‘Done’ - all is done;

Low
Critical
Done

CONSTRAINTS:

  1. Strings are of the same length from 5 to 40 characters.
  2. Upper and lower case matters.
  3. The number of test cases is 40.

My Code

#!/usr/bin/env ruby -w

def test(actual, expected)
  wrong_count = 0
  expected.size.times { |i| wrong_count += 1 unless actual[i] == expected[i] }
  case
  when wrong_count == 0 then "Done"
  when wrong_count <= 2 then "Low"
  when wrong_count <= 4 then "Medium"
  when wrong_count <= 6 then "High"
  else "Critical"
  end
end

ARGF.each_line do |line|
  actual, expected = line.chomp.split(" | ").map { |l| l.split("") }
  puts test(actual, expected)
end