diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..c2973278 Binary files /dev/null and b/.DS_Store differ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..09799671 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: csharp +solution: TravisCI.sln +branches: + only: + - master +install: + - nuget restore TravisCI.sln +script: + - msbuild /p:Configuration=Release TravisCI.sln + - mono ./packages/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./Tests/bin/Release/Tests.dll diff --git a/Console/Program.cs b/Console/Program.cs index b3fcdf6a..f0c618ae 100644 --- a/Console/Program.cs +++ b/Console/Program.cs @@ -84,7 +84,7 @@ public static double Divide(string x, string y) // Implement this method following a similar pattern as above public static double Power(string x, string y) { - throw new NotImplementedException(); + return Math.Pow(double.Parse(x), double.Parse(y)); } } diff --git a/Tests/UnitTests.cs b/Tests/UnitTests.cs index 84cde036..9e63aee7 100644 --- a/Tests/UnitTests.cs +++ b/Tests/UnitTests.cs @@ -31,5 +31,100 @@ public void Add_Null() } // Implement 3 tests per operation, following a similar pattern as above + [Test] + public void Subtract_ValidZach() + { + Assert.AreEqual(-1, Program.Subtract("1", "2")); + Assert.AreEqual(1, Program.Subtract("3", "2")); + Assert.AreEqual(-2, Program.Subtract("5", "7")); + } + + [Test] + public void Subtract_InvalidZach() + { + Assert.Throws(() => Program.Subtract("1", "a")); + Assert.Throws(() => Program.Subtract("a", "1")); + Assert.Throws(() => Program.Subtract("a", "a")); + } + + [Test] + public void Subtract_NullZach() + { + Assert.Throws(() => Program.Subtract("1", null)); + Assert.Throws(() => Program.Subtract(null, "1")); + Assert.Throws(() => Program.Subtract(null, null)); + } + + [Test] + public void Multiply_ValidZach() + { + Assert.AreEqual(2, Program.Multiply("1", "2")); + Assert.AreEqual(6, Program.Multiply("3", "2")); + Assert.AreEqual(35, Program.Multiply("5", "7")); + } + + [Test] + public void Multiply_InvalidZach() + { + Assert.Throws(() => Program.Multiply("1", "a")); + Assert.Throws(() => Program.Multiply("a", "1")); + Assert.Throws(() => Program.Multiply("a", "a")); + } + + [Test] + public void Multiply_NullZach() + { + Assert.Throws(() => Program.Multiply("1", null)); + Assert.Throws(() => Program.Multiply(null, "1")); + Assert.Throws(() => Program.Multiply(null, null)); + } + + [Test] + public void Divide_ValidZach() + { + Assert.AreEqual(2, Program.Divide("2", "1")); + Assert.AreEqual(1.5, Program.Divide("3", "2")); + Assert.AreEqual(1, Program.Divide("5", "5")); + } + + [Test] + public void Divide_InvalidZach() + { + Assert.Throws(() => Program.Divide("1", "a")); + Assert.Throws(() => Program.Divide("a", "1")); + Assert.Throws(() => Program.Divide("a", "a")); + } + + [Test] + public void Divide_NullZach() + { + Assert.Throws(() => Program.Divide("1", null)); + Assert.Throws(() => Program.Divide(null, "1")); + Assert.Throws(() => Program.Divide(null, null)); + } + + [Test] + public void Power_ValidZach() + { + Assert.AreEqual(1, Program.Power("1", "2")); + Assert.AreEqual(9, Program.Power("3", "2")); + Assert.AreEqual(78125, Program.Power("5", "7")); + } + + [Test] + public void Power_InvalidZach() + { + Assert.Throws(() => Program.Power("1", "a")); + Assert.Throws(() => Program.Power("a", "1")); + Assert.Throws(() => Program.Power("a", "a")); + } + + [Test] + public void Power_NullZach() + { + Assert.Throws(() => Program.Power("1", null)); + Assert.Throws(() => Program.Power(null, "1")); + Assert.Throws(() => Program.Power(null, null)); + } } }