exercism/problem-specifications

Name: problem-specifications

Owner: exercism

Description: Shared metadata for exercism exercises.

Created: 2014-02-27 18:40:48.0

Updated: 2018-01-17 03:41:40.0

Pushed: 2018-01-18 21:34:16.0

Homepage: null

Size: 1431

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

problem-specifications

Shared metadata for Exercism exercises.

Contributing Guide

Please see the contributing guide

Problem metadata

Each problem's data lives in a directory under exercises/

cises/
accumulate
??? description.md
??? metadata.yml
...
minesweeper
??? canonical-data.json
??? description.md
??? metadata.yml
...
zipper
??? description.md
??? metadata.yml

There are three metadata files:

Test Data Format (canonical-data.json)

This data can be incorporated into test programs manually or extracted by a program. The file format is described in canonical-schema.json, but it is easier to understand with an example:

xercise": "foobar"
ersion" : "1.0.0"
omments":
[ " Comments are always optional and can be used almost anywhere.      "
, "                                                                    "
, " They usually document how the exercise's readme ('description.md') "
, " is generally interpreted in test programs across different         "
, " languages.                                                         "
, "                                                                    "
, " In addition to a mainstream implementation path, this information  "
, " can also document significant variations.                          "
]
ases":
[ { "comments":
      [ " A test case must have a 'description' and a 'property'.  "
      , " Anything else is optional.                               "
      , "                                                          "
      , " The 'property' is a string in lowerCamelCase identifying "
      , " the type of test, but most of the times it is just the   "
      , " name of a function being tested.                         "
      , "                                                          "
      , " Test cases can have any number of additional keys, and   "
      , " most of them also have an 'expected' one, defining the   "
      , " value a test should return.                              "
      ]
  , "description": "Foo'ing a word returns it reversed"
  , "property"   : "foo"
  , "input"      : "lion"
  , "expected"   : "noil"
  }
, { "description": "Bar'ing a name returns its parts combined"
  , "property"   : "bar"
  , "input"      : {
      "firstName"  : "Alan",
      "lastName"   : "Smithee"
    }  
  , "expected"   : "ASlmainthee"
  }
, { "comments":
      [ " Test cases can be arbitrarily grouped with a description "
      , " to make organization easier.                             "
      ]
  , "description": "Abnormal inputs: numbers"
  , "cases":
      [ { "description": "Foo'ing a number returns nothing"
        , "property"   : "foo"
        , "input"      : "42"
        , "expected"   : null
        }
      , { "description": "Bar'ing a name with numbers gives an error"
        , "property"   : "bar"
        , "input"      : {
            "firstName"  : "HAL",
            "lastName"   : "9000"
          }  
        , "expected"   : { "error": "You should never bar a number" }
        }
      ]
  }


Keep in mind that the description should not simply explain what each case is (that is redundant information) but also why each case is there. For example, what kinds of implementation mistakes might this case help us find?

There are also some conventions that must be followed:

Test Data Versioning

Test data should be versioned according to Semantic Version 2.0, which is defined as follows:

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes. Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

MAJOR version changes

The MAJOR version should be changed when the test suite is modified in a fundamentally incompatible way.

There are examples of changes requiring a MAJOR version change:

MAJOR changes should be expected to break even well-behaved test generators.

MINOR version changes

The MINOR version should change when you add functionality in a backwards-compatible manner, make non-breaking changes that alter the meaning of the test suite, make previously passing solutions possibly fail, or failing solutions fail at a different spot.

There are examples of changes requiring a MINOR version change:

MINOR changes would never break well-designed test generators, because the test-generation logic remains exactly the same.

PATCH version changes

The PATCH version should change when you make backwards-compatible bug fixes or whenever the meaning of the tests does not change.

There are examples of changes requiring a PATCH version change:

PATCH changes would never break well-designed test generators, because the test data remains exactly the same.

Automated Tests

canonical-data.json for each exercise is checked for compliance against the canonical-schema.json. In order to run these tests, you will need to have yarn installed on your system. Install them from here.

Install the required packages:

 install

Run for all exercises:

 test

Run for single exercise:

 run test-one exercises/<exercise>/canonical-data.json

Replace <exercise> by the name of exercise which you want to check.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.