Re: Converting Numbers to Words in English by recursion.



On Sat, 10 Mar 2007 02:07:39 -0600, Richard Heathfield wrote
(in article <dqadnTh4WpCZ-m_YnZ2dnUVZ8vmdnZ2d@xxxxxx>):

Phlip said:

jedale wrote

I am trying to convert numbers to there corresponding words but it
only works for numbers under 1,000 but need it to work for 1 billion.

Where are your unit tests?

I would use C++,

Well, that's up to you. :-) Not everyone shares your enthusiasm for
that language.

and would start like this:

assert("zero" == convert(0));

Then I would write convert like this:

string
convert(int x)
{
return "0";
}

Then I would assert for "one" == convert(1), and change the code to
say if(x == 1) return "one".

That sounds silly,

Yes, it does.

but it isn't.

Yes, it is.

That's because the end-game of any form of zealotry is silliness.

At the time you have 2, you should
refactor the convert function into a little lookup table.

A lookup table is an inadequate solution here. Why bother to code an
inadequate solution? And you've completely ignored the spec, too.

It's okay as long as you have unit tests, apparently.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw





.



Relevant Pages

  • Re: Converting Numbers to Words in English by recursion.
    ... Phlip said: ... Where are your unit tests? ... A lookup table is an inadequate solution here. ...
    (comp.programming)
  • Re: The design is the code?
    ... >>I dont use unit tests either. ... >>i've checked that the design implements the spec and that the spec ... >>the code does what the design asks for. ... With a large code base, ...
    (comp.object)
  • Re: Ruby Specifications
    ... A spec would be good from a "business" sense. ... > Subject: Re: Ruby Specifications ... Use the same unit tests to ... >> standardised Verilog specification. ...
    (comp.lang.ruby)
  • Properly using Rake::TestTask
    ... I have a Rakefile that I am using to create and upload a gem. ... I am having a problem with Rake::TestTask not aborting the ... How do I make my unit tests abort the gem creation? ...
    (comp.lang.ruby)