/// <summary> /// Use the following to run in a console: /// FuncOneConsole.exe --Add --Value1 1 --Value2 2 /// FuncOneConsole.exe --Multiply --Value1 2 --Value2 2 /// FuncOneConsole.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 CalculatorLib.Calculator(); Parser.Default.ParseArguments <Options>(args) .WithParsed(o => { Logging(o); int result = 0; if (o.Add) { result = mathRunner.Calculate(o.Value1, o.Value2, Addition.Add); } else if (o.Multiply) { result = mathRunner.Calculate(o.Value1, o.Value2, Multiplication.Multiply); } else if (o.Subtract) { result = mathRunner.Calculate(o.Value1, o.Value2, Subtraction.Substract); } Log.Information("Result: " + result); }); }
static void Main(string[] args) { CalculatorLib.Calculator obj = new CalculatorLib.Calculator(); int result = obj.Add(10, 20); Console.WriteLine(result); }
static void Main(string[] args) { var calc = new CalculatorLib.Calculator(); var result = calc.Sum(10, 20); Console.WriteLine(result); Console.ReadLine(); }
static void Main(string[] args) { CalculatorLib.Calculator c = new CalculatorLib.Calculator(); while (true) { c.Main(); } }
static void Main(string[] args) { // Compiler will reflect CalculatorLib metadata CalculatorLib.Calculator obj = new CalculatorLib.Calculator(); int result = obj.Add(10, 20); Console.WriteLine(result); }
public void TestMedianEvens10TThrough30() { double[] arr = { 20, 18, 22, 16, 24, 14, 26, 12, 28, 10, 30 }; double expected = (double)20; var calc = new CalculatorLib.Calculator(); double actual = calc.Median(arr); Assert.Equal(expected, actual); }
public void TestMedian1Through10() { double[] arr = { 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 }; double expected = (double)5.5; var calc = new CalculatorLib.Calculator(); double actual = calc.Median(arr); Assert.Equal(expected, actual); }
public void TestMean1Through10() { double[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; double expected = 5.5; var calc = new CalculatorLib.Calculator(); double actual = calc.Mean(arr); Assert.Equal(expected, actual); }
static void Main(string[] args) { Console.WriteLine("Looking for CalcInput.txt."); if (!(File.Exists("CalcInput.txt"))) {//Terminates the program if CalcInput.txt does not exist. Console.WriteLine("CalcInput.txt could not be found."); System.Environment.Exit(1); } Console.WriteLine("Opening CalcInput.txt and reading in values."); StreamReader textReader = File.OpenText("CalcInput.txt"); //This program will only read in up to 100 lines double[] arr = new double[100]; int count = 0; while (!textReader.EndOfStream) { try {//This try catch block converts each line to a double arr[count] = Convert.ToDouble(textReader.ReadLine()); } catch (Exception ex) {//If the line cannot be converted, the program terminates. Console.WriteLine($"{ex.GetType()} cannot be converted to a double. Terminating program."); System.Environment.Exit(1); } count++; } textReader.Close(); Array.Resize <double>(ref arr, count); var calc = new CalculatorLib.Calculator(); //Any file called "CalcOutput.txt" will be overwritten by this program. StreamWriter textWriter = File.CreateText("CalcOutput.txt"); textWriter.WriteLine("The following array of doubles \"arr\" was read in: "); for (int i = 0; i < arr.Length; i++) { textWriter.Write($"{arr[i]}\t"); } textWriter.WriteLine(); textWriter.WriteLine(); Console.WriteLine("Finding the mean."); textWriter.WriteLine($"The mean of arr is {Math.Round(calc.Mean(arr),2)}"); textWriter.WriteLine(); Console.WriteLine("Finding the median."); textWriter.WriteLine($"The median of arr is {calc.Median(arr)}"); textWriter.Close(); Console.WriteLine("Please see CalcOutput.txt for mean and median."); }
public void TestDiv2And3() { double a = 2; double b = 3; double expected = (double)2 / (double)3; var calc = new CalculatorLib.Calculator(); double actual = calc.Div(a, b); Assert.Equal(expected, actual); }
public void TestAdd2And2() { double a = 2; double b = 2; double expected = 4; var calc = new CalculatorLib.Calculator(); double actual = calc.Add(a, b); Assert.Equal(expected, actual); }
public void TestMul2And3() { double a = 2; double b = 3; double expected = 6; var calc = new CalculatorLib.Calculator(); double actual = calc.Mul(a, b); Assert.Equal(expected, actual); }
public void Add1and1equals3() { //Arrange var calc = new CalculatorLib.Calculator(); int expected = 3; //Act int result = calc.Add(1, 1); //Assert Assert.AreEqual(expected, result); }
static void Main(string[] args) { var calculator = new CalculatorLib.Calculator(10); Console.WriteLine("Введите число а: "); int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Введите число b: "); int b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Сумма равна "); Console.WriteLine(calculator.Add(a, b)); }