@@ -96,6 +96,38 @@ This is usually the hard part of creating random tests. After all, creating
96
96
sufficient random input is most often harder than creating the kata itself.
97
97
But it is worth every honour.
98
98
99
+ ### Hide your solution
100
+ If you use random tests, make sure to hide your solution. In Java or C#, this
101
+ includes making your function ` private ` . Haskell doesn't allow mutual imports,
102
+ so the user cannot import the tests either way. However, in dynamic languages,
103
+ one can sometimes simply use ` solve = solution ` .
104
+
105
+ You can prevent this kind of cheating if you
106
+
107
+ - add static tests (not only random ones),
108
+ - move your solution into a local scope.
109
+
110
+ The first one is obvious. The second one can be realized if you don't provide
111
+ a ` solution ` with the same interface, but instead a ` testAgainstSolution ` :
112
+
113
+ ``` javascript
114
+ // bad!
115
+ var solution = function (a , b ){
116
+ // ...
117
+ }
118
+
119
+ // better
120
+ var testFunction = function (a ,b ){
121
+ var solution = function (a , b ) {
122
+ // ...
123
+ }
124
+ Test .assertEquals (userFunc (a,b), solution (a,b));
125
+ }
126
+ ```
127
+ There are more creative ways to hide/store the function, but that's one way
128
+ at least. Note that all dynamic languages on Codewars (Ruby, Python, CS, JS)
129
+ support this kind of local scopes.
130
+
99
131
### Always have some example tests
100
132
101
133
Unless you're creating a puzzle where the user has to find * the answer* ,
0 commit comments