Example #1
0
        /// <summary>
        /// Get an element from the set.
        /// </summary>
        /// <returns>An element if non-empty.</returns>
        public T Element()
        {
            var model = this.Solver.Satisfiable(this.Set);

            if (!model.HasValue)
            {
                throw new ZenException("No element exists in state set.");
            }

            var assignment = new Dictionary <object, object>();

            foreach (var kv in this.ArbitraryMapping)
            {
                var value = this.Solver.Get(model.Value, kv.Value);
                assignment[kv.Key] = value;
            }

            var interpreterEnv = new ExpressionEvaluatorEnvironment(assignment);

            return(CommonUtilities.ConvertSymbolicResultToCSharp <T>(this.ZenExpression.Accept(new ExpressionEvaluator(false), interpreterEnv)));
        }
Example #2
0
        /// <summary>
        /// Get an element from the set.
        /// </summary>
        /// <returns>An element if non-empty.</returns>
        public Option <T> Element()
        {
            var model = this.Solver.Satisfiable(this.Set);

            if (!model.HasValue)
            {
                return(Option.None <T>());
            }

            var assignment = new Dictionary <object, object>();

            foreach (var kv in this.ArbitraryMapping)
            {
                var value = this.Solver.Get(model.Value, kv.Value);
                assignment[kv.Key] = value;
            }

            var interpreterEnv = new ExpressionEvaluatorEnvironment(assignment);
            var result         = CommonUtilities.ConvertSymbolicResultToCSharp <T>(this.ZenExpression.Accept(new ExpressionEvaluator(false), interpreterEnv));

            return(Option.Some(result));
        }