public override Value Visit(Substract substract) { Value left = substract.Left.Accept(this); Value right = substract.Right.Accept(this); return(left.Minus(right)); }
public void CalculateTest(double firstValue, double secondValue, double expected) { var calculator = new Substract(); var actualResult = calculator.Calculate(firstValue, secondValue); Assert.AreEqual(expected, actualResult); }
public MathTask Next() { _step++; MathTask t = null; do { var op = GetNextOperationType(); switch (op) { case Operation.Add: t = new Add(op, level); break; case Operation.Substract: t = new Substract(op, level); break; case Operation.Multiply: t = new Mult(op, level); break; case Operation.Divide: t = new Divide(op, level); break; case Operation.Prime: t = new Prime(op, level); break; case Operation.Perimeter: t = new Perimeter(op, level); break; } t.GenerateArgs(_step, _random); } while (hs.Contains(t.GetHashCode())); _tasks.Add(t); hs.Add(t.GetHashCode()); return(t); }
public override Function SimplifyFunction() { this.RightFunc = this.RightFunc.SimplifyFunction(); if (this.LeftFunc != null) { this.LeftFunc = this.LeftFunc.SimplifyFunction(); if (this.RightFunc.IsNr() && this.RightFunc.Calculate(0) == 0) { return(this.LeftFunc); } else if (this.LeftFunc.IsNr() && this.LeftFunc.Calculate(0) == 0) { this.LeftFunc = null; return(this); } else if (this.LeftFunc.IsNr() && this.RightFunc.IsNr()) { r func = new r(); (func as r).Data = this.Calculate(0); return(func); } return(this); } else { Substract func = new Substract(); func.RightFunc = this.RightFunc.SimplifyFunction(); return(func); } }
public void Calculate(double firstInput, double secondInput, double output) { var calculator = new Substract(); var testResult = calculator.Calculate(firstInput, secondInput); var result = output; Assert.AreEqual(testResult, result); }
public override Function GetDerivativeAnalytically() { Substract derivative = new Substract(); if (this.LeftFunc != null) { derivative.LeftFunc = this.LeftFunc.GetDerivativeAnalytically(); } derivative.RightFunc = this.RightFunc.GetDerivativeAnalytically(); return(derivative); }
public void SubstractionThrowsOverflowExceptionTest() { // Create instance to test. var substract = new Substract(); // Define a test input and output value. var number = new Number { NumberOne = int.MaxValue, NumberTwo = int.MinValue }; // Run the method under test. Assert.Throws <OverflowException>(() => substract.DoOperation(number)); }
public void SubstractionTest() { // Create instance to test. var subtract = new Substract(); // Define a test input and output value. var expected = 4 - 10; var number = new Number { NumberOne = 4, NumberTwo = 10 }; // Run the method under test. var actual = subtract.DoOperation(number); // Verify the result. Assert.AreEqual(expected, actual); }
public void SubstractionStrategyTest() { // Create instance to test. var subtract = new Substract(); var context = new Context(subtract); // Define a test input and output value. var expected = 4 - 10; var number = new Number { NumberOne = 4, NumberTwo = 10 }; // Run the method under test. var actual = helper.DoStrategy(context, number); // Verify the result. Assert.AreEqual(expected, actual); }
static void RunBasicCOR() { ICalcChain add = new Add(); ICalcChain sub = new Substract(); ICalcChain mul = new Multiply(); ICalcChain div = new Divide(); add.NextChain(sub); sub.NextChain(mul); mul.NextChain(div); Console.WriteLine("------ Running Basic COR ------"); Console.WriteLine($"6 + 3 = {add.Calculate(ICalcType.Add, 6, 3)}"); Console.WriteLine($"6 - 3 = {add.Calculate(ICalcType.Substract, 6, 3)}"); Console.WriteLine($"6 * 3 = {add.Calculate(ICalcType.Multiply, 6, 3)}"); Console.WriteLine($"6 / 3 = {add.Calculate(ICalcType.Divide, 6, 3)}"); }
static void Main(string[] args) { RunConfig runConfig; if (!TryParseArguments(args, out runConfig)) { Usage(); return; } var code = File.ReadAllText(args[0]); var pageState = new GraphicsState(); var stack = new LinearList <IOperation>(); var execStack = new LinearList <IOperation>(); var dictStack = new LinearList <IDictionary <string, IOperation> >(); var system = new Dictionary <string, IOperation>(); system["add"] = new Add(); system["sub"] = new Substract(); system["mul"] = new Multiplicate(); system["div"] = new Divide(); system["mod"] = new Mod(); system["def"] = new Define(); system["for"] = new For(); system["dup"] = new Duplicate(); system["index"] = new Index(); system["pop"] = new Pop(); system["exch"] = new Exchange(); system["repeat"] = new Repeat(); system["array"] = new EmptyArray(); system["astore"] = new LoadArray(); system["rand"] = new Rand(); system["cvi"] = new ConvertToInteger(); system["copy"] = new Copy(); system["roll"] = new Roll(); system["get"] = new ArrayGet(); system["put"] = new ArrayPut(); system["ne"] = new NotEqual(); system["eq"] = new Equal(); system["or"] = new Or(); system["ifelse"] = new IfElse(); system["if"] = new If(); system["neg"] = new Neg(); system["not"] = new Not(); system["sqrt"] = new Sqrt(); system["lt"] = new LessThan(); system["ge"] = new GreaterOrEqualThan(); dictStack.Push(system); var graphics = new Dictionary <string, IOperation>(); graphics["newpath"] = new NewPath(pageState); graphics["closepath"] = new ClosePath(pageState); graphics["fillpath"] = new FillPath(pageState); graphics["setgray"] = new SetGray(pageState); graphics["setrgbcolor"] = new SetRGB(pageState); graphics["setlinewidth"] = new SetLineWidth(pageState); graphics["fill"] = new FillPath(pageState); graphics["showpage"] = new ShowPage(pageState); graphics["moveto"] = new MoveTo(pageState); graphics["lineto"] = new LineTo(pageState); graphics["rlineto"] = new RelativeLineTo(pageState); graphics["gsave"] = new SaveGraphicsState(pageState); graphics["grestore"] = new RestoreGraphicsState(pageState); graphics["stroke"] = new StrokePath(pageState); graphics["curveto"] = new CurveTo(pageState); graphics["arc"] = new Arc(pageState); dictStack.Push(graphics); dictStack.Push(new Dictionary <string, IOperation>()); //execStack.Push(start); CodeParser.LoadCode(execStack, @" /findfont { pop (somefont) } def /scalefont { exch pop } def /setfont { pop } def /setlinecap { pop } def /srand { pop } def "); CodeParser.LoadCode(execStack, code); var state = new PreScriptState(stack, execStack, dictStack); while (execStack.Count > 0) { var operation = execStack.Pop(); operation.Process(state); } }
internal protected virtual T Visit(Substract node) { return(Visit(node as Expression)); }
protected override EP_VP1 Visit(Substract node) { node.Children[1].Visit(this); node.Children[0].Visit(this); return(this); }
public virtual T Visit(Substract substract) { return(VisitBinaryExpression(substract)); }
private bool ReadToken(out Token token) { var currentState = InputState.Start; var tokenStr = new StringBuilder(); for (; _pos < _expression.Length; _pos++) { var symbol = _expression[_pos]; var pair = _table.Get(new KeyValuePair <InputState, char>(currentState, symbol)); if (pair.Key == InputState.Start) { continue; } if (pair.Key == InputState.Finish) { switch (pair.Value) { case OutputState.Add: token = new Add(); Step(); return(true); case OutputState.Sub: token = new Substract(); Step(); return(true); case OutputState.Mul: token = new Multiply(); return(true); case OutputState.Div: token = new Divide(); Step(); return(true); case OutputState.Pow: token = new Power(); Step(); return(true); case OutputState.LBr: token = new OpenBracket(); Step(); return(true); case OutputState.RBr: token = new CloseBracket(); Step(); return(true); case OutputState.LPart: token = new Digit(tokenStr.ToString()); return(true); case OutputState.RPart: token = new Digit(tokenStr.ToString()); return(true); } } currentState = pair.Key; tokenStr.Append(symbol); } token = null; return(false); }
public override object Visit(Substract substract) { ValidateBinaryExpression(substract); return(base.Visit(substract)); }