public int CompareTo(DataTypeValuePair <TDataTypeEnum> other) { if (other == null) { return(1); } var leftTypeCmp = Left.DataType.CompareTo(other.Left.DataType); if (leftTypeCmp != 0) { return(leftTypeCmp); } var rightTypeCmp = Right.DataType.CompareTo(other.Right.DataType); if (rightTypeCmp != 0) { return(rightTypeCmp); } var leftValueCmp = Left.CompareTo(other.Left); if (leftValueCmp != 0) { return(leftValueCmp); } return(Right.CompareTo(other.Right)); }
public static void TestThatAllPossibleOperandTypesAreSupported(Dictionary <DataType, HashSet <DataType> > supportedOperandTypes, Func <InternalDataTypeBase, InternalDataTypeBase, InternalDataTypeBase> operation, string operationDescription) { var allTypePairs = (new[] { EnumExtensions.GetEnumCollection <DataType>(), EnumExtensions.GetEnumCollection <DataType>() }) .CartesianProduct() .Select(r => new DataTypePair <DataType>(r.First(), r.Last())) .Distinct(); var supportedTypes = allTypePairs .Where(p => supportedOperandTypes.ContainsKey(p.Left) && supportedOperandTypes[p.Left].Contains(p.Right)) .ToList(); foreach (var pair in allTypePairs) { var valuePair = new DataTypeValuePair <DataType>(MakeDataType(pair.Left), MakeDataType(pair.Right)); var act = new Action(() => _ = operation(valuePair.Left as InternalDataTypeBase, valuePair.Right as InternalDataTypeBase)); if (supportedTypes.Contains(pair)) { act.Should().NotThrow($"a {pair.Left} and {pair.Right} should be able to be {operationDescription}"); } else { act.Should().Throw <Exception>($"a {pair.Left} and {pair.Right} should not be able to be {operationDescription}"); } } }
public bool Equals(DataTypeValuePair <TDataTypeEnum> other) => this == other;