public void ComparerInitialises() { IComparer <ChainedComparerTestItem> primary = new KeySelectorComparer <ChainedComparerTestItem, int>(i => i.A); IComparer <ChainedComparerTestItem> secondary = new KeySelectorComparer <ChainedComparerTestItem, int>(i => i.B); var comparer = new ChainedComparer <ChainedComparerTestItem>(primary, secondary); Assert.IsNotNull(comparer); }
public void ComparerReturnsPositiveOneWhenFirstItemIsGreaterThanSecondItemOnSecondaryComparer() { IComparer <ChainedComparerTestItem> primary = new KeySelectorComparer <ChainedComparerTestItem, int>(i => i.A); IComparer <ChainedComparerTestItem> secondary = new KeySelectorComparer <ChainedComparerTestItem, int>(i => i.B); var comparer = new ChainedComparer <ChainedComparerTestItem>(primary, secondary); var first = new ChainedComparerTestItem { A = 1, B = 2 }; var second = new ChainedComparerTestItem { A = 1, B = 1 }; int result = comparer.Compare(first, second); Assert.AreEqual(1, result); }
public void ComparerReturnsZeroWhenFirstItemIsEqualToSecondItemOnBothPrimaryAndSecondaryComparers() { IComparer <ChainedComparerTestItem> primary = new KeySelectorComparer <ChainedComparerTestItem, int>(i => i.A); IComparer <ChainedComparerTestItem> secondary = new KeySelectorComparer <ChainedComparerTestItem, int>(i => i.B); var comparer = new ChainedComparer <ChainedComparerTestItem>(primary, secondary); var first = new ChainedComparerTestItem { A = 1, B = 1 }; var second = new ChainedComparerTestItem { A = 1, B = 1 }; int result = comparer.Compare(first, second); Assert.AreEqual(0, result); }