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/Console.csproj b/Console/Console.csproj index 26c0ed8b..4f92f043 100644 --- a/Console/Console.csproj +++ b/Console/Console.csproj @@ -1,5 +1,5 @@  - + Debug diff --git a/Console/Console.sln b/Console/Console.sln new file mode 100644 index 00000000..f86d7d9a --- /dev/null +++ b/Console/Console.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.810.8 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Console.csproj", "{C5964EEF-DA27-4C98-B4D0-7F27767FE870}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C5964EEF-DA27-4C98-B4D0-7F27767FE870}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C5964EEF-DA27-4C98-B4D0-7F27767FE870}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C5964EEF-DA27-4C98-B4D0-7F27767FE870}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C5964EEF-DA27-4C98-B4D0-7F27767FE870}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E9E65B21-FC44-473C-AF97-180CE81CA355} + EndGlobalSection +EndGlobal diff --git a/Console/Program.cs b/Console/Program.cs index b3fcdf6a..ec001c8f 100644 --- a/Console/Program.cs +++ b/Console/Program.cs @@ -81,13 +81,17 @@ public static double Divide(string x, string y) return double.Parse(x) / double.Parse(y); } - // Implement this method following a similar pattern as above public static double Power(string x, string y) { - throw new NotImplementedException(); - } - } + double ret = 1; + for (int i = 0; i <= double.Parse(y); i++) { + ret *= double.Parse(x); + + } + return ret; + } + } } diff --git a/Tests/UnitTests.cs b/Tests/UnitTests.cs index 84cde036..149c8b5c 100644 --- a/Tests/UnitTests.cs +++ b/Tests/UnitTests.cs @@ -30,6 +30,81 @@ public void Add_Null() Assert.Throws(() => Program.Add(null, null)); } - // Implement 3 tests per operation, following a similar pattern as above + [Test] + public void Sub_Valid_Durante(){ + Assert.AreEqual(-1, Program.Subtract("1", "2")); + Assert.AreEqual(1, Program.Subtract("3", "2")); + Assert.AreEqual(3, Program.Subtract("10", "7")); + } + + [Test] + public void Sub_Invalid_Durante(){ + Assert.Throws(() => Program.Subtract("1", "a")); + Assert.Throws(() => Program.Subtract("a", "1")); + Assert.Throws(() => Program.Subtract("a", "a")); + } + [Test] + public void Sub_Null_Durante(){ + Assert.Throws(() => Program.Subtract("1", null)); + Assert.Throws(() => Program.Subtract(null, "1")); + Assert.Throws(() => Program.Subtract(null, null)); + } + + [Test] + public void Mult_Valid_Durante(){ + Assert.AreEqual(2, Program.Multiply("1", "2")); + Assert.AreEqual(0, Program.Multiply("0", "99")); + Assert.AreEqual(70, Program.Multiply("10", "7")); + } + [Test] + public void Mult_Invalid_Durante(){ + Assert.Throws(() => Program.Multiply("1", "a")); + Assert.Throws(() => Program.Multiply("a", "1")); + Assert.Throws(() => Program.Multiply("a", "a")); + } + [Test] + public void Mult_Null_Durante(){ + Assert.Throws(() => Program.Multiply("1", null)); + Assert.Throws(() => Program.Multiply(null, "1")); + Assert.Throws(() => Program.Multiply(null, null)); + } + + [Test] + public void Div_Valid_Durante(){ + Assert.AreEqual(.5, Program.Divide("1", "2")); + Assert.AreEqual(0, Program.Divide("0", "99")); + Assert.AreEqual(20, Program.Divide("100", "5")); + } + [Test] + public void Div_Invalid_Durante(){ + Assert.Throws(() => Program.Divide("1", "a")); + Assert.Throws(() => Program.Divide("a", "1")); + Assert.Throws(() => Program.Divide("a", "a")); + } + [Test] + public void Div_Null_Durante(){ + Assert.Throws(() => Program.Divide("1", null)); + Assert.Throws(() => Program.Divide(null, "1")); + Assert.Throws(() => Program.Divide(null, null)); + } + + [Test] + public void Pow_Valid_Durante(){ + Assert.AreEqual(0, Program.Power("0", "2")); + Assert.AreEqual(64, Program.Power("4", "2")); + Assert.AreEqual(81, Program.Power("3", "3")); + } + [Test] + public void Pow_Invalid_Durante(){ + Assert.Throws(() => Program.Power("1", "a")); + Assert.Throws(() => Program.Power("a", "1")); + Assert.Throws(() => Program.Power("a", "a")); + } + [Test] + public void Pow_Null_Durante(){ + Assert.Throws(() => Program.Power("1", null)); + Assert.Throws(() => Program.Power(null, "1")); + Assert.Throws(() => Program.Power(null, null)); + } } }