From 9d7382d7878988db2f676aeab5ed26fe59f77f44 Mon Sep 17 00:00:00 2001 From: Geoff Hubbard Date: Fri, 21 Apr 2017 08:07:44 +0100 Subject: [PATCH 1/2] Update test generator documentation. Update the readme to better reflect the current best practices for test generators. --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4ab283896a..7b4cb2b617 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,8 @@ class ProblemNameCase < OpenStruct end def workload - # implement main logic of test here + # Example workload: + "assert #{expected.inspect}, Problem.call(#{input.inspect})" end def skipped @@ -157,7 +158,7 @@ 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 +- `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 From 96829271dea97a90ce28738c6bd10e1bfb02f0b7 Mon Sep 17 00:00:00 2001 From: Geoff Hubbard Date: Fri, 21 Apr 2017 08:51:55 +0100 Subject: [PATCH 2/2] Name the name method `name` --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7b4cb2b617..f2c3a04fad 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ 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 @@ -157,7 +157,7 @@ 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`) +- `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`)