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

little schemer: add new problem specs #1285

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
215 changes: 215 additions & 0 deletions exercises/little-schemer/canonical-data.json
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",
Copy link
Contributor

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.

"input": {
"function": "null?",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those from languages where ? is not a valid identifier character will probably object to this.

"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."
Copy link
Contributor

Choose a reason for hiding this comment

The 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"]
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it is expected that inputs to atom? may be things other than lists, I would say to use something reflective of that fact. Perhaps input, or if that's deemed too redundant (having an input nested inside input) then value.

},
"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
}
]
}
]
}
16 changes: 16 additions & 0 deletions exercises/little-schemer/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Implement four operations: `null?`, `car`, `cdr` (pronounced could-der), and
Copy link
Contributor

Choose a reason for hiding this comment

The 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
```
4 changes: 4 additions & 0 deletions exercises/little-schemer/metadata.yml
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"