예제 #1
0
        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));
        }
예제 #2
0
        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}");
                }
            }
        }
예제 #3
0
 public bool Equals(DataTypeValuePair <TDataTypeEnum> other) => this == other;