< Summary

Information
Class: ValidateLib.TabularData.Datatypes.NumericDatatypes.DecimalDT
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\NumericDatatypes\DecimalDT.cs
Line coverage
73%
Covered lines: 19
Uncovered lines: 7
Coverable lines: 26
Total lines: 53
Line coverage: 73%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBlocks covered Blocks not covered
DecimalDT()20
DecimalDT(...)70
DecimalDT(...)100
CheckLexicalSpace()142
CompareTo(...)09

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\NumericDatatypes\DecimalDT.cs

#LineLine coverage
 1using ExtendedNumerics;
 2using System.Text.RegularExpressions;
 3using ValidateLib.ErrorsAndWarnings.Errors;
 4using ValidateLib.Metadata.Descriptors;
 5
 6namespace ValidateLib.TabularData.Datatypes.NumericDatatypes
 7{
 8    public class DecimalDT : NumericBaseDT
 9    {
 110        public DecimalDT() { }
 111        public DecimalDT(string stringValue) : base(stringValue)
 12        {
 113            CheckLexicalSpace();
 114            Value = BigDecimal.Parse(this.stringValue);
 115            ResolvePercentPermileExponent();
 116        }
 17
 118        public DecimalDT(string stringValue, FormatDescriptor format) : base(stringValue, format)
 19        {
 20            //Contains Exponent
 121            if (Exponent != 1)
 122                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 23            // Contains special type NaN....
 124            if (SpecialType != SpecialTypes.Normal)
 125                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 126        }
 27
 28
 29
 30        void CheckLexicalSpace()
 31        {
 32
 133            string pattern = @"^(\+|-)?([0-9]+(\.[0-9]*)?|\.[0-9]+)$";
 134            if (!Regex.IsMatch(stringValue, pattern))
 135                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 136            if (Exponent != 1)
 137                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 138            if (SpecialType != SpecialTypes.Normal)
 039                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 140        }
 41
 42        override public int CompareTo(BaseDT? other)
 43        {
 044            if (other is null)
 045                return 1;
 046            if (other is not DecimalDT)
 047                throw new ArgumentException();
 048            var typedOther = (DecimalDT)other;
 049            return Value.CompareTo(typedOther.Value);
 50
 51        }
 52    }
 53}