Exemplo n.º 1
0
        private bool Add(SymbolicConstant <T> lower, SymbolicConstant <T> upper)
        {
            if (LessThan(upper, lower) == true)
            {
                // Cycle!
                return(false);
            }

            if (lower.Equals(upper))
            {
                return(true);
            }

            if (!_Orders.TryGetValue(lower, out var lowerNode))
            {
                lowerNode = new OrderNode(lower);
                _Orders.Add(lower, lowerNode);
            }

            if (!_Orders.TryGetValue(upper, out var upperNode))
            {
                upperNode = new OrderNode(upper);
                _Orders.Add(upper, upperNode);
            }

            upperNode.Previous.Add(lowerNode);
            lowerNode.Next.Add(upperNode);
            return(true);
        }
Exemplo n.º 2
0
        protected bool TryGetSymbolicConstant <T>(ExpressionSyntax expression, out SymbolicConstant <T> value, bool acceptSymbolic = true)
            where T : IComparable <T>
        {
            var constant = Model.GetConstantValue(expression);

            if (!constant.HasValue)
            {
                var symbol = Model.GetSymbolInfo(expression).Symbol;
                if (_DateTimeConstants.TryGetValue(symbol, out var dt) ||
                    _DateTimeConstants.TryGetValue(symbol.OriginalDefinition, out dt))
                {
                    value = new SymbolicConstant <T>((T)(object)dt);
                    return(true);
                }

                if (_DateTimeConstructions.Contains(symbol))
                {
                    return(TryCreateDateTime((ObjectCreationExpressionSyntax)expression, out value));
                }

                if (acceptSymbolic)
                {
                    if (symbol is IFieldSymbol field)
                    {
                        // Symbolic Range
                        value = new SymbolicConstant <T>(field);
                        return(true);
                    }

                    if (symbol is IPropertySymbol property &&
                        !property.IsIndexer)
                    {
                        // Symbolic Range
                        value = new SymbolicConstant <T>(property);
                        return(true);
                    }
                }

                if (Equals((symbol as ILocalSymbol)?.Type ??
                           (symbol as IPropertySymbol)?.Type ??
                           (symbol as IMethodSymbol)?.ReturnType,
                           _DateTimeType))
                {
                    ReportDiagnostic(SmartTestsDiagnostics.CreateNotADateCreation(expression));
                }
                else
                {
                    ReportDiagnostic(SmartTestsDiagnostics.CreateNotAConstantPropertyField(expression));
                }
                value = default;
                return(false);
            }

            value = new SymbolicConstant <T>((T)Convert.ChangeType(constant.Value, typeof(T)));
            return(true);
        }
Exemplo n.º 3
0
        public bool?LessThan(SymbolicConstant <T> a, SymbolicConstant <T> b)
        {
            if (!a.Symbolic && !b.Symbolic)
            {
                return(a.Constant.CompareTo(b.Constant) < 0);
            }
            if (a.Equals(_Min) || b.Equals(_Max))
            {
                return(true);
            }
            if (a.Equals(_Max) || b.Equals(_Min))
            {
                return(false);
            }

            // Need to find a path from a to b
            if (!_Orders.TryGetValue(a, out var nodeA))
            {
                // ?!? Unable to compare
                return(null);
            }
            var result = nodeA.HasNext(b);

            if (result)
            {
                return(true);
            }

            result = nodeA.HasPrevious(b);
            if (result)
            {
                return(false);
            }

            return(null);
        }
Exemplo n.º 4
0
 public SymbolicOrder(SymbolicConstant <T> min, SymbolicConstant <T> max)
 {
     _Min = min;
     _Max = max;
 }
Exemplo n.º 5
0
 public bool HasNext(SymbolicConstant <T> value) => Next.Any(node => node.Constant.Equals(value) || node.HasNext(value));
Exemplo n.º 6
0
 public bool HasPrevious(SymbolicConstant <T> value) => Previous.Any(node => node.Constant.Equals(value) || node.HasPrevious(value));
Exemplo n.º 7
0
 public OrderNode(SymbolicConstant <T> constant)
 {
     Constant = constant;
 }
Exemplo n.º 8
0
 public bool?GreaterOrEqual(SymbolicConstant <T> a, SymbolicConstant <T> b) => !LessThan(a, b);
Exemplo n.º 9
0
 public bool?LessOrEqual(SymbolicConstant <T> a, SymbolicConstant <T> b) => a.Equals(b) ? true : LessThan(a, b);
Exemplo n.º 10
0
 public bool Equals(SymbolicConstant <T> other) =>
 other != null &&
 Unknown == other.Unknown &&
 Constant.Equals(other.Constant) &&
 Equals(Field, other.Field) &&
 Equals(Property, other.Property);
Exemplo n.º 11
0
 public bool ConstantGreaterThan(SymbolicConstant <T> other) => !Symbolic && Constant.CompareTo(other.Constant) > 0;