Best NBi code snippet using NBi.Core.Scalar.Comparer.NumericToleranceFactory
NumericComparer.cs
Source:NumericComparer.cs
...13 caster = new NumericCaster();14 }15 public ComparerResult Compare(object x, object y, string tolerance)16 {17 return base.Compare(x, y, new NumericToleranceFactory().Instantiate(tolerance));18 }19 20 internal ComparerResult Compare(object x, object y, decimal tolerance, SideTolerance side)21 {22 return base.Compare(x, y, new NumericAbsoluteTolerance(tolerance, side));23 }24 protected override ComparerResult CompareObjects(object x, object y)25 {26 var builder = new NumericIntervalBuilder(x);27 builder.Build();28 if (builder.IsValid())29 return CompareDecimals30 (31 builder.GetInterval()...
NumericToleranceFactoryTest.cs
Source:NumericToleranceFactoryTest.cs
...6using System.Text;7using System.Threading.Tasks;8namespace NBi.Testing.Core.Scalar.Comparer9{10 public class NumericToleranceFactoryTest11 {12 [Test]13 public void Instantiate_Absolute_Value()14 {15 var value = "50000";16 var tolerance = new NumericToleranceFactory().Instantiate(value);17 Assert.That(tolerance, Is.TypeOf<NumericAbsoluteTolerance>());18 Assert.That(tolerance.Value, Is.EqualTo(50000));19 Assert.That(tolerance.ValueString, Is.EqualTo("50000"));20 }21 [Test]22 public void Instantiate_AbsoluteWithDecimalSeparator_Value()23 {24 var value = "50.250";25 var tolerance = new NumericToleranceFactory().Instantiate(value);26 Assert.That(tolerance, Is.TypeOf<NumericAbsoluteTolerance>());27 Assert.That(tolerance.Value, Is.EqualTo(50.25));28 Assert.That(tolerance.ValueString, Is.EqualTo("50.250"));29 }30 [Test]31 public void Instantiate_Percentage_Value()32 {33 var value = "50%";34 var tolerance = new NumericToleranceFactory().Instantiate(value);35 Assert.That(tolerance, Is.TypeOf<NumericPercentageTolerance>());36 Assert.That(tolerance.Value, Is.EqualTo(0.5));37 Assert.That(tolerance.ValueString, Is.EqualTo("50.0%"));38 }39 [Test]40 public void Instantiate_BoundedPercentage_Value()41 {42 var value = "50% (min 0.001)";43 var tolerance = new NumericToleranceFactory().Instantiate(value);44 Assert.That(tolerance, Is.TypeOf<NumericBoundedPercentageTolerance>());45 var boundedTolerance = tolerance as NumericBoundedPercentageTolerance;46 Assert.That(boundedTolerance.Value, Is.EqualTo(0.5));47 Assert.That(boundedTolerance.Min, Is.EqualTo(0.001));48 Assert.That(boundedTolerance.Max, Is.EqualTo(0));49 Assert.That(boundedTolerance.ValueString, Is.EqualTo("50.0% (min: 0.001)"));50 }51 [Test]52 public void Instantiate_BoundedPercentageWithSpaceAndWithoutBrackets_Value()53 {54 var value = " 50 % min:0.001 ";55 var tolerance = new NumericToleranceFactory().Instantiate(value);56 Assert.That(tolerance, Is.TypeOf<NumericBoundedPercentageTolerance>());57 var boundedTolerance = tolerance as NumericBoundedPercentageTolerance;58 Assert.That(boundedTolerance.Value, Is.EqualTo(0.5));59 Assert.That(boundedTolerance.Min, Is.EqualTo(0.001));60 Assert.That(boundedTolerance.Max, Is.EqualTo(0));61 Assert.That(boundedTolerance.ValueString, Is.EqualTo("50.0% (min: 0.001)"));62 }63 [Test]64 public void Instantiate_BoundedPercentageWithEqual_Value()65 {66 var value = "10%(max=125) ";67 var tolerance = new NumericToleranceFactory().Instantiate(value);68 Assert.That(tolerance, Is.TypeOf<NumericBoundedPercentageTolerance>());69 var boundedTolerance = tolerance as NumericBoundedPercentageTolerance;70 Assert.That(boundedTolerance.Value, Is.EqualTo(0.1));71 Assert.That(boundedTolerance.Min, Is.EqualTo(0));72 Assert.That(boundedTolerance.Max, Is.EqualTo(125));73 Assert.That(boundedTolerance.ValueString, Is.EqualTo("10.0% (max: 125)"));74 }75 [Test]76 public void Instantiate_OneSidedMore_Value()77 {78 var value = " + 50%";79 var tolerance = new NumericToleranceFactory().Instantiate(value);80 Assert.That(tolerance, Is.TypeOf<NumericPercentageTolerance>());81 var boundedTolerance = tolerance as NumericPercentageTolerance;82 Assert.That(boundedTolerance.Value, Is.EqualTo(0.5));83 Assert.That(boundedTolerance.ValueString, Is.EqualTo("+50.0%"));84 }85 [Test]86 public void Instantiate_OneSidedLess_Value()87 {88 var value = "-16.25";89 var tolerance = new NumericToleranceFactory().Instantiate(value);90 Assert.That(tolerance, Is.TypeOf<NumericAbsoluteTolerance>());91 var boundedTolerance = tolerance as NumericAbsoluteTolerance;92 Assert.That(boundedTolerance.Value, Is.EqualTo(16.25));93 Assert.That(boundedTolerance.ValueString, Is.EqualTo("-16.25"));94 }95 }96}...
ToleranceFactory.cs
Source:ToleranceFactory.cs
...24 case ColumnType.Text:25 tolerance = new TextToleranceFactory().Instantiate(value);26 break;27 case ColumnType.Numeric:28 tolerance = new NumericToleranceFactory().Instantiate(value);29 break;30 case ColumnType.DateTime:31 tolerance = new DateTimeToleranceFactory().Instantiate(value);32 break;33 case ColumnType.Boolean:34 break;35 default:36 break;37 }38 return tolerance;39 }40 41 public static Tolerance None(ColumnType type)42 {...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!