Test cases for numeric input - testing

What are some common (or worthwhile) tests, test questions, weaknesses, or misunderstandings dealing with numeric inputs?
This is a community wiki. Please add to it.
For example, here are a couple sample ideas:
I commonly see users enter text into number fields (eg, ">4" or "4 days", etc).
Fields left blank (null)
Very long numeric strings
Multiple decimals and commas (eg, "4..4" and "4,,434.4.4")
Boundary Value Analysis:
Lower Boundary
Lower Boundary - 1 (for decimal/float, use smaller amounts)
Upper Boundary
Upper Boundary + 1
Far below the lower boundary (eg, beyond the hardware boundary value)
Far above the upper boundary
middle of the range
0
0.0
White space, nothing else " "
String input & other incorrect data types.
Number with text in front or back, eg "$5.00", "4 lbs", "about 60", "50+"
Negative numbers
+ sign with positive numbers, "+4"
Both plus and minus sign, eg "+-4" and "-4e+30"
Exponents of 10, both uppercase and lowercase, positive and negative eg "4e10", "-5E-10", "+6e+60", etc
Too many "e" characters, eg "4e4e4" "4EE4"
Impossibly large/small exponents or inappropriate ones
Decimal values that cannot be represented in a computer
eg, .3 + .6 == 1.0? This bug affects most hardware, so outputs that compare decimal values should allow for a degree of error.
Integer/hardware overflow. Eg, for 32-bit integers, what happens when adding 4 billion to 4 billion?
wrong use of decimal sign and thousands seperator ("," vs. ".") (MikeD)
internationalisation i18n issues: In english aplications you write "12,345.67" meaning "12345.67" in german you write "12345,67" – (k3b)
leading 0's don't make number octal (common javascript bug)

Related

How to print a number with number of fixed characters in Smalltalk/Pharo

Actual task: I want to print the matrix (of my own implementation) in humanly readable format. As a pre-requisite, I figured I need to be able to specify "fit the number representation into X characters". I found #printShowingDecimalPlaces: and #printPaddedWith:to: in Float and Integer classes (the first method is in more general Number class). Individually, they work, but the former works on fractional part only and the the latter on part before fractional, e.g.:
10.3 printPaddedWith: Character space to: 5.
"' 10.3'"
-10.3 printPaddedWith: Character space to: 5.
"' -10.3'"
10.3 printShowingDecimalPlaces: 3.
"'10.300'"
Also, their action on very large (or equally small numbers) in scientific form is not ideal:
12.3e9 printShowingDecimalPlaces: 3.
"'12300000000.000'"
12.3e9 printPaddedWith: Character space to: 5.
"' 1.23e10'"
So, I would like something like Common Lisp's (FORMAT T "~10g" 12.3d9) or C's printf("%10g", 12.3e9), that (a) restricts the whole width to 10 characters and (b) chooses the most suitable format depending on the size of the number. Is there something like this in Pharo?
For versatile printing options, I suggest loading NumberPrinter package from
http://ss3.gemstone.com/ss/NumberPrinter/
(FloatPrinter fixed) digitCount: 2; print: 10.3.
-> '10.30'
I did not try it in recent Pharo versions though.
EDIT:
Ah, but I see no format for handling exponents multiple of 3, maybe you would have to create a subclass for such format.
EDIT:
Or I missunderstood: you don't want it to print as '12.3e9' but rather '1.23e10'? note that apart significand digitCount, you need extra size for at worst 1 for sign + 1 for fraction separator + 1 for exponent letter + 1 for exponent sign + 3 for exponent (worst case for double precision floating point).
The more or less equivalent to g format would be something like this:
(FloatPrinter freeFormat)
totalWidth: 13; "size of the generated string"
digitCount: 6; "number of significant figures"
print: -12.3e-205.
->' -1.23e-204'

Set standard number format with thousand separator, 2 decimals and minus sign for negative numbers using VBA?

I've seen the question asked before on stackoverflow, how to get normal number format with thousand separator and 2 decimals. The answer was to set:
rng.NumberFormat = "##0.00"
But this is incomplete, because, at least on my computer, I don't get any space separator between millions and thousands. So I have changed that to:
rng.NumberFormat = "### ### ##0.00"
But this is again incomplete, because for some reason negative numbers were formatted to look like they have a space between the minus sign and the number. See below:
- 12.4
So, there are some things left to do to arrive at Excels "built-in" "format as number" formats. Additionally the formatting that I apply though VBA is described as Custom by Excel.
Is there any way to set the format to be the standard built in format as number with thousand separators, 2 decimals and minus signs for negative numbers?
I'm looking for something like:
rng.NumberFormat = "Number, 2, minus"
rng.NumberFormat = "# ##0.00:-# ##0.00"
You put the format for positive numbers before : and the format for negative after. You don't need to put hundreds of # signs in the format, just enough to show what the 1000's separator is.

What does "hyphenation vector" mean?

