From b5c446abc8b87c56b29e6ad456ac34df6d2e830d Mon Sep 17 00:00:00 2001 From: Fronk Lom Lom Date: Fri, 3 Aug 2018 23:03:41 +0800 Subject: [PATCH] Add new problem specs for Little Schemer --- exercises/little-schemer/canonical-data.json | 215 +++++++++++++++++++ exercises/little-schemer/description.md | 16 ++ exercises/little-schemer/metadata.yml | 4 + 3 files changed, 235 insertions(+) create mode 100644 exercises/little-schemer/canonical-data.json create mode 100644 exercises/little-schemer/description.md create mode 100644 exercises/little-schemer/metadata.yml diff --git a/exercises/little-schemer/canonical-data.json b/exercises/little-schemer/canonical-data.json new file mode 100644 index 0000000000..11bfe19a01 --- /dev/null +++ b/exercises/little-schemer/canonical-data.json @@ -0,0 +1,215 @@ +{ + "exercise": "little-schemer", + "version": "1.0.0", + "comments": [ + "Tests are ordered to allow sequential build up of primitives", + "for use in writing the final recursive function lat?." + ], + "cases": [ + { + "description": "Test null? of a list", + "cases": [ + { + "description": "null of non-empty list", + "property": "boolean", + "input": { + "function": "null?", + "list": [1] + }, + "expected": false + }, + { + "description": "null of empty list", + "property": "boolean", + "input": { + "function": "null?", + "list": [] + }, + "expected": true + }, + { + "description": "null of non-list", + "property": "exception", + "input": { + "function": "null?", + "list": "'Zang'" + }, + "comments": [ + "The primitive null? is defined only for lists." + ], + "expected": -1 + } + ] + }, + { + "description": "Test car of a list", + "cases": [ + { + "description": "car of simple list", + "property": "equality", + "input": { + "function": "car", + "list": [1] + }, + "expected": 1 + }, + { + "description": "car of small list", + "property": "equality", + "input": { + "function": "car", + "list": ["Immaculate", 23, "G.O.A.T"] + }, + "expected": "'Immaculate'" + }, + { + "description": "car of nested list", + "property": "equality", + "input": { + "function": "car", + "list": [[4, 5], 6, 7, [8, 9]] + }, + "expected": [4, 5] + }, + { + "description": "car of null list", + "property": "exception", + "input": { + "function": "car", + "list": [] + }, + "comments": [ + "The primitive car is defined only for non-empty lists." + ], + "expected": -1 + } + ] + }, + { + "description": "Test cdr of a list", + "cases": [ + { + "description": "cdr of simple list", + "property": "equality", + "input": { + "function": "cdr", + "list": [1] + }, + "expected": [] + }, + { + "description": "cdr of small list", + "property": "equality", + "input": { + "function": "cdr", + "list": ["Immaculate", 23, "G.O.A.T"] + }, + "expected": [23, "G.O.A.T"] + }, + { + "description": "cdr of nested list", + "property": "equality", + "input": { + "function": "cdr", + "list": [[4, 5], 6, 7, [8, 9]] + }, + "expected": [6, 7, [8, 9]] + }, + { + "description": "cdr of null list", + "property": "exception", + "input": { + "function": "cdr", + "list": [] + }, + "comments": [ + "The primitive cdr is defined only for non-empty lists. The cdr of any non-empty list is always another list" + ], + "expected": -1 + } + ] + }, + { + "description": "Test atom of a list", + "cases": [ + { + "description": "atom of a list", + "property": "boolean", + "input": { + "function": "atom?", + "list": ["Immaculate", 23] + }, + "expected": false + }, + { + "description": "atom of a string", + "property": "boolean", + "input": { + "function": "atom?", + "list": "'Immaculate'" + }, + "expected": true + }, + { + "description": "atom of an integer", + "property": "boolean", + "input": { + "function": "atom?", + "list": 23 + }, + "expected": true + }, + { + "description": "atom of null list", + "property": "boolean", + "input": { + "function": "atom?", + "list": [] + }, + "expected": false + } + ] + }, + { + "description": "Test lat of a list", + "cases": [ + { + "description": "lat of a simple list", + "property": "boolean", + "input": { + "function": "lat?", + "list": ["Immaculate", 23] + }, + "expected": true + }, + { + "description": "lat of another list", + "property": "boolean", + "input": { + "function": "lat?", + "list": ["Immaculate", "Bicycle"] + }, + "expected": true + }, + { + "description": "lat of nested list", + "property": "boolean", + "input": { + "function": "lat?", + "list": ["Help", "I", "am", ["nested"]] + }, + "expected": false + }, + { + "description": "lat of null list", + "property": "boolean", + "input": { + "function": "lat?", + "list": [] + }, + "expected": true + } + ] + } + ] +} diff --git a/exercises/little-schemer/description.md b/exercises/little-schemer/description.md new file mode 100644 index 0000000000..fd245dc952 --- /dev/null +++ b/exercises/little-schemer/description.md @@ -0,0 +1,16 @@ +Implement four operations: `null?`, `car`, `cdr` (pronounced could-der), and +`atom?` to be *used together* in defining a **recursive operation** +`lat?` (short for list of atoms). + +Given a list of numbers, strings, and/or lists, `lat?` returns a +**boolean** indicating if the input list is a list of atoms. + +``` +l = [1, 'Two', 3, 4, []] +lat?(l) +false + +m = ['Grapefruit', 'Tea', 'Yo'] +lat?(m) +true +``` diff --git a/exercises/little-schemer/metadata.yml b/exercises/little-schemer/metadata.yml new file mode 100644 index 0000000000..cc2724f969 --- /dev/null +++ b/exercises/little-schemer/metadata.yml @@ -0,0 +1,4 @@ +--- +blurb: "Given a list, recursively determine whether the list contains only atoms." +source: "The Little Schemer" +source_url: "https://mitpress.mit.edu/books/little-schemer-fourth-edition"