Skip to content

Commit

Permalink
Merge pull request #560 from Insti/Update_test_generator_documentation
Browse files Browse the repository at this point in the history
Update test generator documentation.
  • Loading branch information
kotp authored Apr 21, 2017
2 parents 67e3b5a + 9682927 commit 7ae5bec
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7ae5bec

Please sign in to comment.