Best NBi code snippet using NBi.Core.Scalar.Comparer.CellComparer.Compare
Evaluator.cs
Source:Evaluator.cs
...3using System.Data;4using System.Diagnostics;5using System.Globalization;6using System.Linq;7using NBi.Core.Scalar.Comparer;8using System.Text;9using NBi.Core.Scalar.Casting;10using NBi.Core.ResultSet.Analyzer;11using System.Collections.ObjectModel;12using NBi.Core.ResultSet.Equivalence;13namespace NBi.Core.ResultSet.Uniqueness14{15 public abstract class Evaluator16 {17 protected ISettingsResultSet Settings { get; set; }18 private readonly CellComparer cellComparer = new CellComparer();19 protected CellComparer CellComparer20 {21 get { return cellComparer; }22 }23 public Evaluator()24 {25 }26 public Evaluator(ISettingsResultSet settings)27 {28 Settings = settings;29 }30 private readonly Dictionary<KeyCollection, int> dict = new Dictionary<KeyCollection, int>();31 public ResultUniqueRows Execute(object x)32 {33 if (x is DataTable)34 return doCompare((DataTable)x);35 if (x is ResultSet)36 return doCompare(((ResultSet)x).Table);37 throw new ArgumentException();38 }39 protected virtual ResultUniqueRows doCompare(DataTable x)40 {41 var stopWatch = new Stopwatch();42 var columnsCount = x.Columns.Count;43 PreliminaryChecks(x);44 var keyComparer = BuildDataRowsKeyComparer(x);45 stopWatch.Start();46 BuildRowDictionary(x, keyComparer, dict);47 Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceInfo, string.Format("Building dictionary: {0} [{1}]", x.Rows.Count, stopWatch.Elapsed.ToString(@"d\d\.hh\h\:mm\m\:ss\s\ \+fff\m\s")));48 stopWatch.Reset();49 var duplicatedRows = dict.Where(r => r.Value > 1);50 51 return new ResultUniqueRows(52 x.Rows.Count53 , duplicatedRows54 );55 }56 protected abstract void PreliminaryChecks(DataTable x);57 protected abstract DataRowKeysComparer BuildDataRowsKeyComparer(DataTable x);58 59 private void BuildRowDictionary(DataTable dt, DataRowKeysComparer keyComparer, Dictionary<KeyCollection, int> dict)60 {61 dict.Clear();62 foreach (DataRow row in dt.Rows)63 {64 RowHelper hlpr = new RowHelper();65 var keys = keyComparer.GetKeys(row);66 hlpr.Keys = keys;67 //Check that the rows in the reference are unique68 // All the rows should be unique regardless of whether it is the system under test or the result set.69 if (dict.ContainsKey(keys))70 dict[keys]++;71 else72 dict.Add(keys, 1);73 }74 }75 76 protected bool IsNumericField(DataColumn dataColumn)77 {78 return79 dataColumn.DataType == typeof(Byte) ||80 dataColumn.DataType == typeof(Decimal) ||81 dataColumn.DataType == typeof(Double) ||82 dataColumn.DataType == typeof(Int16) ||83 dataColumn.DataType == typeof(Int32) ||84 dataColumn.DataType == typeof(Int64) ||85 dataColumn.DataType == typeof(SByte) ||86 dataColumn.DataType == typeof(Single) ||87 dataColumn.DataType == typeof(UInt16) ||88 dataColumn.DataType == typeof(UInt32) ||89 dataColumn.DataType == typeof(UInt64);90 }91 protected bool IsDateTimeField(DataColumn dataColumn)92 {93 return94 dataColumn.DataType == typeof(DateTime);95 }96 protected void CheckSettingsFirstRowCell(ColumnRole columnRole, ColumnType columnType, DataColumn dataColumn, object value, string[] messages)97 {98 var columnName = dataColumn.ColumnName;99 if (!DBNull.Value.Equals(value))100 {101 if (columnRole != ColumnRole.Ignore)102 {103 if (columnType == ColumnType.Numeric && IsNumericField(dataColumn))104 return;105 var numericConverter = new NumericCaster();106 if (columnType == ColumnType.Numeric && !(numericConverter.IsValid(value) || BaseComparer.IsValidInterval(value)))107 {108 var exception = string.Format(messages[0]109 , columnName, value.ToString());110 if (numericConverter.IsValid(value.ToString().Replace(",", ".")))111 exception += messages[1];112 throw new EquivalerException(exception);113 }114 if (columnType == ColumnType.DateTime && IsDateTimeField(dataColumn))115 return;116 if (columnType == ColumnType.DateTime && !BaseComparer.IsValidDateTime(value.ToString()))117 {118 throw new EquivalerException(119 string.Format(messages[2]120 , columnName, value.ToString()));121 }122 }123 }124 }125 protected void WriteSettingsToDataTableProperties(DataColumn column, ColumnRole role, ColumnType type, Tolerance tolerance, Rounding rounding)126 {127 if (column.ExtendedProperties.ContainsKey("NBi::Role"))128 column.ExtendedProperties["NBi::Role"] = role;129 else130 column.ExtendedProperties.Add("NBi::Role", role);...
LookupMatchesAnalyzer.cs
Source:LookupMatchesAnalyzer.cs
1using NBi.Core.ResultSet.Lookup.Violation;2using NBi.Core.Scalar.Casting;3using NBi.Core.Scalar.Comparer;4using System;5using System.Collections.Generic;6using System.Collections.ObjectModel;7using System.Data;8using System.Diagnostics;9using System.Linq;10using System.Text;11using System.Threading.Tasks;12namespace NBi.Core.ResultSet.Lookup13{14 public class LookupMatchesAnalyzer : LookupExistsAnalyzer15 {16 protected ColumnMappingCollection Values { get; private set; }17 protected IDictionary<IColumnIdentifier, Tolerance> Tolerances { get; private set; }18 public LookupMatchesAnalyzer(ColumnMappingCollection keys, ColumnMappingCollection values)19 : this(keys, values, null) { }20 21 public LookupMatchesAnalyzer(ColumnMappingCollection keys, ColumnMappingCollection values, IDictionary<IColumnIdentifier, Tolerance> tolerances)22 : base(keys)23 {24 Values = values;25 Tolerances = tolerances ?? new Dictionary<IColumnIdentifier, Tolerance>();26 }27 protected override LookupViolationCollection Execute(DataTable candidate, DataTable reference)28 {29 var stopWatch = new Stopwatch();30 stopWatch.Start();31 var referenceKeyRetriever = BuildColumnsRetriever(Keys, x => x.ReferenceColumn);32 var referenceValueRetriever = BuildColumnsRetriever(Values, x => x.ReferenceColumn);33 var references = BuildReferenceIndex(reference, referenceKeyRetriever, referenceValueRetriever);34 Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceInfo, $"Building the index (including value columns) for keys from the reference table containing {references.Count} rows [{stopWatch.Elapsed:d'.'hh':'mm':'ss'.'fff'ms'}]");35 stopWatch.Restart();36 var candidateKeyBuilder = BuildColumnsRetriever(Keys, x => x.CandidateColumn);37 var candidateValueRetriever = BuildColumnsRetriever(Values, x => x.CandidateColumn);38 var violations = ExtractLookupViolation(candidate, candidateKeyBuilder, candidateValueRetriever, references, Tolerances);39 Trace.WriteLineIf(Extensibility.NBiTraceSwitch.TraceInfo, $"Analyzing potential lookup violations (based on keys and values) for the {candidate.Rows.Count} rows from candidate table [{stopWatch.Elapsed:d'.'hh':'mm':'ss'.'fff'ms'}]");40 return violations;41 }42 protected IDictionary<KeyCollection, ICollection<KeyCollection>> BuildReferenceIndex(DataTable table, CellRetriever keyRetriever, CellRetriever valuesRetriever)43 {44 var references = new Dictionary<KeyCollection, ICollection<KeyCollection>>();45 foreach (DataRow row in table.Rows)46 {47 var keys = keyRetriever.GetColumns(row);48 var values = valuesRetriever.GetColumns(row);49 if (!references.ContainsKey(keys))50 references.Add(keys, new HashSet<KeyCollection>() { values });51 else52 references[keys].Add(values);53 }54 return references;55 }56 private LookupViolationCollection ExtractLookupViolation(DataTable table, CellRetriever keyRetriever, CellRetriever valueRetriever, IDictionary<KeyCollection, ICollection<KeyCollection>> references, IDictionary<IColumnIdentifier, Tolerance> tolerances)57 {58 var violations = new LookupMatchesViolationCollection(Keys, Values);59 foreach (DataRow row in table.Rows)60 {61 var keys = keyRetriever.GetColumns(row);62 if (!references.ContainsKey(keys))63 violations.Register(keys, row);64 else65 {66 var setResults = new List<Dictionary<DataColumn, ComparerResult>>();67 foreach (var valueFields in references[keys])68 {69 var rowResults = new Dictionary<DataColumn, ComparerResult>();70 var tuples = valueFields.Members.Zip(Values,71 (x, c) => new {72 ReferenceValue = x,73 CandidateValue = row.GetValue(c.CandidateColumn),74 c.Type,75 Column = row.Table.GetColumn(c.CandidateColumn),76 Tolerance = tolerances.ContainsKey(c.CandidateColumn) ? tolerances[c.CandidateColumn] : null77 } );78 foreach (var tuple in tuples)79 {80 var cellComparer = new CellComparer();81 var cellResult = cellComparer.Compare(tuple.ReferenceValue, tuple.CandidateValue, tuple.Type, tuple.Tolerance, null);82 rowResults.Add(tuple.Column, cellResult);83 }84 setResults.Add(rowResults);85 if (rowResults.Values.All(x => x.AreEqual))86 break;87 }88 if (!setResults.Any(x => x.All(y => y.Value.AreEqual)))89 {90 var composite = new LookupMatchesViolationComposite(row, new List<LookupMatchesViolationRecord>());91 foreach (var rowResults in setResults)92 {93 var cases = new LookupMatchesViolationRecord();94 foreach (var cellResult in rowResults)95 {...
CellComparerTest.cs
Source:CellComparerTest.cs
1using System;2using System.Linq;3using NBi.Core.Scalar.Comparer;4using NUnit.Framework;5using NBi.Core.ResultSet;6namespace NBi.Testing.Core.Scalar.Comparer7{8 [TestFixture]9 public class CellComparerTest10 {11 #region SetUp & TearDown12 //Called only at instance creation13 [OneTimeSetUp]14 public void SetupMethods()15 {16 }17 //Called only at instance destruction18 [OneTimeTearDown]19 public void TearDownMethods()20 {21 }22 //Called before each test23 [SetUp]24 public void SetupTest()25 {26 }27 //Called after each test28 [TearDown]29 public void TearDownTest()30 {31 }32 #endregion33 [TestCase(10, ColumnType.Numeric)]34 [TestCase(10.12212, ColumnType.Numeric)]35 [TestCase("alpha", ColumnType.Text)]36 [TestCase("2016-12-10", ColumnType.DateTime)]37 [TestCase(true, ColumnType.Boolean)]38 [Test]39 public void Compare_ToItself_True(object value, ColumnType columnType)40 {41 var comparer = new CellComparer();42 var result = comparer.Compare(value, value, columnType, null, null);43 Assert.That(result.AreEqual, Is.True);44 }45 [TestCase(10, ColumnType.Numeric)]46 [TestCase(10.12212, ColumnType.Numeric)]47 [TestCase("alpha", ColumnType.Text)]48 [TestCase("2016-12-10", ColumnType.DateTime)]49 [TestCase(true, ColumnType.Boolean)]50 [Test]51 public void Compare_ToAny_True(object value, ColumnType columnType)52 {53 var comparer = new CellComparer();54 var result = comparer.Compare(value, "(any)", columnType, null, null);55 Assert.That(result.AreEqual, Is.True);56 }57 [TestCase(10, ColumnType.Numeric)]58 [TestCase(10.12212, ColumnType.Numeric)]59 [TestCase("alpha", ColumnType.Text)]60 [TestCase("2016-12-10", ColumnType.DateTime)]61 [TestCase(true, ColumnType.Boolean)]62 [Test]63 public void Compare_ToValue_True(object value, ColumnType columnType)64 {65 var comparer = new CellComparer();66 var result = comparer.Compare(value, "(value)", columnType, null, null);67 Assert.That(result.AreEqual, Is.True);68 }69 [TestCase("(null)", "(blank)")]70 [TestCase("(blank)", "(null)")]71 [Test]72 public void Compare_BlankNullEmpty_True(object x, object y)73 {74 var comparer = new CellComparer();75 var result = comparer.Compare(x, y, ColumnType.Text, null, null);76 Assert.That(result.AreEqual, Is.True);77 }78 }79}...
Compare
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.Scalar.Comparer;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Comparer;9using NBi.Core.ResultSet.Equivalence;10using NBi.Core.Calculation;11using NBi.Core.Calculation.Predicate;12using NBi.Core.Calculation.Ranking;13using NBi.Core.Calculation.Ranking.Strategy;14using NBi.Core.Calculation.Ranking.Position;15using NBi.Core.Calculation.Ranking.Nth;16using NBi.Core.Calculation.Ranking.Percentile;17using NBi.Core.Calculation.Ranking.Proportion;18using NBi.Core.Calculation.Ranking.Proportion.Proportions;19using NBi.Core.Calculation.Ranking.Proportion.Proportions.Nth;20using NBi.Core.Calculation.Ranking.Proportion.Proportions.Percentile;21using NBi.Core.Calculation.Ranking.Proportion.Proportions.Proportion;22using NBi.Core.Calculation.Ranking.Proportion.Proportions.Top;23using NBi.Core.Calculation.Ranking.Proportion.Proportions.Bottom;24using NBi.Core.Calculation.Ranking.Proportion.Proportions.BottomNth;25using NBi.Core.Calculation.Ranking.Proportion.Proportions.TopNth;26using NBi.Core.Calculation.Ranking.Proportion.Proportions.TopPercentile;27using NBi.Core.Calculation.Ranking.Proportion.Proportions.BottomPercentile;28using NBi.Core.Calculation.Ranking.Proportion.Proportions.TopProportion;29using NBi.Core.Calculation.Ranking.Proportion.Proportions.BottomProportion;30using NBi.Core.Calculation.Ranking.Proportion.Proportions.TopProportion;31using NBi.Core.Calculation.Ranking.Proportion.Proportions.BottomProportion;32using NBi.Core.Calculation.Ranking.Proportion.Proportions.TopProportion;33using NBi.Core.Calculation.Ranking.Proportion.Proportions.BottomProportion;34using NBi.Core.Calculation.Ranking.Proportion.Proportions.TopProportion;35using NBi.Core.Calculation.Ranking.Proportion.Proportions.BottomProportion;36using NBi.Core.Calculation.Ranking.Proportion.Proportions.TopProportion;37using NBi.Core.Calculation.Ranking.Proportion.Proportions.BottomProportion;
Compare
Using AI Code Generation
1var comparer = new CellComparer();2var result = comparer.Compare("1", "1");3var comparer = new CellComparer();4var result = comparer.Compare("1", "2");5var comparer = new CellComparer();6var result = comparer.Compare("1", "1");7var comparer = new CellComparer();8var result = comparer.Compare("1", "2");9var comparer = new CellComparer();10var result = comparer.Compare("1", "1");11var comparer = new CellComparer();12var result = comparer.Compare("1", "2");13var comparer = new CellComparer();14var result = comparer.Compare("1", "1");15var comparer = new CellComparer();16var result = comparer.Compare("1", "2");17var comparer = new CellComparer();18var result = comparer.Compare("1", "1");19var comparer = new CellComparer();20var result = comparer.Compare("1", "2");21var comparer = new CellComparer();22var result = comparer.Compare("1", "1");23var comparer = new CellComparer();24var result = comparer.Compare("1", "2");
Compare
Using AI Code Generation
1using System;2using System.Data;3using NBi.Core.Scalar.Comparer;4{5 public static void Main()6 {7 DataTable dt = new DataTable();8 dt.Columns.Add("ID", typeof(int));9 dt.Columns.Add("Name", typeof(string));10 dt.Rows.Add(1, "Test");11 dt.Rows.Add(2, "Test");12 dt.Rows.Add(3, "Test");13 dt.Rows.Add(4, "Test");14 dt.Rows.Add(5, "Test");15 dt.Rows.Add(6, "Test");16 dt.Rows.Add(7, "Test");17 dt.Rows.Add(8, "Test");18 dt.Rows.Add(9, "Test");19 dt.Rows.Add(10, "Test");20 dt.Rows.Add(11, "Test");21 dt.Rows.Add(12, "Test");22 dt.Rows.Add(13, "Test");23 dt.Rows.Add(14, "Test");24 dt.Rows.Add(15, "Test");25 dt.Rows.Add(16, "Test");26 dt.Rows.Add(17, "Test");27 dt.Rows.Add(18, "Test");28 dt.Rows.Add(19, "Test");29 dt.Rows.Add(20, "Test");30 dt.Rows.Add(21, "Test");31 dt.Rows.Add(22, "Test");32 dt.Rows.Add(23, "Test");33 dt.Rows.Add(24, "Test");34 dt.Rows.Add(25, "Test");35 dt.Rows.Add(26, "Test");36 dt.Rows.Add(27, "Test");37 dt.Rows.Add(28, "Test");38 dt.Rows.Add(29, "Test");39 dt.Rows.Add(30, "Test");40 dt.Rows.Add(31, "Test");41 dt.Rows.Add(32, "Test");42 dt.Rows.Add(33, "Test");43 dt.Rows.Add(34, "Test");44 dt.Rows.Add(35, "Test");45 dt.Rows.Add(36, "Test");46 dt.Rows.Add(37, "Test");47 dt.Rows.Add(38, "Test");48 dt.Rows.Add(39, "Test");49 dt.Rows.Add(40, "Test");50 dt.Rows.Add(41, "Test");51 dt.Rows.Add(42, "Test");52 dt.Rows.Add(43, "Test");53 dt.Rows.Add(44, "Test");
Compare
Using AI Code Generation
1var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();2var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();3var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();4var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();5var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();6var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();7var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();8var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();9var cellComparer = new NBi.Core.Scalar.Comparer.CellComparer();
Compare
Using AI Code Generation
1string expected = "1";2string actual = "1";3var comparer = new CellComparer();4var result = comparer.Compare(expected, actual);5Console.WriteLine(result);6string expected = "1";7string actual = "2";8var comparer = new CellComparer();9var result = comparer.Compare(expected, actual);10Console.WriteLine(result);11string expected = "1";12string actual = "1.0";13var comparer = new CellComparer();14var result = comparer.Compare(expected, actual);15Console.WriteLine(result);16string expected = "1";17string actual = "1.1";18var comparer = new CellComparer();19var result = comparer.Compare(expected, actual);20Console.WriteLine(result);21string expected = "1";22string actual = "1.0";23var comparer = new CellComparer();24var result = comparer.Compare(expected, actual);25Console.WriteLine(result);26string expected = "1";27string actual = "1.1";28var comparer = new CellComparer();29var result = comparer.Compare(expected, actual);30Console.WriteLine(result);31string expected = "1";32string actual = "1.0";33var comparer = new CellComparer();34var result = comparer.Compare(expected, actual);35Console.WriteLine(result);36string expected = "1";37string actual = "1.1";38var comparer = new CellComparer();39var result = comparer.Compare(expected, actual);40Console.WriteLine(result);
Compare
Using AI Code Generation
1var comparer = new CellComparer();2var result = comparer.Compare("1", "1", new CellComparerArgs());3Console.WriteLine(result);4var comparer = new CellComparer();5var result = comparer.Compare("1", "1", new CellComparerArgs());6Console.WriteLine(result);7var comparer = new CellComparer();8var result = comparer.Compare("1", "1", new CellComparerArgs());9Console.WriteLine(result);10var comparer = new CellComparer();11var result = comparer.Compare("1", "1", new CellComparerArgs());12Console.WriteLine(result);13var comparer = new CellComparer();14var result = comparer.Compare("1", "1", new CellComparerArgs());15Console.WriteLine(result);16var comparer = new CellComparer();17var result = comparer.Compare("1", "1", new CellComparerArgs());18Console.WriteLine(result);19var comparer = new CellComparer();20var result = comparer.Compare("1", "1", new CellComparerArgs());21Console.WriteLine(result);22var comparer = new CellComparer();23var result = comparer.Compare("1", "1", new CellComparerArgs());24Console.WriteLine(result);25var comparer = new CellComparer();26var result = comparer.Compare("1", "1", new CellComparerArgs());27Console.WriteLine(result);28var comparer = new CellComparer();29var result = comparer.Compare("1", "1", new CellComparerArgs());30Console.WriteLine(result);
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!!