public void PowerOne() { var pow = new Pow(Variable.X, new Number(1)); var expected = Variable.X; SimpleTest(pow, expected); }
public PowModel(Pow pow) { Pow = pow.Nazwa; PowID = pow.PowID; Woj = pow.Woj.Nazwa; WojId = pow.WojID; }
public void PowerZero() { var pow = new Pow(Variable.X, new Number(0)); var expected = new Number(1); SimpleTest(pow, expected); }
public void PowerOne() { var pow = new Pow(new Variable("x"), new Number(1)); var expected = new Variable("x"); SimpleTest(pow, expected); }
public void CalculateTest(double firstArgument, double secondArgument, double result, double accracy) { var testingFunction = new Pow(); var testResult = testingFunction.Calculate(firstArgument, secondArgument); Assert.AreEqual(result, testResult, accracy); }
public override Expression On(Pow e) { var res = base.On(e); if (res is Pow) { var resB = res as Pow; if (_.Same(resB.Arguments[0], 0)) { return(0); } if (_.Same(resB.Arguments[1], 0)) { return(1); } if (_.Same(resB.Arguments[1], 1)) { return(resB.Arguments[0]); } if (_.Same(resB.Arguments[1], 0.5)) // simplification ? { return(_.Sqrt(resB.Arguments[0])); } } return(res); }
protected override void OnLayout(float left, float top, float width, float height, Graphics g, Font font, Style style) { float baseLine = Math.Max(X.FindMaxTop(), Pow.DesiredHeight); X.Layout(this, 0, baseLine - X.FindMaxTop(), X.DesiredWidth, X.DesiredHeight, g, font, style); Pow.Layout(this, X.DesiredWidth, baseLine - Pow.DesiredHeight, Pow.DesiredWidth, Pow.DesiredHeight, g, font, style); }
public void CalculateAdditionTestStrong(double firstValue, double secondValue, double expected) { ITwoArgumentsCalculator calculator = new Pow(); double result = calculator.Calculate(5, 2); Assert.AreEqual(25, result); }
public static Pow[] GetNarrowPowers(this Rational r, Rational[] narrows = null) { if (narrows == null) { narrows = NarrowUtils.GetDefault(r.GetInvolvedPowerCount()); } int len = r.GetInvolvedPowerCount(); if (len > narrows.Length) { return(null); } Pow[] res = new Pow[len]; r = r.Clone(); for (int i = len - 1; i >= 0; --i) { Pow e = r.GetPrimePower(i); res[i] = e; if (e != 0) { r /= narrows[i].Power(e); } } return(res); }
static public Rational Prime(int primeIndex) { var pows = new Pow[primeIndex + 1]; pows[primeIndex] = (Pow)1; return(new Rational(pows)); }
public void ExecuteTest5() { var complex = new Complex(-3, 2); var exp = new Pow(new ComplexNumber(complex), new Number(10)); Assert.Equal(Complex.Pow(complex, 10), exp.Execute()); }
public int Visit(Pow node) { return ((int)Math.Pow( Visit((dynamic)node[0]), Visit((dynamic)node[1]))); }
protected override void OnMeasure(MeasureSpec widthSpec, MeasureSpec heightSpec, Graphics g, Font font, Style style) { MeasureSpec leftWidth = null; MeasureSpec rightWidth = null; if (widthSpec.Mode == MeasureSpecMode.Fixed || widthSpec.Mode == MeasureSpecMode.AtMost) { leftWidth = MeasureSpec.MakeFixed(widthSpec.Size * 0.8f); rightWidth = MeasureSpec.MakeFixed(widthSpec.Size * 0.2f); } else if (widthSpec.Mode == MeasureSpecMode.Unspecified) { leftWidth = widthSpec; rightWidth = widthSpec; } X.Measure(leftWidth, heightSpec, g, font, style); Pow.Measure(rightWidth, heightSpec, g, font, style); SetDesiredSize( X.DesiredWidth + Pow.DesiredWidth, Pow.DesiredHeight + X.FindMaxTop() + X.FindMaxBottom() - 10); }
public static DoptimizationAlgorithm SelectState(DoptimizeExperimentTable det) { IDoptimizationDistributionSelection distributionSelection = null; LangleyMethodStandardSelection langleyMethod = null; if (det.det_DistributionState == 0) { distributionSelection = new Dop_Noraml(); } else if (det.det_DistributionState == 1) { distributionSelection = new Dop_Logistic(); } if (det.det_StandardState == 0) { langleyMethod = new Standard(); } else if (det.det_StandardState == 1) { langleyMethod = new Ln(); } else if (det.det_StandardState == 2) { langleyMethod = new Log(); } else if (det.det_StandardState == 3) { langleyMethod = new Pow(double.Parse(det.det_Power)); } return(new DoptimizationAlgorithm(distributionSelection, langleyMethod)); }
public void SimpleTest(double first, double second, double expected) { Pow calcul = new Pow(); double result = calcul.Doit(first, second); Assert.AreEqual(expected, result); }
public static Pow[] FromInt(Long n) { if (n <= 0) { throw new ArgumentException(); } var pows = new List <Pow>(); for (int i = 0; n != 1; ++i) { Long p = (Long)Utils.GetPrime(i); //if (p == 0) break; // out of known primes Pow e = (Pow)0; for (;;) { Long rem; Long n1 = LongMath.DivRem(n, p, out rem); if (rem != 0) { break; } n = n1; e += (Pow)1; } pows.Add(e); } return(pows.ToArray()); }
public void CalculateTest(double firstValue, double secondValue, double expected) { var calculator = new Pow(); var actualResult = calculator.Calculate(firstValue, secondValue); Assert.AreEqual(expected, actualResult); }
public void CloneTest() { var exp = new Pow(Variable.X, new Number(0)); var clone = exp.Clone(); Assert.Equal(exp, clone); }
public void Calculate(double firstArgument, double secondArgument, double result) { var calculator = new Pow(); var testresult = calculator.Calculate(firstArgument, secondArgument); Assert.AreEqual(result, testresult); }
public static LangleyAlgorithm SelectState(LangleyExperimentTable let) { LangleyDistributionSelection distributionSelection = null; LangleyMethodStandardSelection langleyMethod = null; if (let.let_DistributionState == 0) { distributionSelection = new Normal(); } else if (let.let_DistributionState == 1) { distributionSelection = new Logistic(); } if (let.let_StandardState == 0) { langleyMethod = new Standard(); } else if (let.let_StandardState == 1) { langleyMethod = new Ln(); } else if (let.let_StandardState == 2) { langleyMethod = new Log(); } else if (let.let_StandardState == 3) { langleyMethod = new Pow(double.Parse(let.let_Power)); } return(new LangleyAlgorithm(distributionSelection, langleyMethod));; }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns> /// The result of analysis. /// </returns> public override IExpression Analyze(Div exp) { if (!Helpers.HasVariable(exp, Variable)) { return(new Number(0)); } var first = Helpers.HasVariable(exp.Left, Variable); var second = Helpers.HasVariable(exp.Right, Variable); if (first && second) { var mul1 = new Mul(exp.Left.Clone().Analyze(this), exp.Right.Clone()); var mul2 = new Mul(exp.Left.Clone(), exp.Right.Clone().Analyze(this)); var sub = new Sub(mul1, mul2); var inv = new Pow(exp.Right.Clone(), new Number(2)); var division = new Div(sub, inv); return(division); } if (second) { var mul2 = new Mul(exp.Left.Clone(), exp.Right.Clone().Analyze(this)); var unMinus = new UnaryMinus(mul2); var inv = new Pow(exp.Right.Clone(), new Number(2)); var division = new Div(unMinus, inv); return(division); } //if (first) return(new Div(exp.Left.Clone().Analyze(this), exp.Right.Clone())); }
public void CalculateTest(double argument, double secondArgument, double result) { var calculator = new Pow(); var testResult = calculator.Calculate(argument, secondArgument); Assert.AreEqual(testResult, result); }
public string Visit(Pow node) { return("(expt " + Visit((dynamic)node[0]) + " " + Visit((dynamic)node[1]) + ")"); }
public void TestCalulate() { Pow operation = new Pow(); var answer = operation.Calculate(3.0, 2.0); Assert.AreEqual(9.0, answer, 1e-9); }
public String Visit(Pow node) { return("(int) pow(" + Visit((dynamic)node[0]) + ", " + Visit((dynamic)node[1]) + ")"); }
public void ExecuteTest4() { var complex1 = new Complex(-3, 2); var complex2 = new Complex(-4, 5); var exp = new Pow(new ComplexNumber(complex1), new ComplexNumber(complex2)); Assert.Equal(Complex.Pow(complex1, complex2), exp.Execute()); }
private CommonF Factor() { Pow pow = new Pow(); CommonF power = Power(); if (!power.IsZero()) { pow.RaiseTo(power); } else { while (IsCaret(look)) { Match('^'); Power(); } return(new Constant(0)); } while (IsCaret(look)) { Match('^'); power = Power(); if (!power.IsZero()) { pow.RaiseTo(power); } else { if (pow.baseAndPower.Count > 1) { pow.baseAndPower.RemoveAt(pow.baseAndPower.Count - 1); while (IsCaret(look)) { Match('^'); Power(); } return(pow); } else { while (IsCaret(look)) { Match('^'); Power(); } return(new Constant(1)); } } } if (pow.baseAndPower.Count == 1) { return(pow.baseAndPower[0]); } else { return(pow); } }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns>The result of analysis.</returns> public string Analyze(Pow exp) { if (exp.Parent is BinaryExpression && !(exp.Parent is Add || exp.Parent is Sub || exp.Parent is Mul)) { return(ToString(exp, "({0} ^ {1})")); } return(ToString(exp, "{0} ^ {1}")); }
public void WhenX2Y3_ShouldResult8( [Values(2)] double x, [Values(3)] double y ) { var operation = new Pow(x, y); Assert.AreEqual(8, operation.Operate()); }
public void WhenXMaxValueY2_ShouldArgumentException( [Values(double.MaxValue)] double x, [Values(2)] double y ) { var operation = new Pow(x, y); Assert.Throws <ArgumentException>(() => { var result = operation.Operate(); }); }