public void ComparerFromComparison() { IComparer <int> comparer = Comparers.ComparerFromComparison <int>(CompareOddEven); Assert.IsTrue(comparer.Compare(7, 6) < 0); Assert.IsTrue(comparer.Compare(7, 8) < 0); Assert.IsTrue(comparer.Compare(12, 11) > 0); Assert.IsTrue(comparer.Compare(12, 143) > 0); Assert.IsTrue(comparer.Compare(5, 7) < 0); Assert.IsTrue(comparer.Compare(9, 5) > 0); Assert.IsTrue(comparer.Compare(6, 8) < 0); Assert.IsTrue(comparer.Compare(14, -8) > 0); Assert.IsTrue(comparer.Compare(0, 0) == 0); Assert.IsTrue(comparer.Compare(-3, -3) == 0); }
/// <summary> /// Creates a new OrderedDictionary. The passed delegate will be used to compare keys in this dictionary. /// </summary> /// <param name="comparison">A delegate to a method that will be used to compare keys.</param> public OrderedDictionary(Comparison <TKey> comparison) : this( null, Comparers.ComparerFromComparison <TKey>(comparison), Comparers.ComparerKeyValueFromComparisonKey <TKey, TValue>(comparison)) { }
/// <summary> /// <para>Creates a new OrderedDictionary. The passed delegate will be used to compare keys in this dictionary.</para> /// <para>A collection and keys and values (typically another dictionary) is used to initialized the /// contents of the dictionary.</para> /// </summary> /// <param name="keysAndValues">A collection of keys and values whose contents are used to initialized the dictionary.</param> /// <param name="comparison">A delegate to a method that will be used to compare keys.</param> public OrderedDictionary(IEnumerable <KeyValuePair <TKey, TValue> > keysAndValues, Comparison <TKey> comparison) : this( keysAndValues, Comparers.ComparerFromComparison <TKey>(comparison), Comparers.ComparerKeyValueFromComparisonKey <TKey, TValue>(comparison)) { }
/// <summary> /// Create a new OrderedMultiDictionary. If duplicate values /// are allowed, multiple copies of the same value can be associated with the same key. For example, the key "foo" /// could have "a", "a", and "b" associated with it. If duplicate values are not allowed, only one copies of a given value can /// be associated with the same key, although different keys can have the same value. For example, the key "foo" could /// have "a" and "b" associated with it, which key "bar" has values "b" and "c" associated with it. /// </summary> /// <param name="allowDuplicateValues">Can the same value be associated with a key multiple times?</param> /// <param name="keyComparison">A delegate to a method that will be used to compare keys.</param> /// <param name="valueComparison">A delegate to a method that will be used to compare values.</param> public OrderedMultiDictionary(bool allowDuplicateValues, Comparison <TKey> keyComparison, Comparison <TValue> valueComparison) : this( allowDuplicateValues, Comparers.ComparerFromComparison(keyComparison), Comparers.ComparerFromComparison(valueComparison) ) { }