Write a program to generate all potential
anagrams of an input string.
For example, the potential anagrams of "biro" are
biro bior brio broi boir bori
ibro ibor irbo irob iobr iorb
rbio rboi ribo riob roib robi
obir obri oibr oirb orbi orib
--
You received this message because you are subscribed to the Google Groups "software_craftsmanship" group.
To post to this group, send email to software_cr...@googlegroups.com.
To unsubscribe from this group, send email to software_craftsma...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/software_craftsmanship?hl=en.
I think there are a number of small tests that you can use here:
The result is a sequence.
Each element of the sequence has N characters where N = len( input ).
Each element of the sequence has the same set of characters as the input.
The sequence does not contain the input.
The sequence has K elements = factorial( N ) - 1 where N = len( input ).
Each element of the sequence is unique.
Each test would need a few variants based on inputs ("", "a", "it",
"the", "name" ought to be enough).
That should give you a nice, gentle slope of tests that you can write
the code for a little at a time.
Thoughts?
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
--
- George
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
+1 on this.
This is also why I consider the statement "I'll TDD a <well known data
structure>" an oxymoron.
As soon as you name the algorithm or data structure you've already
taken taken a leap of faith w.r.t design and what would constitute a
'sane' design.
Yah, that's why I don't like using algorithmically-based topics for more than basic TDD.
I've found it much more interesting (and fun) to do the basics of a dice-based game, such as Monopoly. I guess I should write up how I've done that. :-)
It's worth pointing out that while this type of exercise is great for
practice real TDD is mostly about imagining the API you want to use
and then using that to wrap the algorithm out of the book, or better
yet someone else's well tested library.
On 1/5/12 5:26 AM, Alastair Smith wrote:
> Thanks everyone for your replies!
>
> A few of you mentioned that you thought this wasn't a good problem for
> TDD, but was still suited to test-first development. How would you go
> about tackling this in a test-first manner as distinct to a test-driven
> manner? Would you plan out all your tests, write all your tests, and
> then write the implementation, or would you still take an incremental
> approach to the test and production code?
I would still take an incremental approach. The distinction is that I'm
not letting the needs of the client's usage drive the design. Instead,
I'm expressing the requirements of the algorithm in tests.
In your example, I would likely start with the 0-character, 1-character,
and 2-character cases, as you mentioned. When I got to the 3-character
case, I would implement it using the design I had in mind (the recursive
algorithm) rather than trying to tease out the design as forced by the
tests.
- George
On 1/5/12 5:26 AM, Alastair Smith wrote:Thanks everyone for your replies!A few of you mentioned that you thought this wasn't a good problem forTDD, but was still suited to test-first development. How would you goabout tackling this in a test-first manner as distinct to a test-drivenmanner? Would you plan out all your tests, write all your tests, andthen write the implementation, or would you still take an incrementalapproach to the test and production code?
I would still take an incremental approach. The distinction is that I'm not letting the needs of the client's usage drive the design. Instead, I'm expressing the requirements of the algorithm in tests.
In your example, I would likely start with the 0-character, 1-character, and 2-character cases, as you mentioned. When I got to the 3-character case, I would implement it using the design I had in mind (the recursive algorithm) rather than trying to tease out the design as forced by the tests.
I'm not in George's mind, but I've actually thought about something
similar often. Often when confronted with a problem like this one an
algorithm pops to my mind. Were I not TDDing, I would just go ahead
and write it. But, because I want the tests to drive my design I start
implementing one test at a time, trying to ignore the way I've already
envisioned and see if the tests are telling me I should use a
different way to solve the problem. Sometimes I do get a better
realization, and sometimes the tests just nudge me towards the same
thing I had in mind from the first place (maybe because I get
developer-myopia once I think of a solution).
I guess the question is "does what I have in mind relate to the external
view of this bit of code or the internal view?" For this particular
problem, working only from the external view might take some steps
bigger than I want, so I might work from an internal view--knowing the
algorithm I want.
In less algorithmic cases, I often (now) don't think too much about the
implementation until I've written the test asking for the behavior.
Does that make more sense? I've not found a good way to describe this.
I guess the question is "does what I have in mind relate to the external view of this bit of code or the internal view?" For this particular problem, working only from the external view might take some steps bigger than I want, so I might work from an internal view--knowing the algorithm I want.
In less algorithmic cases, I often (now) don't think too much about the implementation until I've written the test asking for the behavior.
Does that make more sense? I've not found a good way to describe this.
Hi, Everybody,
I’m not clear on the difference between test-first and test-driven here. Sorry if this has already been covered earlier… I just started reading this list.
Thanks,
Kay Pentecost