PHP Classes

Buggy - More Testing

Recommend this page to a friend!

      Sudoku Solver  >  All threads  >  Buggy - More Testing  >  (Un) Subscribe thread alerts  
Subject:Buggy - More Testing
Summary:Unexpected behaviour and incorrect help information.
Author:Christian Royle
Date:2005-09-05 10:56:12
Update:2005-09-13 13:45:26

  1. Buggy - More Testing   Reply   Report abuse  
Christian Royle - 2005-09-05 10:56:12
NOTE: Yes, this is PHP5 only, and it would be nice if the writer stated this.

This class is buggy, badly thought out, and under tested, here is some reasons:

(1) The help page states the following about the 'Value-Check' action:

"This action is useful if you would like to solve the Sudoku yourself, but you would like to avoid the pain of finding all possible values for each field.
This action iterates over each field and calculates the possible values. If this is a single value, that will lead to updatting the possible values already found. The Solver makes only one pass. Newly found values are shown in red."

However, pressing the value-check button, results in the puzzle being completed, which sort of defeats the object of the class. You get the same result when pressing "unique-check". I haven't bothered to test the others.

Note that the behaviour works with the example files, but does not work with other data sets - here is an example:

1, 6, 4, , , , , , 2,
2, , , 4, , 3, 9, 1, ,
, , 5, , 8, , 4, , 7,
, 9, , , , 6, 5, , ,
5, , , 1, , 2, , , 8,
, , 8, 9, , , , 3, ,
8, , 9, , 4, , 2, , ,
, 7, 3, 5, , 9, , , 1,
4, , , , , , 6, 7, 9,

(2) The upload generates "No such file or directory" unless you have already created a "temp" directory. A good programmer checks for the existence of the directory and raises a human readable error if it does not exist.

(3) The class is described as being designed as humans would use it, but the tab order takes you through each 3x3 square. All 8 people I asked to test data entry in the grid preferred to enter data line-by-line and were having to continually refer back to their data source to read more information for the 3x3 grid.

(4) If there are more than 5 possibilities for a square, they do not display correctly.

I like the idea of the class, but it needs a lot more work and testing before it is released on PHPClasses.

  2. Re: Buggy - More Testing   Reply   Report abuse  
Manuel Lemos - 2005-09-05 18:59:49 - In reply to message 1 from Christian Royle
It is my fault that did not put this class under PHP 5 group when I approved it. It is fixed now.

Other than that, there are no particular quality requirements to publish classes in the PHP Classes site. Quality is subjective. What may seem to not have enough quality for some, may be good enough for others.

Everybody has the chance to publish their classes in the site. The idea of the site is to allow every author to share their classes to the largest audience possible, so that can maximize the chances of receiving (hopefully) constructive feedback to motivate the authors to keep improving their work.

  3. Re: Buggy - More Testing   Reply   Report abuse  
Ghica van Emde Boas - 2005-09-05 22:24:29 - In reply to message 1 from Christian Royle
Thanks for the praise ;-)
If a puzzle is completed by only pressing the value check button, then this was a puzzle in the "easy" category. As a human you would do it the same way. By the time you would arrive at the last field, the puzzle would be solved.
There are however many Sudoku's which are not so easy to solve, like the hard example I provided can not be solved at all without some trial and error by the user. Your example is apparently of the easy kind, because it is solved within one pass.

(2) If you had read the readme text, you would have known that a temp directory was needed.
I agree about your good programmer statement, but it was beyond the objective of a fun summer vacation project to sprinkle my program with defensive checks and error messages. This is open source, you could help me out here...

(3) Personally I had no problem at all with entering puzzle examples using the tab order as it is. It did not even occur to me that it could be a problem to someone.
It would be rather hard to change though, because the arragement of 3x3 grids with borders within a table would be broken. I could not find a way to get the borders right otherwise. If you have a suggestion, let me know.

(4) The other figures are there if there are more than 5, they are just hidden because the field is not big enough. Maybe next release...

I wonder what you expect of classes on the phpClasses site. I think that Manuel is doing great by giving people a chance to publish their work.
I do not know at how many other classes you have looked, but I have seen quite a few that had no documentation, no testcase, or that had apparent bugs. Mine works as described and it has documentation and testcases.

You say it is badly thought out, why? There no known set of requirements for solving Sudoku games! This class is not solving a bussiness problem, it was just for fun. I will be happy to implement good suggestions though (if I find some time, this is not a job I do for a living of course).

  4. Re: Buggy - More Testing   Reply   Report abuse  
Christian Royle - 2005-09-06 00:05:57 - In reply to message 2 from Manuel Lemos
Thanks for correcting the PHP5 listing. This will make it clearer for downloaders to determine what they need, before they download/install.

I fully support your site and its growing reputation, and completely understand that there is no expectation of quality or level of programming skill.

This of course does not reduce my *personal* expectation on *any* open source programmer to take responsibility for their designs and products and test accordingly. You may not agree with my expectations, and I have no problem with that (I have been fairly criticised for this in the past)... but sadly there will always be moaning pedants like myself, and hopefully we play our part in keeping the quality up.

Please don't take offence, your site is excellent, and full of good ideas, some of which are implemented with pride for quality and tested to a reasonable level for developers to build upon, and others which are more sketches of ideas. Both of which are equally valid.

  5. Re: Buggy - More Testing   Reply   Report abuse  
Christian Royle - 2005-09-06 00:46:21 - In reply to message 3 from Ghica van Emde Boas

Please accept my apologies if my reply seemed aggresive, it wasn't intended, but reading it back I see that it is poorly worded. I was very busy this morning and, well I think you get the picture.

