public void Pow_Func() { ComplexFunctions cf = ComplexFunctions.GetSingletonInstance(); Complex c = new Complex(50, 50); Complex pow = new Complex(10, 1); Complex expected = Complex.Pow(c, pow); Complex actual = cf.Pow(c, pow, (x) => x); Assert.AreEqual(expected, actual); expected = Complex.Pow(Complex.Exp(c), pow); actual = cf.Pow(c, pow, (x) => Complex.Exp(x)); Assert.AreEqual(expected, actual); expected = Complex.Exp(Complex.Pow(c, pow)); actual = cf.Exp(c, (x) => cf.Pow(c, pow)); Assert.AreEqual(expected, actual); }
private static Boolean TryComplexParse(String normalizedExpression, out String strExpression, out ComplexFunctions complexFunction) { complexFunction = ComplexFunctions.None; strExpression = String.Copy(normalizedExpression); if (Regex.IsMatch(strExpression, @"^[0-9]")) { return(false); } var subExpression = Helpers.GetSubExpression(strExpression); if (subExpression != strExpression) { return(false); } var match = Regex.Match(strExpression, @"[([{]"); if (!match.Success) { return(false); } var expression1 = strExpression.Substring(0, match.Index).ToUpper(); var functionName = Enum.GetNames(typeof(ComplexFunctions)).FirstOrDefault(p => p.ToUpper() == expression1); if (functionName == null) { return(false); } complexFunction = (ComplexFunctions)Enum.Parse(typeof(ComplexFunctions), functionName); strExpression = strExpression.Substring(functionName.Length + 1, strExpression.Length - functionName.Length - 2); return(true); }
public void GetSingletonInstance() { ComplexFunctions cf = ComplexFunctions.GetSingletonInstance(); Assert.IsNotNull(cf); }
public ComplexUnit(String strExpression, ComplexFunctions complexFunction) : base(strExpression) { this._function = complexFunction; }
private static Boolean TryComplexParse(String normalizedExpression, out String strExpression, out ComplexFunctions complexFunction) { complexFunction = ComplexFunctions.None; strExpression = normalizedExpression; /*************************************************** * NOTE: now it has 2 classified conditions: * 1. sub != origin * 2. sub == orgin ***************************************************/ // 1.sub != origin var subExpression = Helper.GetSubExpression(strExpression); if (subExpression != strExpression) { return(false); } // 2. sub == origin /*************************************************** * NOTE: now it has 3 potential conditions: * 1. started with number * 2. started with left bracket --- [Impossible] * 3. start with string which is function name * * so, actually it has 2 classified conditions: * 1. started with number * 2. started with char ***************************************************/ // 2.1 started with number if (Regex.IsMatch(strExpression, @"^[0-9]")) { return(false); } // 2.2 started with char var match = Regex.Match(strExpression, @"[([{]"); if (!match.Success) { throw new Exception(String.Format("TryComplexParse Expression: {0}", strExpression)); } // get the complex function name var expression1 = strExpression.Substring(0, match.Index).ToUpper(); var functionName = Enum.GetNames(typeof(ComplexFunctions)).FirstOrDefault(p => p.ToUpper() == expression1); if (functionName == null) // not a complex function { return(false); } complexFunction = (ComplexFunctions)Enum.Parse(typeof(ComplexFunctions), functionName); strExpression = strExpression.Substring(functionName.Length + 1, strExpression.Length - functionName.Length - 2); return(true); }