-
-
Notifications
You must be signed in to change notification settings - Fork 544
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
little schemer: add new problem specs #1285
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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?", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those from languages where |
||
"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." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't test invalid input error conditions |
||
], | ||
"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"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either use all strings or numbers in the list, we're not testing lists. |
||
}, | ||
"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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's an established format for specifying errors, check the docs. |
||
} | ||
] | ||
}, | ||
{ | ||
"description": "Test atom of a list", | ||
"cases": [ | ||
{ | ||
"description": "atom of a list", | ||
"property": "boolean", | ||
"input": { | ||
"function": "atom?", | ||
"list": ["Immaculate", 23] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since it is expected that inputs to |
||
}, | ||
"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 | ||
} | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Implement four operations: `null?`, `car`, `cdr` (pronounced could-der), and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit confusing since there are 5 things you need to implement. |
||
`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 | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
property tends to describe the name of the function/method being tested.
In this case it would should probably be "is_null" and the function section of input should be removed.