< Summary

Information
Class: ValidateLib.TabularData.Datatypes.NumericDatatypes.DoubleDT
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\NumericDatatypes\DoubleDT.cs
Line coverage
74%
Covered lines: 29
Uncovered lines: 10
Coverable lines: 39
Total lines: 77
Line coverage: 74.3%
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
DoubleDT()20
DoubleDT(...)111
DoubleDT(...)112
HandleSpecialCases(...)160
CompareTo(...)09

File(s)

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

#LineLine coverage
 1using System.Globalization;
 2using ValidateLib.ErrorsAndWarnings.Errors;
 3using ValidateLib.Metadata.Descriptors;
 4
 5namespace ValidateLib.TabularData.Datatypes.NumericDatatypes
 6{
 7    public class DoubleDT : FloatBaseDT
 8    {
 19        protected override string pattern { get; set; } =
 110            @"^(?:\+|-)?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[Ee](?:\+|-)?[0-9]+)?|(?:\+|-)?INF|NaN$";
 111        new public double Value { get; set; }
 112        public DoubleDT() { }
 113        public DoubleDT(string stringValue) : base(stringValue)
 14        {
 115            CheckLexicalSpace(stringValue);
 16            try
 17            {
 118                if (HandleSpecialCases(stringValue))
 119                    Value = double.Parse(stringValue, CultureInfo.InvariantCulture);
 120                ResolvePercentPermileExponent();
 121            }
 122            catch (Exception)
 23            {
 124                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 025            }
 126        }
 127        public DoubleDT(string strValue, FormatDescriptor format) : base(strValue, format)
 28        {
 129            if (HandleSpecialCases(strValue))
 30            {
 31                try
 32                {
 33                    checked
 34                    {
 135                        Value = double.Parse(base.Value.ToString(), CultureInfo.InvariantCulture);
 136                        ResolvePercentPermileExponent();
 37                    }
 138                }
 039                catch (Exception)
 40                {
 041                    ErrorFactory.ThrowDatatypeValidationError(strValue);
 042                }
 43            }
 144        }
 45
 46        protected bool HandleSpecialCases(string strValue)
 47        {
 148            if (stringValue == "NaN")
 49            {
 150                Value = double.NaN;
 151                return false;
 52            }
 153            if (stringValue == "-INF")
 54            {
 155                Value = double.NegativeInfinity;
 156                return false;
 57            }
 158            if (stringValue == "INF")
 59            {
 160                Value = double.PositiveInfinity;
 161                return false;
 62            }
 163            return true;
 64        }
 65
 66        override public int CompareTo(BaseDT? other)
 67        {
 068            if (other is null)
 069                return 1;
 070            if (other is not DoubleDT)
 071                throw new ArgumentException();
 072            var typedOther = (DoubleDT)other;
 073            return Value.CompareTo(typedOther.Value);
 74
 75        }
 76    }
 77}