-
-
Notifications
You must be signed in to change notification settings - Fork 195
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
crypto-square: Rewrite it to match x-common or to be more idiomatic. #259
Comments
The JSON fileThe reference Ignoring the last test - that we'll discuss later - they are related like this: normalizedPlaintext :: String -> String
plaintextSegments :: String -> [String]
plaintextSegments = toSquare . normalizedPlaintext
encoded :: String -> String
encoded = concat . transpose . plaintextSegments
ciphertext :: String -> String
ciphertext = unwords . transpose . plaintextSegments Why not?
En example solution to the exerciseThe above design seems unidiomatic in a language where function composition is so easy. A more idiomatic solution would be: normalize :: String -> String
toSquare :: [a] -> [[a]]
encode :: String -> String
encode = unwords . transpose . toSquare . normalize PaddingThe last test checks the padding of the "words" outputted by This is not mentioned in
What do we have now?In the Haskell track, currently we ask for the functions: normalizePlaintext :: String -> String -- Just missing a 'd' in the name.
plaintextSegments :: String -> [String] -- Matches the JSON file.
plaintextSegments = toSquare . normalizePlaintext
ciphertext :: String -> String -- Matches `encoded` from the JSON file.
ciphertext = concat . transpose . plaintextSegments
normalizeCiphertext :: String -> String -- Matches `ciphertext` from them JSON file, without testing for padding.
normalizeCiphertext = unwords . transpose . plaintextSegments What should we do? |
Ruby also wishes changes to their crypto-square exercism/ruby#422 Either way, should we fix the problem at the source by changing canonical-data.json? Especially if the intermediate functions are removed, we will have a lot more freedom, since we can ask for less. |
Reading exercism/problem-specifications#250, it seems that keeping the intermediary functions was not an unpopular decision at the time. so I'm not sure if people will agree with removing them. Anyway, we are not alone in the feeling that they are undesirable but, if we remove the intermediary tests, only three test will remain, and one of them has space-padded words. We need more comprehensive tests. Ignoring the JSON file or a while, we could imagine a completely new test suite... How could it be?Given a list of input-output pairs for the encoding function, we could progressively test the following:
I think that the last two test This plan would add a lot o complexity to the tests, but it would keep a progression similar to the one using intermediary functions. Is it too crazy? |
It sounds like the tests you describe will be test for particular properties of the outputs, rather than specific values! It's interesting because exercism/problem-specifications#191 was intended to be that sort of exercise as well. I'd be interested to see one. |
The "design" came out this way for two reasons:
Instead of over-specifying the tests, the idea was to test progressively until it have the minimum desired behavior. |
Fixes exercism#895, the complaint that the whitespace was being ignored. The canonical test data itself is fine; the problem was that the test suite was ignoring whitespace when comparing the actual result to the expected result. The decision to ignore whitespace was a originally deliberate decision, with the reasoning in exercism#259. However, maintainers' current judgment is that as long as our output is a String, it's better to keep it as the problem description says, for it would be against the description if a student emitted an output with a lot of leading spaces (among others). If the track changes the output to a [String], then the maintainers could freely choose whether to require the trailing spaces or forbid them.
Fixes exercism#895, the complaint that the whitespace was being ignored. The canonical test data itself is fine; the problem was that the test suite was ignoring whitespace when comparing the actual result to the expected result. The decision to ignore whitespace was a originally deliberate decision, with the reasoning in exercism#259. However, maintainers' current judgment is that as long as our output is a String, it's better to keep it as the problem description says, for it would be against the description if a student emitted an output with a lot of leading spaces (among others). If the track changes the output to a [String], then the maintainers could freely choose whether to require the trailing spaces or forbid them.
The way it is now,
crypto-square
has some problems:x-common
.x-common/crypto-square.json
, but seems so badong...At least, we need to review the functions' names.
Related to #194 and exercism/problem-specifications#356.
Important: This exercise was changed in branchhspec-fail-fast
by #249 . Please use that branch for any PR related to it or wait until it's merged inmaster
.The text was updated successfully, but these errors were encountered: