public static void Main(string[] args) { MathNode[] nodes = Parser.Parse(args); Fraction result = MathRunner.Calculate(nodes); Console.WriteLine("= " + result.ToConsoleOutput()); }
/// <summary> /// Use the following to run in a console: /// ActionOneConsole.exe --Add --Value1 1 --Value2 2 /// ActionOneConsole.exe --Multiply --Value1 2 --Value2 2 /// ActionOneConsole.exe --Subtract --Value1 2 --Value2 3 /// </summary> /// <param name="args"></param> static void Main(string[] args) { #region Logging Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Console() .CreateLogger(); #endregion var mathRunner = new MathRunner(); Parser.Default.ParseArguments <Options>(args) .WithParsed(o => { Logging(o); if (o.Add) { mathRunner.RunMethod(o.Value1, o.Value2, Addition.Add); } else if (o.Multiply) { mathRunner.RunMethod(o.Value1, o.Value2, Multiplication.Multiply); } else if (o.Subtract) { mathRunner.RunMethod(o.Value1, o.Value2, Subtraction.Substract); } }); }
public void Parse3Subtract() { string[] values = new string[] { "3_1/2", "-", "1_1/2" }; MathNode[] parsed = Parser.Parse(values); Fraction result = MathRunner.Calculate(parsed); Fraction expected = Fraction.FromString("2"); Assert.Equal(expected, result); }
public void InvalidInputThrowsTrailingFraction() { string[] values = new string[] { "3_1/2", "+", "1_1/2", "1/4" }; MathNode[] parsed = Parser.Parse(values); Exception ex = Assert.Throws <InvalidOperationException>(() => MathRunner.Calculate(parsed)); }
public void DivideByZero() { string[] values = new string[] { "3", "/", "0" }; MathNode[] parsed = Parser.Parse(values); Exception ex = Assert.Throws <InvalidOperationException>(() => MathRunner.Calculate(parsed)); }