static void Main(String[] args) { Calculator myCalculator = new Calculator(); int T = 4; string[] stringArray = new string[] { "3 5", "2 4", "-1 -2", "-1 3" }; while (T-- > 0) { //string[] num = Console.ReadLine().Split(); string[] num = stringArray[T].Split(); int n = int.Parse(num[0]); int p = int.Parse(num[1]); try{ int ans = myCalculator.power(n, p); Console.WriteLine(ans); } catch (Exception e) { Console.WriteLine(e.Message); } } Console.ReadKey(); }
public void Test_Method() { // Arrange int[][] inputs = { new int[] { 3, 5 }, new int[] { 2, 4 }, new int[] { -1, -2 }, new int[] { -1, 3 } }; List <int> successResults = new List <int>(); List <string> exceptionResults = new List <string>(); try { for (int i = 0; i < inputs.Length; i++) { successResults.Add(Calculator.power(inputs[i][0], inputs[i][1])); } } catch (Exception ex) { exceptionResults.Add(ex.Message); } // Assert CollectionAssert.Contains(successResults, 243); CollectionAssert.Contains(successResults, 16); CollectionAssert.Contains(exceptionResults, "n and p should be non-negative"); }
static void Main(String[] args) { Calculator myCalculator = new Calculator(); Console.WriteLine("Type # of Test Cases"); int T = Int32.Parse(Console.ReadLine()); while (T-- > 0) { Console.WriteLine("Type values for n and p space separated"); string[] num = Console.ReadLine().Split(); int n = int.Parse(num[0]); int p = int.Parse(num[1]); try { int ans = myCalculator.power(n, p); Console.WriteLine(ans); } catch (Exception e) { Console.WriteLine(e.Message); } } }
//#45. run - error comes back saying no attribute for 'sqroot', so go to calculator file and add 'sqroot' function //#50. add a test - Power public void test_Power() { var calculator = new Calculator(); this.Equals(1, calculator.power(0, 0)); this.Equals(0, calculator.power(0, 1)); this.Equals(1, calculator.power(1, 1)); this.Equals(1, calculator.power(1, 2)); this.Equals(2, calculator.power(2, 1)); this.Equals(4, calculator.power(2, 2)); this.Equals(32, calculator.power(2, 5)); this.Equals(-32, calculator.power(-2, 5)); }
static void Main(String[] args){ Calculator myCalculator=new Calculator(); int T=Int32.Parse(Console.ReadLine()); while(T-->0){ string[] num = Console.ReadLine().Split(); int n = int.Parse(num[0]); int p = int.Parse(num[1]); try{ int ans=myCalculator.power(n,p); Console.WriteLine(ans); } catch(Exception e){ Console.WriteLine(e.Message); } }
public void MoreExceptionsTest1() { string[] testInput = new string[] { "3 5", "2 4", "-1 -2", "-1 3" }; string[] expectedResult = new string[] { "243", "16", "n and p should be non-negative", "n and p should be non-negative" }; Calculator myCalculator = new Calculator(); for (int x = 0; x < testInput.Length; x++) { string[] num = testInput[x].Split(); int n = int.Parse(num[0]); int p = int.Parse(num[1]); using (var sw = new StringWriter()) { Console.SetOut(sw); try { int ans = myCalculator.power(n, p); Console.WriteLine(ans); } catch (Exception e) { Console.WriteLine(e.Message); } string actualResult = sw.ToString().Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); Assert.AreEqual(expectedResult[x], actualResult); } } }
static void Main(String[] args) { Calculator myCalculator = new Calculator(); int T = int.Parse(Console.ReadLine()); while (T-- > 0) { string[] num = Console.ReadLine().Split(); int n = int.Parse(num[0]); int p = int.Parse(num[1]); try { int ans = myCalculator.power(n, p); Console.WriteLine(ans); } catch (Exception e) { Console.WriteLine(e.Message); } } }
static void Main(string[] args) { //Console.Write("Enter a letter: "); //string S = Console.ReadLine(); //try //{ // int converted = Convert.ToInt32(S); // Console.WriteLine(converted); //} //catch //{ // Console.WriteLine("Bad String"); //} Calculator myCalculator = new Calculator(); Console.WriteLine("Enter the number of test cases, followed 2 space seperated integers: "); int T = Int32.Parse(Console.ReadLine()); while (T-- > 0) { string[] num = Console.ReadLine().Split(); int n = int.Parse(num[0]); int p = int.Parse(num[1]); try { int ans = myCalculator.power(n, p); Console.WriteLine(ans); } catch (System.Exception e) { Console.WriteLine(e.Message); } } }
public void WhenIPressPower() { result = calculator.power(); }