Python doctrines associate simple tests with source code (in Python they are in the function documentation). Additional information and examples here .
Is there anything similar for Clojure?
I know about unit tests with clojure.test , but you are looking for something more closely integrated with the source (usually unit tests are in different files, here I want to get "inside" defn ).
Search around I found this one , but it seems very insincere (the tests are in real text, for example Python - certainly a macro that extends defn would be preferable?).
Or maybe there is another way to solve the general problem, namely that I have some tests (usually simple things that demonstrate the basic properties of the function) that would be best included in the documentation (I use marginalia ) than in separate unit files test.
update Here is an example: I have a function that calculates (manhattan) the distance (in pixels) from the rectangle of pixels to the center of the image. It sounds simple, but complicated by things like the difference in the "center" value for images with an odd or even number of pixels on the sides or with which part of the block you are measuring. So I had to write some tests to get the code directly. And now I look at the documents, and in fact it would be better if the documents included these tests, because they explained better than words what the function does ...
andrew cooke
source share