Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test generator documentation. #560

Merged
merged 2 commits into from
Apr 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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