Here's a more contructive approach:

1) I appreciate the reason why the puzzles are completed, and looking at your code, I can see how this happens. Personally, I would simplify the functions available in the solver, so that a user has at least one button that does not solve the puzzle but presents all available numbers in each field.

2) I *did* read the README file, but still tripped up, perhaps because the information is not clear in the README file. You have gone to a lot of trouble to produce good algorithms, and it seems odd not to include a small section of code such as:

if (!is_dir($uploaddir)) {
trigger_error("You need to create a directory: " . $uploaddir,

3) You don't need to change the layout of the table or input fields to allow the user to TAB along one row at a time. Just give each field across each row an ever increasing 'tabindex' and the browser will take care of the rest.

So, if you imaging the columns are labelled A,B,C,D... and the rows are labelled 1-9, and if you realise that the tabindex does not have to be sequential, the following tabindices could be applied to the textfields in each column/row:

A1 tabindex="11"
A2 tabindex="12"
A3 tabindex="13"
A4 tabindex="14"
A5 tabindex="15"
A6 tabindex="16"
A7 tabindex="17"
A8 tabindex="18"
A9 tabindex="19"
B1 tabindex="21"
B2 tabindex="22"
B3 tabindex="23"
B4 tabindex="24"
B5 tabindex="25"
B6 tabindex="26"
B7 tabindex="27"
B8 tabindex="28"
B9 tabindex="29"


Looking at your 'NumberField' class, this would be easy to implement, since you store the grid location of each field. You would need to modify the HTML output by the function 'displayField()'.

4) Use CSS to cause the text to wrap within a field. HINT - You don't have to make the field an '<INPUT type="text"...' until the user clicks on the area, intendind to enter a character.

I hereby aplogise and recind "Badly Thought Out", although *I* would personally never release a 'Just For Fun' piece of code along with the GNU license.

In my humble opinion (and I know people disagree with me), if a programmer expects intellectual property protection under the GPL, a third party programmer should be able to expect a basic level of quality and unit testing/approval to have been attained. We can't have the best of both worlds, otherwise we end up with Microsoft ;-)

  6. Re: Buggy - More Testing   Reply   Report abuse  
Manuel Lemos - 2005-09-06 02:45:24 - In reply to message 4 from Christian Royle
Christian, that is ok. It is not up to me to judge the quality of the published classes, not even the fairness of the eventual criticisms that the users may make.

I just wanted to make clear that the site does not impose any quality requirements to accept classes for publishing. The spirit is to let the users be the judges of that.

If this or other classes do not match your quality requirements, that is ok. You are free to express that here or rate each class according to your criteria.

I am sure many authors appreciate well justified criticisms, and if possible suggestions for improvements, because that helps them to focus their efforts in well appreciated aspects. Well made criticisms may lead the authors to work on improvements from which they ultimately also benefit.

So rest assured that I did not take any offense nor I meant to censor your comments.

  7. Re: Buggy - More Testing   Reply   Report abuse  
Ghica van Emde Boas - 2005-09-06 12:18:48 - In reply to message 5 from Christian Royle
Apologies accepted. Now it starts to be interesting!
One of your problems is the GPL licence. The only reason I selected that is that I wanted the source to remain open if someone adds to it or changes it. I thought GPL would be the best choice for that.

If you do a piece of open source development alone, you do not have any feedback and therefore always unexpected requirements or criticisms come up. I did not consider my code really production strength yet, but you cannot be sure if you do not get some exposure. For that I appreciate your feedback very much.

One reason to put it out now, is because I was curious whether someone would come up with a rule I could add that could solve the very hard type sudoku's, without resorting to brute force.

It would be nice if we would be able to specify a status of the code, like alpha or beta version - I could have done that if I would have put my code on Sourceforge for example. I put it on phpClasses, because I wanted it to be something informal and it is something small.

I will implement your suggestions (not today, because it happens to be my birthday). I am not sure yet about the possible values input fields though. I guess I would need some javascript to handle changing output fields to input fields on the fly. I will think about it.

I know that there is more error checking to be done too, for example, if you would put abc in one of the input fields, I do not know what will happen. I plan to solve that too.


  8. Re: Buggy - More Testing   Reply   Report abuse  
Christian Royle - 2005-09-06 14:37:56 - In reply to message 7 from Ghica van Emde Boas
A little javascript to allow you to restrict character entry to numerical values only. Copy/Paste this into a HTML file and test it.

<title>Test input numeric only</title>

function numericOnly() {
var key=window.event.keyCode;
var keychar;
keychar = String.fromCharCode(key);
validSet += String.fromCharCode(8);
if (validSet.indexOf(keychar) < 0) {
return false;
} else {
return true;

<input type="text" name="numericField" onkeypress="return numericOnly()">


  9. Re: Buggy - More Testing   Reply   Report abuse  
Ghica van Emde Boas - 2005-09-13 13:45:26 - In reply to message 1 from Christian Royle
As well as I could, I implemented Christians suggestions. This went far beyond my knowledge of Javascript, therefore it took a while.

The value-check does not recurse anymore. It takes now 4 button presses to solve Christians puzzle.

I added an undo function, so you can go back and forth if you want. Similarly, I added a reset, which brings you back as if you just uploaded the last example.

I added the error message if you do not have a temp directory.

The tabbing order is now as Christian likes it.

All possibilities, even if more than 5, are shown. If you click on a field, it changes to an input field, and in this case some digits may disappear (but are still there). I did not do the check for numerics only (yet). If you edit a field, be a bit careful!