< Summary

Information
Class: ValidateLib.TabularData.Datatypes.NumericDatatypes.FloatDT
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\NumericDatatypes\FloatDT.cs
Line coverage
69%
Covered lines: 27
Uncovered lines: 12
Coverable lines: 39
Total lines: 80
Line coverage: 69.2%
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
FloatDT()20
FloatDT(...)121
FloatDT(...)011
HandleSpecialCases(...)160
CompareTo(...)63

File(s)

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

#LineLine coverage
 1using System.Globalization;
 2using ValidateLib.ErrorsAndWarnings.Errors;
 3using ValidateLib.Metadata.Descriptors;
 4
 5namespace ValidateLib.TabularData.Datatypes.NumericDatatypes
 6{
 7    public class FloatDT : FloatBaseDT
 8    {
 19        protected override string pattern { get; set; } =
 110            @"^(?:\+|-)?(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:[Ee](?:\+|-)?[0-9]+)?|(?:\+|-)?INF|NaN$";
 111        new public float Value { get; set; }
 12
 113        public FloatDT() { }
 114        public FloatDT(string strValue) : base(strValue)
 15        {
 116            CheckLexicalSpace(strValue);
 17            try
 18            {
 119                if (HandleSpecialCases(strValue))
 120                    Value = float.Parse(stringValue, CultureInfo.InvariantCulture);
 121                ResolvePercentPermileExponent();
 122            }
 123            catch (Exception)
 24            {
 125                ErrorFactory.ThrowDatatypeValidationError(strValue);
 026            }
 127        }
 28
 029        public FloatDT(string strValue, FormatDescriptor format) : base(strValue, format)
 30        {
 031            HandleSpecialCases(strValue);
 32            try
 33            {
 34                checked
 35                {
 036                    Value = (float)base.Value;
 037                    ResolvePercentPermileExponent();
 38                }
 039            }
 040            catch (Exception)
 41            {
 042                ErrorFactory.ThrowDatatypeValidationError(strValue);
 043            }
 44
 045        }
 46
 47
 48        protected bool HandleSpecialCases(string strValue)
 49        {
 150            if (stringValue == "NaN")
 51            {
 152                Value = float.NaN;
 153                return false;
 54            }
 155            if (stringValue == "-INF")
 56            {
 157                Value = float.NegativeInfinity;
 158                return false;
 59            }
 160            if (stringValue == "INF")
 61            {
 162                Value = float.PositiveInfinity;
 163                return false;
 64            }
 165            return true;
 66        }
 67
 68
 69        override public int CompareTo(BaseDT? other)
 70        {
 171            if (other is null)
 072                return 1;
 173            if (other is not FloatDT)
 074                throw new ArgumentException();
 175            var typedOther = (FloatDT)other;
 176            return Value.CompareTo(typedOther.Value);
 77
 78        }
 79    }
 80}