JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
1.3. Testing Using Alternative Brute-Force Solution | Reply
Re: 1.3. Testing Using Alternative Brute-Force Solution (response to post by Nickolas) | Reply
Writing a brute force solution is not the only applicable method to automatically test your solution. For example, consider the ProductsOfDigits problem. If your solution involves lots of special cases (like mine did), submitting it without automated testing is looking for trouble. The problem has the form of "given x and k, find the smallest i such that F(k,i) = x", where the function F can be easily calculated. Thus, the method of automated testing is the following:

for each k
for each i from 0 to a big number
  x = F(k,i)
  j = answer of our program on x
  if j>i then ERROR
  if j<i and F(k,j) != x then ERROR


I think this method is quite generic (it works for problems where you have to reverse some simple operation).
Re: 1.3. Testing Using Alternative Brute-Force Solution (response to post by Eryx) | Reply
That's a nice testing method. It could even make into a separate recipe (since it doesn't really fit the topic of this one), if we could think of other examples (preferably easier ones). Any ideas?
Re: 1.3. Testing Using Alternative Brute-Force Solution (response to post by Eryx) | Reply
As a second thought, we'll make it a sidebar - it's a perfect fit, since it's something rare (no other such problem example) but interesting.
RSS