< Summary

Information
Class: ValidateLib.TabularData.Datatypes.BooleanDT
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\TabularData\Datatypes\BooleanDT.cs
Line coverage
89%
Covered lines: 26
Uncovered lines: 3
Coverable lines: 29
Total lines: 57
Line coverage: 89.6%
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
BooleanDT()20
BooleanDT(...)101
BooleanDT(...)143
IsPatternValid(...)50

File(s)

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

#LineLine coverage
 1using ValidateLib.ErrorsAndWarnings.Errors;
 2using ValidateLib.Metadata.Descriptors;
 3
 4namespace ValidateLib.TabularData.Datatypes
 5{
 6    public class BooleanDT : BaseDT
 7    {
 18        bool Value { get; set; }
 19        string[] trueValues = new string[] { "true", "1" };
 110        string[] falseValues = new string[] { "false", "0" };
 111        public BooleanDT() { }
 112        public BooleanDT(string stringValue) : base(stringValue)
 13        {
 114            if (trueValues.Contains(stringValue)) Value = true;
 115            else if (falseValues.Contains(stringValue)) Value = false;
 116            else ErrorFactory.ThrowDatatypeValidationError(stringValue);
 17
 018        }
 19
 120        public BooleanDT(string stringValue, FormatDescriptor descriptor) : base(stringValue, descriptor)
 21        {
 22            //never null here
 123            string formatPattern = descriptor.pattern!;
 124            string[] formatParts = formatPattern.Split('|');
 125            string? trueVal = null;
 126            string? falseVal = null;
 127            if (formatParts.Length == 2)
 28            {
 129                trueVal = formatParts[0];
 130                falseVal = formatParts[1];
 31            }
 32            else
 33            {
 034                ErrorFactory.ThrowInvalidFormatError(descriptor.pattern);
 35            }
 36
 137            if (stringValue == trueVal)
 138                Value = true;
 139            else if (stringValue == falseVal)
 140                Value = false;
 41            else
 142                ErrorFactory.ThrowDatatypeValidationError(stringValue);
 043        }
 44
 45
 46        public override bool IsPatternValid(FormatDescriptor format)
 47        {
 148            string formatPattern = format.pattern!;
 149            string[] formatParts = formatPattern.Split('|');
 150            if (formatParts.Length != 2)
 151                return false;
 152            return true;
 53        }
 54
 55
 56    }
 57}