diff --git a/README.md b/README.md index 4ab283896a..f2c3a04fad 100644 --- a/README.md +++ b/README.md @@ -137,12 +137,13 @@ The `lib/$PROBLEM_cases.rb` file should contain a small class that wraps the JSO require 'exercise_cases' class ProblemNameCase < OpenStruct - def test_name + def name 'test_%s' % description.gsub(/[ -]/, '_') end def workload - # implement main logic of test here + # Example workload: + "assert #{expected.inspect}, Problem.call(#{input.inspect})" end def skipped @@ -156,8 +157,8 @@ the generator script will infer the name of the class from the argument that is This class must implement the following methods: -- `test_name` - Returns the name of the test (i.e `test_one_equals_one`) -- `workload` - Returns the main syntax for the test. This will vary depending on the test generator and its underlying implementation +- `name` - Returns the name of the test (i.e `test_one_equals_one`) +- `workload` - Returns the main syntax for the test. This includes the assertion and any setup required for the test. This will vary depending on the test generator and its underlying implementation - `skipped` - Returns skip syntax (i.e. `skip` or `# skip`) Beyond that, you can implement any helper methods that you need. @@ -183,14 +184,12 @@ loop through each of the cases in an inner loop: ``` ProblemNameCases = proc do |data| - i = 0 json = JSON.parse(data) cases = [] %w(section1 section2 etc).each do |section| json[section]['cases'].each do |row| - row = row.merge(row.merge('index' => i, 'section' => section)) + row = row.merge(row.merge('index' => cases.size, 'section' => section)) cases << ProblemNameCase.new(row) - i += 1 end end cases @@ -208,11 +207,13 @@ require 'minitest/autorun' require_relative '$PROBLEM' # Common test data version: <%= abbreviated_commit_hash %> -class ProblemNameTest < Minitest::Test<% test_cases.each do |test_case| %> +class ProblemNameTest < Minitest::Test +<% test_cases.each do |test_case| %> def <%= test_case.name %> <%= test_case.skipped %> - assert_equal <%= test_case.expected %>, <%= test_case.work_load %> + <%= test_case.workload %> end + <% end %> <%= IO.read(XRUBY_LIB + '/bookkeeping.md') %> def test_bookkeeping