LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > astrogeek
User Name
Password

Notices


Rate this Entry

Test Cases: Optional AND Input and Output Handling

Posted 10-10-2021 at 11:52 PM by astrogeek
Updated 10-11-2021 at 12:10 AM by astrogeek

This post is part of the Alphanumeric Calculator program group.

Test cases to validate handling of optional "and" in english numeric expressions.

Use of "and" in input stream is always optional. For example, either of these basic forms is allowed:

Code:
one thousand one hundred one
one thousand one hundred and one
By default output follows input usage per expression - if "and" appears in the input stream then the output stream will also include "and" as appropriate.

The user may also enable/disable "and" in the output stream for all expressions by typing "and" as the only word on an input line.

Test cases input file:

Code:
cat tests_optand
/* Test optional "and" input and output handling.
   The "specification" is what sounds right to myself and others who have commented, but in the absence of any
   linguistic definition, "how it works" should be taken as the actual spec - feel free to add your own rules!
   Note: Output handling is slightly more strict than input handling, so that some
   output usage may differ from input usage - but all output strings are valid when used as input.
*/
######## Output follows input usage - 1 is No input AND, 2 is input stream AND
one hundred three thousand one hundred three
one hundred and three thousand one hundred three
######## Toggle default output AND state with same input
one million one hundred twenty one thousand three
and
one million one hundred twenty one thousand three
and
one million one hundred twenty one thousand three
######## Single digit tail with successive left-most multipliers
and
one
twenty one
one hundred one
one thousand one
one million one
one billion one
######## Double digit tail with successive left-most multipliers
eleven
twenty one
one hundred twenty one
one thousand twenty one
one million twenty one
one billion twenty one
######## Single digit term in successive left-most multipliers
one hundred one
one hundred one thousand
one hundred one million
one hundred one billion
######## Double digit term in successive left-most multipliers
one hundred twenty one
one hundred twenty one thousand
one hundred twenty one million
one hundred twenty one billion
######## Cumulative multiplier terms
one hundred billion one hundred million one hundred thousand one hundred
one hundred one billion one hundred one million one hundred one thousand one hundred one
######## Invalid use of AND in input stream
one hundred and zero
one thousand and one hundred
one thousand and one hundred and one
one thousand one hundred and zero
one million and one thousand and one hundred
And the results using Rev.3 lexer/parser as posted to this blog.

Code:
./alphacalc tests_optand -c
######## Output follows input usage - 1 is No input AND, 2 is input stream AND
one hundred three thousand one hundred three
one hundred and three thousand one hundred and three
######## Toggle default output AND state with same input
one million one hundred twenty one thousand three
one million one hundred and twenty one thousand and three
one million one hundred twenty one thousand three
######## Single digit tail with successive left-most multipliers
one
twenty one
one hundred and one
one thousand and one
one million and one
one billion and one
######## Double digit tail with successive left-most multipliers
eleven
twenty one
one hundred and twenty one
one thousand and twenty one
one million and twenty one
one billion and twenty one
######## Single digit term in successive left-most multipliers
one hundred and one
one hundred and one thousand
one hundred and one million
one hundred and one billion
######## Double digit term in successive left-most multipliers
one hundred and twenty one
one hundred and twenty one thousand
one hundred and twenty one million
one hundred and twenty one billion
######## Cuumulative multiplier terms
one hundred billion one hundred million one hundred thousand one hundred
one hundred and one billion one hundred and one million one hundred and one thousand one hundred and one
######## Invalid use of AND in input stream
tests_optand:45.17-45.20: error: syntax error
tests_optand:46.22-46.28: error: syntax error
tests_optand:47.22-47.28: error: syntax error
tests_optand:48.30-48.33: error: syntax error
tests_optand:49.38-49.44: error: syntax error
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 06:06 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration