Testing an algorithm...
Testing an algorithm...
- Subject: Testing an algorithm...
- From: Martin Crisp <email@hidden>
- Date: Thu, 6 Feb 2003 16:12:54 +1100
- Organization: Tesseract Computing
Having finally decided to re-write a piece of AS spaghetti from a
couple of years ago... [It was impossible to follow, though it
seemed to work]
I'm now not sure what are good test cases for what the code I've
written does. [It works for all cases I've tried, but there are far
too many cases for me to consider testing all of them]
If you're inclined to have a look at what I've written, and perhaps
comment on it (or testing correctness in general) read on;
otherwise, sorry for wasting your time...
The algorithm fits into a series of scripts, it evaluates a list of
13 integers [values 1-13] sorted in ascending order, to see if the
list can be broken into '3 straights', one of 3 cards, and 2 of 5
cards. BUT the 'aces' can be both low [value of 1] or high [value
of 14]. At most a value can appear only 4 times in the list. So
the script has to re-assign the list items to deal with cases where
an ace should be regarded as a high card, rather than a low card.
Currently the algorithm only returns a boolean.
(true=the list could be divided into 3 straights).
Example input:
{1, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13}
Which can be made into 3 straights:
{1, 2, 3, 4, 5} {6, 7, 8} {10, 11, 12, 13, 14}
or
{1, 2, 3} {4, 5, 6, 7, 8} {10, 11, 12, 13, 14}
If you're interested in looking at the script it's here:
http://members.ozemail.com.au/~martincrisp/3Straights.sit
[if you have problems downloading please contact me offlist, it
works here using Mozilla...]
Notes:
* It is meant to be run from the Script Editor (or whatever) as the
run handler currently has the list to test hard-coded.
* It has only been tested a little as is, I've included the
algorithm in the main application, though, and it's been tested a
few thousand times there (without error in its current form).
* It only has to find 1 solution, or that there are none.
* It contains no error checking, as it needs to not generate errors
and to run as quickly as possible [meaning I want to know about
them loudly]. Hence it assumes a great deal about the problem space
of the larger application and is not a good general routine.
* It isn't heavily commented, though I think it reads fairly well.
Comments on this would be appreciated.
TIA for any comments.
Have Fun
Martin
--
I have absolutely no reason to complain about "success" with my
work; [...] And yet, from time to time a boundless sense of
inferiority plagues me, a desperate feeling of general failure; how
does a person acquire such bits of lunacy?
- MC Escher
Almost always SMASHed
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.