diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64db9d16a..e01de4b52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,21 @@ -name: 'Run App , ' +name: 'Run App Kapaba, Defi' on: [push, pull_request] jobs: build-and-test: runs-on: ubuntu-latest + steps: - - run: echo "Hello, World!" + - uses: actions/checkout@v2 + + - name: install dotnet + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '8.x' + + - name: build + run: dotnet build + + - name: run unit tests + run: dotnet test \ No newline at end of file diff --git a/Console/Program.cs b/Console/Program.cs index 56bb86061..be4c11841 100644 --- a/Console/Program.cs +++ b/Console/Program.cs @@ -84,8 +84,12 @@ 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) { - return 0.0; + if (x == null || y == null) + throw new ArgumentNullException(); + + return Math.Pow(Convert.ToDouble(x), Convert.ToDouble(y)); } } diff --git a/README.md b/README.md index 7400b87d5..5b703cd77 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -[![Run App](https://github.com/kgerot/GithubActions/actions/workflows/run-app.yaml/badge.svg)](https://github.com/kgerot/GithubActions/actions/workflows/run-app.yaml) +[![Run App Kapaba, Defi](https://github.com/defimal/GithubActions/actions/workflows/ci.yml/badge.svg)](https://github.com/defimal/GithubActions/actions/workflows/ci.yml) # Do not submit a pull request to `kgerot/GithubActions` or `dteske/TraviCI`. Not following this instruction can ruin the lab for others, so pay attention. + I receive around 60 pull requests every semester and have to manually delete each request and action run. Your actions will automatically fail if you open a pull request # Github Actions Lab diff --git a/Tests/DivisionTests.cs b/Tests/DivisionTests.cs new file mode 100644 index 000000000..eff4883cc --- /dev/null +++ b/Tests/DivisionTests.cs @@ -0,0 +1,26 @@ +namespace GithubActionsLab; + +[TestClass] +public class Division +{ + [TestMethod] + public void Divide_Valid_Kapaba() + { + Assert.AreEqual(2, Program.Divide("4", "2")); + Assert.AreEqual(3, Program.Divide("9", "3")); + } + + [TestMethod] + public void Divide_Invalid_Kapaba() + { + Assert.ThrowsException(() => Program.Divide("a", "2")); + Assert.ThrowsException(() => Program.Divide("2", "b")); + } + + [TestMethod] + public void Divide_Null_Kapaba() + { + Assert.ThrowsException(() => Program.Divide(null, "2")); + Assert.ThrowsException(() => Program.Divide("2", null)); + } +} \ No newline at end of file diff --git a/Tests/MultiplicationTests.cs b/Tests/MultiplicationTests.cs new file mode 100644 index 000000000..257f0fcb5 --- /dev/null +++ b/Tests/MultiplicationTests.cs @@ -0,0 +1,27 @@ +namespace GithubActionsLab; + +[TestClass] +public class Multiplication +{ + [TestMethod] + public void Multiply_Valid_Kapaba() + { + Assert.AreEqual(6, Program.Multiply("2", "3")); + Assert.AreEqual(0, Program.Multiply("0", "5")); + Assert.AreEqual(-6, Program.Multiply("-2", "3")); + } + + [TestMethod] + public void Multiply_Invalid_Kapaba() + { + Assert.ThrowsException(() => Program.Multiply("a", "2")); + Assert.ThrowsException(() => Program.Multiply("2", "b")); + } + + [TestMethod] + public void Multiply_Null_Kapaba() + { + Assert.ThrowsException(() => Program.Multiply(null, "2")); + Assert.ThrowsException(() => Program.Multiply("2", null)); + } +} \ No newline at end of file diff --git a/Tests/PowerTests.cs b/Tests/PowerTests.cs new file mode 100644 index 000000000..98e439e9b --- /dev/null +++ b/Tests/PowerTests.cs @@ -0,0 +1,27 @@ +namespace GithubActionsLab; + +[TestClass] +public class PowerTests +{ + [TestMethod] + public void Power_Valid_Kapaba() + { + Assert.AreEqual(8, Program.Power("2", "3")); + Assert.AreEqual(1, Program.Power("5", "0")); + Assert.AreEqual(16, Program.Power("4", "2")); + } + + [TestMethod] + public void Power_Invalid_Kapaba() + { + Assert.ThrowsException(() => Program.Power("a", "2")); + Assert.ThrowsException(() => Program.Power("2", "b")); + } + + [TestMethod] + public void Power_Null_Kapaba() + { + Assert.ThrowsException(() => Program.Power(null, "2")); + Assert.ThrowsException(() => Program.Power("2", null)); + } +} \ No newline at end of file diff --git a/Tests/SubtractionTests.cs b/Tests/SubtractionTests.cs new file mode 100644 index 000000000..fa703c4a1 --- /dev/null +++ b/Tests/SubtractionTests.cs @@ -0,0 +1,27 @@ +namespace GithubActionsLab; + +[TestClass] +public class Subtraction +{ + [TestMethod] + public void Subtract_Valid_Kapaba() + { + Assert.AreEqual(1, Program.Subtract("3", "2")); + Assert.AreEqual(0, Program.Subtract("5", "5")); + Assert.AreEqual(-2, Program.Subtract("3", "5")); + } + + [TestMethod] + public void Subtract_Invalid_Kapaba() + { + Assert.ThrowsException(() => Program.Subtract("1", "a")); + Assert.ThrowsException(() => Program.Subtract("a", "1")); + } + + [TestMethod] + public void Subtract_Null_Kapaba() + { + Assert.ThrowsException(() => Program.Subtract(null, "1")); + Assert.ThrowsException(() => Program.Subtract("1", null)); + } +} \ No newline at end of file