I wanted to train making test cases, so I'm gonna try them on something easy.
Take any given (string) input (within visible ASCII range) and deduce if it's a number and output something that could be used to evaluate.
- A number will only contain the characters
- Answers are only required to recognise numbers between -1000000000 and 1000000000 (exclusive), but may recognise arbitrarily large numbers.
- You can write a full program or a function.
- If a number, return anything that could be used to discern it and document the output in the description (ex.
My program outputs T if a number, F if not.).
- Input will be any amount of characters within ASCII range or empty (if empty return whatever you'd output if not a number).
- Numbers could include a decimal point (ex.
3.14). If they do, they must have at least one digit before the decimal point and at least one after it.
- Numbers could have leading or trailing zeros (ex.
- The integer part of a number could be divided for readability into chunks of three digits with commas (ex.
1,000.23456). In this case they must be divided every three digits from right to left (ex.
- Negatives numbers are indicated by a leading
-1.23). A leading
+to indicate a positive number is not permitted, and should result in the falsy output.
- Exceptions are NOT counted as valid and discernible output (except when they can pass outputs to standard out stream (ex.
Exception on line N [...]can be put in as output for a number/nonnumber if the string is put to standard out stream.
My program outputs T if a number, F if not. version)
123 -> T [on integer] -123 -> T [negative numbers need to be handled] 0 -> T [on zero] 123.456 -> T [on floating point] 123,456.789 -> T [on evenly divided by 3 digits with comas] 123456789 -> T [thousand separators are not required] 0000001.00000 -> T [on leading/trailing zeros] 00.00 -> T [on zero and leading/trailing zeros] 999999999.9999999999999999999999999999999999999999999999999999 -> T [on close to the maximum value] -999999999.9999999999999999999999999999999999999999999999999999 -> T [on close to the minimum value] -> F [on empty] lolz -> F [on non-number value] n4melyh4xor -> F [on non-number with digits] 1.2 -> F [on space-padded] 9.3 1.3 -> F [on anyhow separated multiple numbers] 1e5 -> F [no scientific notation] 50cl05e.buty3ts0f4r -> F [on input with letters obscuring the number] 1,2,3,4.5678 -> F [on badly readability-divided number] 1,234.5,678 -> F [on readability-divided floating point part] .234 -> F [on no leading zero] +1 -> F [no leading + sign] 1.234.3 -> F [only one decimal point] 12345,678 -> F [on separator stopping mid-way]
code-golf, least characters is the winner.