Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Recipe: OUnit assertions #472
base: master
Are you sure you want to change the base?
Recipe: OUnit assertions #472
Changes from 2 commits
8d32bb4
73535a8
67f7fbf
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I recommend the following definition:
~printer
defines a printer (stringifier) for compared values.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.
For me, your wording sounds more like "stringified values are compared" rather than "stringified values are presented in a message". I understand it as something like Javascript's
Test.assertSimilar
.But I trust your experience more than my feelings, so I go with your proposal.
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.
It would be useful to provide some common
printer
values: for printingint
,float
,'a list
,'a array
, etc. Printers can be defined with standard OCaml functions or with Batteries (or Core) functions.Since not all translators use Batteries, it may be preferable to use standard OCaml functions in this recipe. On the other hand, Batteries include many useful printing functions. Here is a function for printing
int list
written by trashy_incel:And here is the same function using Batteries:
It is very short and can be inlined.
What do you think? Should we include examples of common printers here? If yes, then is it better to use standard OCaml functions or functions from Batteries (I don't know Core so I cannot say if it is better or not)?
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.
Initially I planned to present an example of a custom printer, but decided not to (for now).
I like the idea of listing some commonly used printers, but I have one problem with this: I struggle with finding some balance between helping authors, and repeating "obvious" things which can be found in obvious places by anyone who would be bothered to search.
Nothing of this short recipe is a thing which, in my opinion, should be presented this explicitly. The recipe presents almost nothing specific to Codewars authoring, and everything here is practical aspects of the ecosystem. Heck, even if someone is totally not familiar with OCaml, or OUnit, all it takes is one run of failing tests, a tiny piece of reflection that "heck, this is bad, there has to be some way to make this look better", and a search in official docs . I know why I have written this recipe, but why it has to be written is beyond me.
If authors struggle to find out that
~printer
even exists, then I think it's not reasonable to expect them to know how to create custom printers. I'd give them commonly used printers too. If you have an idea what printers, and ideas for implementation, just drop a list here, or on Discord, or in a ticket. I for example did not know what printer to use to print strings, or I would not know what to use to print a generic'a list
. Whether to use Core or Batteries, I don't know because I am totally not familiar with OCaml ecosystem and I do not know what are common practices. For me, both are fine. I will rely on judgment of you and other users.Thanks for reviewing!