Ejemplo n.º 1
0
        /// <summary>
        /// Transform formula to canonical form.
        /// </summary>
        /// <param name="formula"></param>
        /// <returns></returns>
        /// <exception cref="InvalidFormulaException"><see cref="IExpressionSearcher"/> cannot form groups collection or render groups that were found.</exception>
        public string Transform(string formula, bool optimize = true)
        {
            if (optimize && _groupsSearcher is IFormulaValidator validator && !validator.Validate(formula))
            {
                // it is faster than catch exception.
                return(null);
            }

            var groups = _groupsSearcher.SearchGroups(formula)
                         ?? throw new InvalidFormulaException(formula, "cannot find variable's expressions");

            return(_renderer.Render(groups) ?? throw new InvalidFormulaException(formula, "cannot render formula"));
        }
 public void NullString_ThrowsInvalidFormulaException()
 {
     Assert.Throws <InvalidFormulaException>(() => searcher.SearchGroups(null).ToArray());
 }