Skip to content

simple-cipher: Add canonical-data.json #1241

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

Merged
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
147 changes: 147 additions & 0 deletions exercises/simple-cipher/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
{
"exercise": "simple-cipher",
"version": "1.0.0",
"comments":
["Some of the strings used in this file are symbolic and do not represent their literal value. They are:",
"cipher.key - Represents the Cipher key",
"cipher.encode - Represents the output of the Cipher encode method",
"new - Represents the Cipher initialization"],
"cases": [
{
"description": "Random key cipher",
"cases": [
{
"description": "Can encode",
"property": "encode",
"input": {
"plaintext": "aaaaaaaaaa"
},
"expected": "cipher.key"
Copy link
Member

@petertseng petertseng May 14, 2018

Choose a reason for hiding this comment

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

this is interesting because we are to understand that this is not the literal string "cipher.key" but instead the key of the cipher, whatever that may be.

This therefore falls under one of the categories of #1225 .

This suggests some possible courses of action:

  1. Make no change to this PR. It's up to readers of this JSON file to understand that certain fields are symbolic instead of literal strings:
    • The expected of every encode
    • The input.ciphertext of every decode
    • I'm not even sure that this list is correct
  2. Make no change to this PR. It's up to readers of this JSON file to understand that all strings beginning with the seven characters cipher. are symbolic instead of literal strings.
  3. Make a change to this PR that uses a different type (perhaps some JSON object) for such symbolic inputs and/or outputs.
  4. Add your suggestion here

I will not yet express an preference ordering between these options

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Make a change to this PR that uses a different type (perhaps some JSON object) for such symbolic inputs and/or outputs.
  2. Add your suggestion here

As a sort of combination of the above, what about the following:

"expected": {
  "match": "^{cipher.key}$"
}

Where {symbol} is to be interpolated with local variables before matching is applied.

On the surface, this approach seems to simply add complication to the current syntax. However, if this is to act as a precedent for future situations, the interpolation approach allows multiple variable values to be used.

Examples of such use:

  • "^{name.first} {name.last}$"
  • "^{a + b / c}$"

However, if my fellow maintainers think this is too complicated, my vote would be option 1.

Copy link
Contributor Author

@gustavosobral gustavosobral May 15, 2018

Choose a reason for hiding this comment

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

This one is very specific to the canonical-data specification/syntax. I believe you guys know way more than me about where we are and where we should go. I'm completely open to suggestions.

},
{
"description": "Can decode",
"property": "decode",
"input": {
"ciphertext": "cipher.key"
},
"expected": "aaaaaaaaaa"
},
{
"description": "Is reversible. I.e., if you apply decode in a encoded result, you must see the same plaintext encode parameter as a result of the decode method",
"property": "decode",
"input": {
"plaintext": "abcdefghij",
"ciphertext": "cipher.encode"
},
"expected": "abcdefghij"
},
{
"description": "Key is made only of lowercase letters",
"property": "key",
"input": {},
"expected": {
"match": "^[a-z]+$"
}
}
]
},
{
"description": "Substitution cipher",
"cases": [
{
"description": "Can encode",
"property": "encode",
"input": {
"key": "abcdefghij",
"plaintext": "aaaaaaaaaa"
},
"expected": "abcdefghij"
},
{
"description": "Can decode",
"property": "decode",
"input": {
"key": "abcdefghij",
"ciphertext": "abcdefghij"
},
"expected": "aaaaaaaaaa"
},
{
"description": "Is reversible. I.e., if you apply decode in a encoded result, you must see the same plaintext encode parameter as a result of the decode method",
"property": "decode",
"input": {
"key": "abcdefghij",
"plaintext": "abcdefghij",
"ciphertext": "cipher.encode"
},
"expected": "abcdefghij"
},
{
"description": "Can double shift encode",
"property": "encode",
"input": {
"key": "iamapandabear",
"plaintext": "iamapandabear"
},
"expected": "qayaeaagaciai"
},
{
"description": "Can wrap on encode",
"property": "encode",
"input": {
"key": "abcdefghij",
"plaintext": "zzzzzzzzzz"
},
"expected": "zabcdefghi"
},
{
"description": "Can wrap on decode",
"property": "decode",
"input": {
"key": "abcdefghij",
"ciphertext": "zabcdefghi"
},
"expected": "zzzzzzzzzz"
},
{
"description": "Can handle messages longer than the key",
"property": "encode",
"input": {
"key": "abc",
"plaintext": "iamapandabear"
},
"expected": "iboaqcnecbfcr"
}
]
},
{
"description": "Incorrect key cipher",
"cases": [
{
"description": "Throws an error with an all uppercase key",
"property": "new",
"input": {
"key": "ABCDEF"
},
"expected": { "error": "Bad key" }
},
{
"description": "Throws an error with a numeric key",
"property": "new",
"input": {
"key": "12345"
},
"expected": { "error": "Bad key" }
},
{
"description": "Throws an error with empty key",
"property": "new",
"input": {
"key": ""
},
"expected": { "error": "Bad key" }
}
]
}
]
}