| | 1 | | using ValidateLib.ErrorsAndWarnings.Errors.Specific; |
| | 2 | | using ValidateLib.Metadata.Descriptors; |
| | 3 | | using ValidateLib.TabularData.Datatypes.NumericDatatypes; |
| | 4 | |
|
| | 5 | | namespace DatatypeTests |
| | 6 | | { |
| | 7 | | public class DecimalTests |
| | 8 | | { |
| | 9 | |
|
| | 10 | |
|
| | 11 | | [Theory] |
| | 12 | | [InlineData("3.0")] |
| | 13 | | [InlineData("-3.0")] |
| | 14 | | [InlineData("+3.5")] |
| | 15 | | [InlineData("3")] |
| | 16 | | [InlineData(".3")] |
| | 17 | | [InlineData("3.")] |
| | 18 | | [InlineData("0")] |
| | 19 | | [InlineData("-.3")] |
| | 20 | | [InlineData("0003.0")] |
| | 21 | | [InlineData("3.0000")] |
| | 22 | | public void ValidDecimalnWithoutPatternTest(string stringValue) |
| 1 | 23 | | { |
| 1 | 24 | | DecimalDT dec = new DecimalDT(stringValue); |
| 1 | 25 | | } |
| | 26 | |
|
| | 27 | | [Theory] |
| | 28 | | [InlineData("not a decimal")] |
| | 29 | | [InlineData("3,5")] |
| | 30 | | [InlineData("")] |
| | 31 | |
|
| | 32 | | public void DecimalWithoutPatternInvalidValues(string stringValue) |
| 1 | 33 | | { |
| 1 | 34 | | Assert.Throws<DatatypeValidationError>(() => new DecimalDT(stringValue)); |
| 1 | 35 | | } |
| | 36 | | [Theory] |
| | 37 | | [InlineData("+10", ",", ".")] |
| | 38 | | [InlineData("+10,000,000", ",", ".")] |
| | 39 | | [InlineData("+10.5", ",", ".")] |
| | 40 | | [InlineData("-10%", ",", ".")] |
| | 41 | | [InlineData("-10‰", ",", ".")] |
| | 42 | |
|
| | 43 | | [InlineData("+10", null, ".")] |
| | 44 | | [InlineData("+10.5", null, ".")] |
| | 45 | | [InlineData("-10%", null, ".")] |
| | 46 | | [InlineData("-10‰", null, ".")] |
| | 47 | |
|
| | 48 | | public void DecimalWithFormatWithoutPatternValidValues(string stringValue,string? groupChar,string? decimalChar) |
| 1 | 49 | | { |
| 1 | 50 | | FormatDescriptor format = new FormatDescriptor |
| 1 | 51 | | { |
| 1 | 52 | | groupChar = groupChar, |
| 1 | 53 | | decimalChar = decimalChar, |
| 1 | 54 | | }; |
| | 55 | |
|
| 1 | 56 | | var decimaldt = new DecimalDT(stringValue, format); |
| 1 | 57 | | } |
| | 58 | |
|
| | 59 | | [Theory] |
| | 60 | | [InlineData("not decimal", ",", ".")] |
| | 61 | | [InlineData("+10,000,000E4", ",", ".")] |
| | 62 | | [InlineData("+10.5E-3", ",", ".")] |
| | 63 | | [InlineData("-10%E+4", ",", ".")] |
| | 64 | | [InlineData("10,,00", ",", ".")] |
| | 65 | |
|
| | 66 | | [InlineData("not decimal", null, ".")] |
| | 67 | | [InlineData("+10.5E6", null, ".")] |
| | 68 | | [InlineData("-10E+6", null, ".")] |
| | 69 | | [InlineData("-10E-6", null, ".")] |
| | 70 | |
|
| | 71 | | [InlineData("NaN", null, ".")] |
| | 72 | | [InlineData("INF", null, ".")] |
| | 73 | | [InlineData("-INF", null, ".")] |
| | 74 | |
|
| | 75 | |
|
| | 76 | | public void DecimalWithFormatWithoutPatternInValidValues(string stringValue, string? groupChar, string? decimalC |
| 1 | 77 | | { |
| 1 | 78 | | FormatDescriptor format = new FormatDescriptor |
| 1 | 79 | | { |
| 1 | 80 | | groupChar = groupChar, |
| 1 | 81 | | decimalChar = decimalChar, |
| 1 | 82 | | }; |
| | 83 | |
|
| 1 | 84 | | Assert.Throws<DatatypeValidationError>(()=> new DecimalDT(stringValue, format)); |
| 1 | 85 | | } |
| | 86 | |
|
| | 87 | | } |
| | 88 | | } |