public void testFailingSubtractnumbers() { // Normal additions Assert.That("3329", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(43, 4))); Assert.That("52305", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(5230, 25))); Assert.That("-2", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(33, -35))); // Edge cases [-1, 0, 1, maxvalue, minvalue] // 1 Assert.That("326", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(1, 5))); // On left Assert.That("54", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(543, 1))); // On right Assert.That("32343", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(1, 1))); // On both Assert.That("32343", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(1, 0))); // with 0 Assert.That("32343", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(1, -1))); // with -1 Assert.That("32343", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(1, Int32.MaxValue))); // with maxvalue Assert.That("32343", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(1, Int32.MinValue))); // with minvalue // -1 Assert.That("-34", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(-1, -3))); // On left Assert.That("-3", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(-532, -1))); // On right Assert.That("52", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(-1, -1))); // On both Assert.That("52", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(-1, 1))); // with 1 Assert.That("52", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(-1, 0))); // With 0 Assert.That("52", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(-1, Int32.MaxValue))); // with maxvalue Assert.That("52", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(-1, Int32.MinValue))); // with minvalue // 0 Assert.That("432", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(0, 321))); // On left Assert.That("32", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(0, 4242))); // On right Assert.That("551", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(0, 12121))); // on both Assert.That("551", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(0, 1))); // with 1 Assert.That("551", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(0, -1))); // with -1 Assert.That("551", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(0, Int32.MaxValue))); // with maxvalue Assert.That("551", Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(0, Int32.MinValue))); // with minvalue // maxvalue Assert.That(Int32.MinValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, 3))); // On left Assert.That(Int32.MinValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(3, Int32.MaxValue))); // On right Assert.That(Int32.MinValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, Int32.MaxValue))); // On both Assert.That(Int32.MinValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, 1))); // with 1 Assert.That(Int32.MinValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, 0))); // with 0 Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, -1))); // with -1 Assert.That(Int32.MinValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, Int32.MinValue))); // with minvalue // minvalue Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, -3))); // On left Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(3, Int32.MinValue))); // On right Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, Int32.MinValue))); // On both Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, 1))); // with 1 Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, 0))); // with 0 Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, -1))); // with -1 Assert.That(Int32.MaxValue.ToString(), Is.Not.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, Int32.MaxValue))); // with maxvalue }
public void testPassingSubtractnumbers() { // Normal subtractions Assert.That("2", Is.EqualTo(CalculatorAppCore.subtractnumbers(4, 2))); Assert.That("55", Is.EqualTo(CalculatorAppCore.subtractnumbers(30, -25))); Assert.That("260", Is.EqualTo(CalculatorAppCore.subtractnumbers(265, 5))); // Edge cases [-1, 0, 1, maxvalue, minvalue] // cases of 1 Assert.That("-4", Is.EqualTo(CalculatorAppCore.subtractnumbers(1, 5))); // On left Assert.That("2", Is.EqualTo(CalculatorAppCore.subtractnumbers(3, 1))); // On right Assert.That("0", Is.EqualTo(CalculatorAppCore.subtractnumbers(1, 1))); // On both Assert.That("1", Is.EqualTo(CalculatorAppCore.subtractnumbers(1, 0))); // with 0 Assert.That("2", Is.EqualTo(CalculatorAppCore.subtractnumbers(1, -1))); // with -1 Assert.That(((Int64)1 - (Int64)Int32.MaxValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(1, Int32.MaxValue))); // with maxvalue Assert.That(((Int64)1 - (Int64)Int32.MinValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(1, Int32.MinValue))); // with minvalue // -1 Assert.That("2", Is.EqualTo(CalculatorAppCore.subtractnumbers(-1, -3))); // On left Assert.That("79", Is.EqualTo(CalculatorAppCore.subtractnumbers(78, -1))); // On right Assert.That("0", Is.EqualTo(CalculatorAppCore.subtractnumbers(-1, -1))); // On both Assert.That("-2", Is.EqualTo(CalculatorAppCore.subtractnumbers(-1, 1))); // with 1 Assert.That("-1", Is.EqualTo(CalculatorAppCore.subtractnumbers(-1, 0))); // with 0 Assert.That((-(Int64)1 - (Int64)Int32.MaxValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(-1, Int32.MaxValue))); // with maxvalue Assert.That((-(Int64)1 - (Int64)Int32.MinValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(-1, Int32.MinValue))); // with minvalue // 0 Assert.That("-4", Is.EqualTo(CalculatorAppCore.subtractnumbers(0, 4))); // On left Assert.That("-2", Is.EqualTo(CalculatorAppCore.subtractnumbers(-2, 0))); // On right Assert.That("0", Is.EqualTo(CalculatorAppCore.subtractnumbers(0, 0))); // On both Assert.That("-1", Is.EqualTo(CalculatorAppCore.subtractnumbers(0, 1))); // with 1 Assert.That("1", Is.EqualTo(CalculatorAppCore.subtractnumbers(0, -1))); // with -1 Assert.That(((Int64)Int32.MaxValue * -1).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(0, Int32.MaxValue))); // with maxvalue Assert.That(((Int64)Int32.MinValue * -1).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(0, Int32.MinValue))); // with minvalue // maxvalue Assert.That(((Int64)Int32.MaxValue - (Int64)3).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, 3))); // On left Assert.That((((Int64)Int32.MaxValue * -1) + (Int64)45).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(45, Int32.MaxValue))); // On right Assert.That(((Int64)Int32.MaxValue - (Int64)Int32.MaxValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, Int32.MaxValue))); // On both Assert.That(((Int64)Int32.MaxValue - -(Int64)1).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, -1))); // with -1 Assert.That(((Int64)Int32.MaxValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, 0))); // with 0 Assert.That(((Int64)Int32.MaxValue - (Int64)1).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, 1))); // with 1 Assert.That(((Int64)Int32.MaxValue - (Int64)Int32.MinValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MaxValue, Int32.MinValue))); // with minvalue // minvalue Assert.That(((Int64)Int32.MinValue - -(Int64)3).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, -3))); // On left Assert.That((-(Int64)8 + ((Int64)Int32.MinValue * -1)).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(-8, Int32.MinValue))); // On right Assert.That(((Int64)Int32.MinValue - (Int64)Int32.MinValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, Int32.MinValue))); // On both Assert.That(((Int64)Int32.MinValue - (Int64)1).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, 1))); // with 1 Assert.That(((Int64)Int32.MinValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, 0))); // with 0 Assert.That(((Int64)Int32.MinValue - -(Int64)1).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, -1))); // with -1 Assert.That(((Int64)Int32.MinValue - (Int64)Int32.MaxValue).ToString(), Is.EqualTo(CalculatorAppCore.subtractnumbers(Int32.MinValue, Int32.MaxValue))); // with maxvalue }
static void Main(string[] args) { Console.WriteLine( "1. Add two numbers\n" + "2. Subtract two numbers\n" + "3. Multiply two numbers\n" + "4. Divide two numbers\n" + "Please select option: "); try // Exception catch for parsing from string to int { string option = Console.ReadLine(); int intOption = Int32.Parse(option); Console.WriteLine("Enter first number:"); string i1 = Console.ReadLine(); int inti1 = Int32.Parse(i1); Console.WriteLine("Enter second number:"); string i2 = Console.ReadLine(); int inti2 = Int32.Parse(i2); switch (intOption) { case 1: Console.WriteLine(i1 + " + " + i2 + " = " + CalculatorAppCore.addnumbers(inti1, inti2)); break; case 2: Console.WriteLine(i1 + " - " + i2 + " = " + CalculatorAppCore.subtractnumbers(inti1, inti2)); break; case 3: Console.WriteLine(i1 + " * " + i2 + " = " + CalculatorAppCore.multiplynumbers(inti1, inti2)); break; case 4: Console.WriteLine(i1 + " / " + i2 + " = " + CalculatorAppCore.dividenumbers(inti1, inti2)); break; default: Console.WriteLine("Please select from given options"); break; } } catch (ArgumentNullException) // If input is null { Console.WriteLine("Please enter a value\n"); } catch (FormatException) // If input is not in the correct format. { Console.WriteLine("Please enter a valid value\n"); } catch (OverflowException) // If input represents a number less than MinValue or greater than MaxValue. { Console.WriteLine("Please enter a number between " + Int32.MaxValue + " and " + Int32.MinValue + "\n"); } catch (DivideByZeroException) // If divide is chosen, and i2 is 0 { Console.WriteLine("Please dont divide by 0\n"); } catch (Exception) // If something else happens { Console.WriteLine("There was an error\n"); } }