public void AddTest() { Assert.AreEqual(4.5, mathlib.Add(1.5, 3.0), errorFactor); //Assert.AreEqual(X, mathlib.Method(a, b)); // X is chosen as answer, a and b are defined in the class lib Assert.AreEqual(9.0, mathlib.Add(4.5, 4.5), errorFactor); Assert.AreEqual(1.4, mathlib.Add(2.7, -1.3), errorFactor); //", 0.1" added at the end as a margin of error }
static void Main(string[] args) { "this is a test".Print(); // shows how to print any message from the extensions class Console.WriteLine($"2 ^ 3 = {2.Power(3)}"); Console.WriteLine($"3 squared is {3.Squared()}"); // using extension method Console.WriteLine($"3 cubed is {3.Cubed()}"); // using extention method var mathlib = new MathLib(); // showing the connection between program and class Console.WriteLine($"12 + 3 = {mathlib.Add(12,3)}"); Console.WriteLine($"12 - 3 = {mathlib.Subtract(12, 3)}"); Console.WriteLine($"12 * 3 = {mathlib.Multiply(12, 3)}"); Console.WriteLine($"12 / 3 = {mathlib.Divide(12, 3)}"); Console.WriteLine($"12 % 3 = {mathlib.Modulo(12, 3)}"); Console.WriteLine($"12 ^ 3 = {mathlib.Power(12, 3)}"); Console.WriteLine($"About is {mathlib.About}"); }
public IActionResult DoneCalculation(MathOperation model) { switch (model.Operator) { case "Plus": model.Result = MathLib.Add(Convert.ToDecimal(model.LeftOperand), Convert.ToDecimal(model.RightOperand)); break; case "Minus": model.Result = MathLib.subtract(Convert.ToDecimal(model.LeftOperand), Convert.ToDecimal(model.RightOperand)); break; case "Divided by": model.Result = MathLib.Divide(Convert.ToDecimal(model.LeftOperand), Convert.ToDecimal(model.RightOperand)); break; case "Times": model.Result = MathLib.Multiply(Convert.ToDecimal(model.LeftOperand), Convert.ToDecimal(model.RightOperand)); break; default: break; } return(View(model)); }
static void Main(string[] args) { //extension method for Console WriteLine "This is a test".Print(); //extension method using two parameters Console.WriteLine($"2 ^ 3 {2.Power(3)}"); //using extension method First thing we did Console.WriteLine($"3 squared is {3.Squared()}"); //create instance of Math Library var mathLib = new MathLib(); //confirming connection with console app and library //Console.WriteLine($" About is {mathLib.About}"); //Test Methods in Console Project by printing Console.WriteLine($"12 + 3 {mathLib.Add(12, 3)}"); Console.WriteLine($"12 - 3 {mathLib.Subtract(12, 3)}"); Console.WriteLine($"12 * 3 {mathLib.Multiply(12, 3)}"); Console.WriteLine($"12 % 3 {mathLib.Modulo(12, 3)}"); Console.WriteLine($"12 ^ 3 {mathLib.Power(12, 3)}"); }
static void Main(string[] args) { //remember static lets us do the below without creating and instance for 'Mathlib', we can directly reference it var oneplustwo = MathLib.Add(1, 2); var sevenminustwo = MathLib.Sub(7, 2); var twoxtwo = MathLib.Product(2, 2); var tendividetwo = MathLib.Divide(10, 2); var twelvemodulothree = MathLib.Modulo(12, 3); }
static void Main(string[] args) { var OnePlusTwo = MathLib.Add(1, 2); var OneLessTwo = MathLib.Subtract(1, 2); var OneTimesTwo = MathLib.Multiply(1, 2); var OneDivideTwo = MathLib.Divide(1, 2); var OneModTwo = MathLib.Modulo(5, 3); var mod = 5 % 3; Console.WriteLine($"{OneModTwo} {mod}"); }
static void Main(string[] args) { "this is a test".print(); Console.WriteLine($"3 squarded is {3.Squared()}"); Console.WriteLine($"2 ^ 3 is {2.Power(3)}"); // down below is creating an instance so we can use it in our program. var mathLib = new MathLib(); Console.WriteLine($"12 + 3 = {mathLib.Add(12, 3)}"); Console.WriteLine($"12 - 3 = {mathLib.Subtract(12, 3)}"); Console.WriteLine($"12 * 3 = {mathLib.Multiply(12, 3)}"); Console.WriteLine($"12 / 2 = {mathLib.Divide(12, 2)}"); Console.WriteLine($"12 % 3 = {mathLib.Modulo(12, 3)}"); Console.WriteLine($"12 ^ 3 = {mathLib.Power(12, 3)}"); Console.WriteLine($"add is {mathLib.about}"); }
static void Main(string[] args) { var mathLib = new MathLib(); Console.WriteLine($" About: {mathLib.About}"); // MathLib practice contd. Created math functions in MathLib.cs Console.WriteLine($"12 + 3 = {mathLib.Add(12, 3)}"); Console.WriteLine($"12 - 3 = {mathLib.Subtract(12, 3)}"); Console.WriteLine($"12 * 3 = {mathLib.Multiply(12, 3)}"); Console.WriteLine($"12 / 3 = {mathLib.Divide(12, 3)}"); Console.WriteLine($"12 % 3 = {mathLib.Modulo(12, 3)}"); Console.WriteLine($"12 ^ 3 = {mathLib.Power(12, 3)}"); //MathLib practice. Extension Method example Console.WriteLine($" 3 squared is {3.Squared()}"); Console.WriteLine($" 2 ^ 3 is {2.Power(3)}"); "This is a test".Print(); }
public void Add() { var result = _sut.Add(2, 3); Assert.Equal(5, result); }
public static void Main() { MathLib mathObj = new MathLib(); Console.WriteLine(mathObj.Add(7, 8)); }
static void Main(string[] args) { MathLib obj = new MathLib(); Console.WriteLine("****************************************************Math Application****************************************************"); Console.WriteLine("If you want to enter numbers in Integer Press 1 or Press 2 for double :"); int c = Convert.ToInt32(Console.ReadLine()); if (c == 1) { Console.WriteLine("Enter Two Integer Numbers :"); Console.Write("Number 1: "); int num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Number 2: "); int num2 = Convert.ToInt32(Console.ReadLine()); Console.Write("Press Corrosponding Numbers : \n Addition => 1 \t Substraction => 2 \t Multiplication => 3 \t Division => 4 \t Modulus Operation => 5 \t Your choice : "); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: int sum = obj.Add(num1, num2); Console.WriteLine("Addition of two numbers is : " + sum); break; case 2: int sub = obj.Subtract(num1, num2); Console.WriteLine("Subtraction of two numbers is : " + sub); break; case 3: int mul = obj.Multiply(num1, num2); Console.WriteLine("Division of two numbers is : " + mul); break; case 4: int div = obj.Divide(num1, num2); Console.WriteLine("Multiplication of two numbers is : " + div); break; case 5: int mod = obj.Modulus(num1, num2); Console.WriteLine("Modulus of two numbers is : " + mod); break; default: Console.WriteLine("The Input is wrong."); break; } } else if (c == 2) { Console.WriteLine("Enter Two Floating Numbers :"); Console.Write("Number 1: "); double num1 = Convert.ToDouble(Console.ReadLine()); Console.Write("Number 2: "); double num2 = Convert.ToDouble(Console.ReadLine()); Console.Write("Press Corrosponding Numbers : \n Addition => 1 \t Substraction => 2 \t Multiplication => 3 \t Division => 4 \t Modulus Operation => 5 \t Your choice : "); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: double sum = obj.FAdd(num1, num2); Console.WriteLine("Addition of two numbers is : " + sum); break; case 2: double sub = obj.FSubtract(num1, num2); Console.WriteLine("Substraction of two numbers is : " + sub); break; case 3: double mul = obj.FMultiply(num1, num2); Console.WriteLine("Multiplication of two numbers is : " + mul); break; case 4: double div = obj.FDivide(num1, num2); Console.WriteLine("Division of two numbers is : " + div); break; case 5: double mod = obj.FModulus(num1, num2); Console.WriteLine("Modulus of two numbers is : " + mod); break; default: Console.WriteLine("The Input is wrong."); break; } } else { Console.WriteLine("The Entered input is wrong."); } Console.ReadKey(); }
public string Add(decimal left, decimal right) { decimal result = MathLib.Add(left, right); return($"{left} plus {right} equals {result}"); }
public void AdditionTestEqualIntArray(int[] nums, int expected) { var result = MathLib.Add(nums); Assert.AreEqual(result, expected); }
public void AdditionTestIntEqual(int numA, int numB, int expected) { var result = MathLib.Add(numA, numB); Assert.AreEqual(result, expected); }
public void AddTest() { Assert.AreEqual(4.5, mathlib.Add(1.5, 3.0)); Assert.AreEqual(9, mathlib.Add(4.5, 4.5)); Assert.AreEqual(1.4, mathlib.Add(2.7, -1.3));
//public static long combine(long input) //{ // int sum = 0; // int[] output = Array.ConvertAll(input.ToString().ToCharArray(), element => (int)char.GetNumericValue(element)); // for (int i = 0; i < output.Length; i++) // { // sum += output[i]; // } // return sum; //} public static int Calculate(string calculation) { int output = 0; if (calculation.Contains('x')) { int product = 1; List <string> Factors = calculation.Split('x').ToList <string>(); Factors.ForEach(delegate(string number) { if (int.TryParse(number, out int num)) { product = MathLib.Multiply(product, num); } } ); output += product; } if (calculation.Contains('/')) { int product = 1; List <string> Factors = calculation.Split('/').ToList <string>(); try { output += MathLib.Divide(int.Parse(Factors[0]), int.Parse(Factors[1])); } catch (Exception e) { throw new Exception("Cant divide by 0."); } } if (calculation.Contains('+')) { int sum = 0; List <string> Adds = calculation.Split('+').ToList <string>(); Adds.ForEach(delegate(string number) { if (int.TryParse(number, out int num)) { sum = MathLib.Add(sum, num); } } ); output += sum; } if (calculation.Contains('-') && calculation[0] != '-') { int sum = 0; List <string> Adds = calculation.Split('-').ToList <string>(); sum += int.Parse(Adds[0]); for (int i = 1; i < Adds.Count; i++) { if (int.TryParse(Adds[i], out int num)) { sum = MathLib.Subtract(sum, num); } } output += sum; } if (calculation.Contains('%')) { List <string> Factors = calculation.Split('%').ToList <string>(); output += MathLib.Modulus(int.Parse(Factors[0]), int.Parse(Factors[1])); } return(output); }
public string Add(decimal valueone, decimal valuetwo) { return($"{MathLib.Add(valueone, valuetwo)}"); }
public void AddTest() { Assert.AreEqual(4.5, mathlib.Add(1.5, 3.0), errorFactor); Assert.AreEqual(9, mathlib.Add(4.5, 4.5), errorFactor); Assert.AreEqual(1.4, mathlib.Add(2.7, -1.3), errorFactor); }