public void ToStringTest() { var complex = new Complex(3.1, 2.5); var exp = new Conjugate(new ComplexNumber(complex)); Assert.Equal("conjugate(3.1+2.5i)", exp.ToString()); }
public void CloneTest() { var exp = new Conjugate(new ComplexNumber(new Complex(2, 2))); var clone = exp.Clone(); Assert.Equal(exp, clone); }
public void SolveComplexTest() { var lexer = new Mock <ILexer>(); var parser = new Mock <IParser>(); var simplifier = new Mock <ISimplifier>(); var strExp = "conjugate(2.3 + 1.4i)"; var complex = new Complex(2.3, 1.4); var exp = new Conjugate(new ComplexNumber(complex)); var tokens = new List <IToken> { new FunctionToken(Functions.Conjugate, 1), new SymbolToken(Symbols.OpenBracket), new NumberToken(2.3), new OperationToken(Operations.Addition), new NumberToken(1.4), new OperationToken(Operations.Multiplication), new ComplexNumberToken(Complex.ImaginaryOne), new SymbolToken(Symbols.CloseBracket) }; lexer.Setup(l => l.Tokenize(strExp)).Returns(() => tokens); parser.Setup(p => p.Parse(tokens)).Returns(() => exp); simplifier.Setup(s => s.Analyze(It.IsAny <Conjugate>())).Returns <Conjugate>(e => e); var processor = new Processor(lexer.Object, parser.Object, simplifier.Object, null); var result = processor.Solve <ComplexNumberResult>(strExp); lexer.Verify(l => l.Tokenize(It.IsAny <string>()), Times.Once()); parser.Verify(p => p.Parse(It.IsAny <IEnumerable <IToken> >()), Times.Once()); Assert.Equal(Complex.Conjugate(complex), result.Result); }
public void ConjugateToStringTest() { var complex = new Complex(3.1, 2.5); var exp = new Conjugate(new ComplexNumber(complex)); Assert.Equal("conjugate(3.1+2.5i)", exp.ToString(commoonFormatter)); }
public void ExecuteTest1() { var complex = new Complex(3.1, 2.5); var exp = new Conjugate(new ComplexNumber(complex)); Assert.Equal(Complex.Conjugate(complex), exp.Execute()); }
public void ExecuteTest1() { var complex = new Complex(3.1, 2.5); var exp = new Conjugate(new ComplexNumber(complex)); Assert.Equal(Complex.Conjugate(complex), exp.Execute()); }
public static string OneOfDescription(bool isPlural, Conjugate conjugate, string desc) { string pronoun = conjugate.PossessiveAdjective(); if (isPlural) { return("one of " + pronoun + " " + desc); } else { return(pronoun + " " + desc); } }
public string EachHornShortDescription(Conjugate conjugate) { string pronoun = conjugate.PossessiveAdjective(); if (numHorns == 0) { return(""); } else if (numHorns == 1) { return(pronoun + " " + ShortDescription()); } else { return("each of " + pronoun + " " + ShortDescription()); } }
public void SolveComplexTest() { var lexer = new Mock<ILexer>(); var parser = new Mock<IParser>(); var simplifier = new Mock<ISimplifier>(); var strExp = "conjugate(2.3 + 1.4i)"; var complex = new Complex(2.3, 1.4); var exp = new Conjugate(new ComplexNumber(complex)); var tokens = new List<IToken> { new FunctionToken(Functions.Conjugate, 1), new SymbolToken(Symbols.OpenBracket), new NumberToken(2.3), new OperationToken(Operations.Addition), new NumberToken(1.4), new OperationToken(Operations.Multiplication), new ComplexNumberToken(Complex.ImaginaryOne), new SymbolToken(Symbols.CloseBracket) }; lexer.Setup(l => l.Tokenize(strExp)).Returns(() => tokens); parser.Setup(p => p.Parse(tokens)).Returns(() => exp); simplifier.Setup(s => s.Analyze(It.IsAny<Conjugate>())).Returns<Conjugate>(e => e); var processor = new Processor(lexer.Object, parser.Object, simplifier.Object, null); var result = processor.Solve<ComplexNumberResult>(strExp); lexer.Verify(l => l.Tokenize(It.IsAny<string>()), Times.Once()); parser.Verify(p => p.Parse(It.IsAny<IEnumerable<IToken>>()), Times.Once()); Assert.Equal(Complex.Conjugate(complex), result.Result); }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns>The result of analysis.</returns> public string Analyze(Conjugate exp) { return(ToString(exp, "conjugate({0})")); }
public void TestConjugateException() { var exp = new Conjugate(new Number(2)); TestException(exp); }
public void TestConjugateComplexNumber() { var exp = new Conjugate(new ComplexNumber(2, 3)); Test(exp, ResultType.ComplexNumber); }
public void TestConjugateUndefined() { var exp = new Conjugate(Variable.X); Test(exp, ResultType.Undefined); }
/// <summary> /// Creates an expression object from <see cref="FunctionToken"/>. /// </summary> /// <param name="token">The function token.</param> /// <returns>An expression.</returns> protected virtual IExpression CreateFunction(FunctionToken token) { IExpression exp; switch (token.Function) { case Functions.Add: exp = new Add(); break; case Functions.Sub: exp = new Sub(); break; case Functions.Mul: exp = new Mul(); break; case Functions.Div: exp = new Div(); break; case Functions.Pow: exp = new Pow(); break; case Functions.Absolute: exp = new Abs(); break; case Functions.Sine: exp = new Sin(); break; case Functions.Cosine: exp = new Cos(); break; case Functions.Tangent: exp = new Tan(); break; case Functions.Cotangent: exp = new Cot(); break; case Functions.Secant: exp = new Sec(); break; case Functions.Cosecant: exp = new Csc(); break; case Functions.Arcsine: exp = new Arcsin(); break; case Functions.Arccosine: exp = new Arccos(); break; case Functions.Arctangent: exp = new Arctan(); break; case Functions.Arccotangent: exp = new Arccot(); break; case Functions.Arcsecant: exp = new Arcsec(); break; case Functions.Arccosecant: exp = new Arccsc(); break; case Functions.Sqrt: exp = new Sqrt(); break; case Functions.Root: exp = new Root(); break; case Functions.Ln: exp = new Ln(); break; case Functions.Lg: exp = new Lg(); break; case Functions.Lb: exp = new Lb(); break; case Functions.Log: exp = new Log(); break; case Functions.Sineh: exp = new Sinh(); break; case Functions.Cosineh: exp = new Cosh(); break; case Functions.Tangenth: exp = new Tanh(); break; case Functions.Cotangenth: exp = new Coth(); break; case Functions.Secanth: exp = new Sech(); break; case Functions.Cosecanth: exp = new Csch(); break; case Functions.Arsineh: exp = new Arsinh(); break; case Functions.Arcosineh: exp = new Arcosh(); break; case Functions.Artangenth: exp = new Artanh(); break; case Functions.Arcotangenth: exp = new Arcoth(); break; case Functions.Arsecanth: exp = new Arsech(); break; case Functions.Arcosecanth: exp = new Arcsch(); break; case Functions.Exp: exp = new Exp(); break; case Functions.GCD: exp = new GCD(); break; case Functions.LCM: exp = new LCM(); break; case Functions.Factorial: exp = new Fact(); break; case Functions.Sum: exp = new Sum(); break; case Functions.Product: exp = new Product(); break; case Functions.Round: exp = new Round(); break; case Functions.Floor: exp = new Floor(); break; case Functions.Ceil: exp = new Ceil(); break; case Functions.Derivative: exp = new Derivative(); break; case Functions.Simplify: exp = new Simplify(); break; case Functions.Del: exp = new Del(); break; case Functions.Define: exp = new Define(); break; case Functions.Vector: exp = new Vector(); break; case Functions.Matrix: exp = new Matrix(); break; case Functions.Transpose: exp = new Transpose(); break; case Functions.Determinant: exp = new Determinant(); break; case Functions.Inverse: exp = new Inverse(); break; case Functions.If: exp = new If(); break; case Functions.For: exp = new For(); break; case Functions.While: exp = new While(); break; case Functions.Undefine: exp = new Undefine(); break; case Functions.Im: exp = new Im(); break; case Functions.Re: exp = new Re(); break; case Functions.Phase: exp = new Phase(); break; case Functions.Conjugate: exp = new Conjugate(); break; case Functions.Reciprocal: exp = new Reciprocal(); break; case Functions.Min: exp = new Min(); break; case Functions.Max: exp = new Max(); break; case Functions.Avg: exp = new Avg(); break; case Functions.Count: exp = new Count(); break; case Functions.Var: exp = new Var(); break; case Functions.Varp: exp = new Varp(); break; case Functions.Stdev: exp = new Stdev(); break; case Functions.Stdevp: exp = new Stdevp(); break; default: exp = null; break; } if (exp is DifferentParametersExpression diff) { diff.ParametersCount = token.CountOfParams; } return(exp); }
/// <summary> /// Creates an expression object from <see cref="FunctionToken"/>. /// </summary> /// <param name="token">The function token.</param> /// <returns>An expression.</returns> protected virtual IExpression CreateFunction(FunctionToken token) { IExpression exp; switch (token.Function) { case Functions.Add: exp = new Add(); break; case Functions.Sub: exp = new Sub(); break; case Functions.Mul: exp = new Mul(); break; case Functions.Div: exp = new Div(); break; case Functions.Pow: exp = new Pow(); break; case Functions.Absolute: exp = new Abs(); break; case Functions.Sine: exp = new Sin(); break; case Functions.Cosine: exp = new Cos(); break; case Functions.Tangent: exp = new Tan(); break; case Functions.Cotangent: exp = new Cot(); break; case Functions.Secant: exp = new Sec(); break; case Functions.Cosecant: exp = new Csc(); break; case Functions.Arcsine: exp = new Arcsin(); break; case Functions.Arccosine: exp = new Arccos(); break; case Functions.Arctangent: exp = new Arctan(); break; case Functions.Arccotangent: exp = new Arccot(); break; case Functions.Arcsecant: exp = new Arcsec(); break; case Functions.Arccosecant: exp = new Arccsc(); break; case Functions.Sqrt: exp = new Sqrt(); break; case Functions.Root: exp = new Root(); break; case Functions.Ln: exp = new Ln(); break; case Functions.Lg: exp = new Lg(); break; case Functions.Lb: exp = new Lb(); break; case Functions.Log: exp = new Log(); break; case Functions.Sineh: exp = new Sinh(); break; case Functions.Cosineh: exp = new Cosh(); break; case Functions.Tangenth: exp = new Tanh(); break; case Functions.Cotangenth: exp = new Coth(); break; case Functions.Secanth: exp = new Sech(); break; case Functions.Cosecanth: exp = new Csch(); break; case Functions.Arsineh: exp = new Arsinh(); break; case Functions.Arcosineh: exp = new Arcosh(); break; case Functions.Artangenth: exp = new Artanh(); break; case Functions.Arcotangenth: exp = new Arcoth(); break; case Functions.Arsecanth: exp = new Arsech(); break; case Functions.Arcosecanth: exp = new Arcsch(); break; case Functions.Exp: exp = new Exp(); break; case Functions.GCD: exp = new GCD(); break; case Functions.LCM: exp = new LCM(); break; case Functions.Factorial: exp = new Fact(); break; case Functions.Sum: exp = new Sum(); break; case Functions.Product: exp = new Product(); break; case Functions.Round: exp = new Round(); break; case Functions.Floor: exp = new Floor(); break; case Functions.Ceil: exp = new Ceil(); break; case Functions.Derivative: exp = new Derivative(); break; case Functions.Simplify: exp = new Simplify(); break; case Functions.Del: exp = new Del(); break; case Functions.Define: exp = new Define(); break; case Functions.Vector: exp = new Vector(); break; case Functions.Matrix: exp = new Matrix(); break; case Functions.Transpose: exp = new Transpose(); break; case Functions.Determinant: exp = new Determinant(); break; case Functions.Inverse: exp = new Inverse(); break; case Functions.If: exp = new If(); break; case Functions.For: exp = new For(); break; case Functions.While: exp = new While(); break; case Functions.Undefine: exp = new Undefine(); break; case Functions.Im: exp = new Im(); break; case Functions.Re: exp = new Re(); break; case Functions.Phase: exp = new Phase(); break; case Functions.Conjugate: exp = new Conjugate(); break; case Functions.Reciprocal: exp = new Reciprocal(); break; case Functions.Min: exp = new Min(); break; case Functions.Max: exp = new Max(); break; case Functions.Avg: exp = new Avg(); break; case Functions.Count: exp = new Count(); break; case Functions.Var: exp = new Var(); break; case Functions.Varp: exp = new Varp(); break; case Functions.Stdev: exp = new Stdev(); break; case Functions.Stdevp: exp = new Stdevp(); break; default: exp = null; break; } var diff = exp as DifferentParametersExpression; if (diff != null) diff.ParametersCount = token.CountOfParams; return exp; }
internal static string EachClitOrClitsNoun <T>(IVaginaCollection <T> collection, Conjugate conjugate) where T : IVagina { return(EachClitOrClitsNoun(collection, conjugate, out bool _)); }
public void ConjugateTest() { var tokens = new List<IToken> { new FunctionToken(Functions.Conjugate, 1), new SymbolToken(Symbols.OpenBracket), new ComplexNumberToken(new Complex(3, -2)), new SymbolToken(Symbols.CloseBracket) }; var exp = parser.Parse(tokens); var expected = new Conjugate(new ComplexNumber(new Complex(3, -2))); Assert.Equal(expected, exp); }
internal static string OneVaginaOrVaginasShort <T>(IVaginaCollection <T> collection, Conjugate conjugate) where T : IVagina { if (collection.vaginas.Count == 0) { return(""); } return(CommonBodyPartStrings.OneOfDescription(collection.vaginas.Count > 1, conjugate, AllVaginasShortDescription(collection))); }
internal static string EachVaginaOrVaginasShort <T>(IVaginaCollection <T> collection, Conjugate conjugate) where T : IVagina { return(EachVaginaOrVaginasShort(collection, conjugate, out bool _)); }
internal static string EachVaginaOrVaginasShort <T>(IVaginaCollection <T> collection, Conjugate conjugate, out bool isPlural) where T : IVagina { isPlural = collection.vaginas.Count != 1; if (collection.vaginas.Count == 0) { return(""); } return(CommonBodyPartStrings.EachOfDescription(collection.vaginas.Count > 1, conjugate, AllVaginasShortDescription(collection))); }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns> /// The result of analysis. /// </returns> /// <exception cref="System.NotSupportedException">Always.</exception> public virtual TResult Analyze(Conjugate exp) { throw new NotSupportedException(); }
public void ExecuteExeptionTest() { var exp = new Conjugate(new Number(2)); Assert.Throws <ResultIsNotSupportedException>(() => exp.Execute()); }