The Hyphen library seems to be a very popular and free way to have hyphenation in your app.
What does hyphenation vector mean?
I am running the example attached to the library source code.
Example output:
hibernate // input word
030412000 // output hyphenation vector
hi=ber=nate // hyphen points
- hi=bernate
- hiber=nate
Odd numbers in the vector indicate hyphenation points. But what do all of those values mean?
László Németh describes the algorithm in OpenOffice's documentation in full detail.
The library uses the algorithm developed by Frank M. Liang ("Word Hy-phen-a-tion by Com-pu-ter"): all letters in digrams, trigrams, and longer patterns are assigned numerical values to indicate it's a 'usual' place (an odd number) or an 'unusual' place (an even number) for a hyphen to occur. The higher the number is, the greater importance -- a pattern will almost never be broken on a larger even number, and almost always on a larger odd number. The number sequences are statistically determined on a corpus of pre-hyphenated words.
Note that the numbers are for positions between two characters. A better notation would have been
h i b e r n a t e
0 3 0 4 1 2 0 0 (0)
(where the last 0 is obsolete).

What do these curly braces mean?

I am working through a rails tutorial, and came across this line rails g model product name decimal:{7, 2}.
What do those curly braces at the end mean? What do they do?
Originally, I thought they force a level of precision with floating point numbers, but that proved to be false. I could make a decimal 10 digits long with a decimal going to the thousandths place.
Please see for example:
- http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html
There it says:
For clarity’s sake: the precision is the number of significant digits,
while the scale is the number of digits that can be stored following
the decimal point. For example, the number 123.45 has a precision of 5
and a scale of 2. A decimal with a precision of 5 and a scale of 2 can
range from -999.99 to 999.99.
It's the decimal field's precision (total number of digits) and scale (digits after the decimal point).
From rails g model -h:
For decimal two integers separated by a comma in curly braces will be used
for precision and scale:
`rails generate model product price:decimal{10,2}`
From MySQL docs:
The declaration syntax for a DECIMAL column is DECIMAL(M,D). The
ranges of values for the arguments in MySQL 5.1 are as follows:
M is the maximum number of digits (the precision). It has a range of 1
to 65. (Older versions of MySQL permitted a range of 1 to 254.)
D is the number of digits to the right of the decimal point (the
scale). It has a range of 0 to 30 and must be no larger than M.

Correct termiology for documentation [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
The documentation below is for a module, which has now been "decommissioned"
and I'm writing it's replacement.
Before i write the replacement I want to get my terms right.
I know the terms are wrong in the documentation - it was hacked together quickly
so i could instruct a college working on the hardware side of this project on how to use a program I'ld made.
Full documentary can be found here for any who are interested (in so much as has been written and added to our wiki), the Website may only be available to certain IPS's (depends on you ISP - university internet connections are most likely to work), and the SVN repo is private.
So there are alot of terms that are wrong.
such as.
deliminators
formatted string containing value expressions (might now be wrong but is hard to say)
What are the correct terms for these.
And what other mistakes have I made
==== formatted string containing value expressions ====
Before I start on actual programs an explanation of:
"formatted string containing value expressions" and how to encode values in them.
The ''formatted string containing value expressions'' is at the core of doing low level transmission.
We know the decimal 65, hex 41, binary 0100 0001, and the ascii character 'A' all have the same binary representation, so to tell which we are using we have a series of deliminators - numbers preceded by:
# are decimal
$ are Hex
# are binary
No deliminator, then ascii.
Putting a sign indicator after the deliminator is optional. It is required if you want to send a negative number.
You may put muliple values in the same string.
eg: "a#21#1001111$-0F"
All values in a ''formatted string containing value expressions'' must be in the range -128 to 255 (inclusive) as they must fit in 8bytes (other values will cause an error). Negative numbers have the compliment of 2 representation for their binary form.
There are some problems with ascii - characters that can't be sent (in future versions this will be fixed by giving ascii a delineator and some more code to make that deliminator work, I think).
Characters that can't be sent:
* The delineator characters: $##
* Numbers written immediately after a value that could have contained those digits:
* 0,1,2,3,4,5,6,7,8,9 for decimal
* 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,A,B,C,D,E,F for hex
* 0,1 for binary
For a start, deliminator would probably be delimiter, although I notice your text has both delineator and deliminator in it - perhaps deliminator is a special delimiter/terminator combination :-)
However, a delimiter is usually used to separate fields and is usually present no matter what. What you have is an optional prefix which dictates the following field type. So I would probably call that a "prefix" or "type prefix" instead.
The "formatted string containing value expressions" I would just call a "value expression string" or "value string" to change it to a shorter form.
One other possible problem:
must be in the range -128 to 255 (inclusive) as they must fit in 8bytes
I think you mean 8 bits.
Try something like the following:
==== Value string encoding ====
The value string is at the core of the data used for low level
transmissions.
Within the value string the following refixes are used:
# decimal
$ Hex
# binary
No prefix - ASCII.
An optional sign may be included after the delimiter for negative numbers.
Negative numbers are represented using twos complement.
The value string may contain multiple values:
eg: "a#21#1001111$-0F"
All elements of the value string must represent an 8bit value and must
be in the range -128 to 255
When using ASCII representation the following characters that can't be sent
* The delineator characters: $## (use prefixed hex value.)
* Numbers written immediately after a value that could have
contained those digits:
* 0,1,2,3,4,5,6,7,8,9 for decimal
* 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,A,B,C,D,E,F for hex
* 0,1 for binary