diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64db9d16a..2b43e97bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: 'Run App , ' +name: "Run App Clausen" on: [push, pull_request] @@ -6,4 +6,12 @@ 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/.github/workflows/run-app.yaml b/.github/workflows/run-app.yaml new file mode 100644 index 000000000..f84d4d17c --- /dev/null +++ b/.github/workflows/run-app.yaml @@ -0,0 +1,17 @@ +name: 'Run App Clausen, Julia' + +on: [push, pull_request] + +jobs: + build-and-test: + runs-on: ubuntu-latest + steps: + - 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/CalculatorTests/CalculatorTests.csproj b/CalculatorTests/CalculatorTests.csproj new file mode 100644 index 000000000..14aa51c8a --- /dev/null +++ b/CalculatorTests/CalculatorTests.csproj @@ -0,0 +1,23 @@ + + + + net9.0 + latest + enable + enable + + + + + + + + + + + + + + + + diff --git a/CalculatorTests/MSTestSettings.cs b/CalculatorTests/MSTestSettings.cs new file mode 100644 index 000000000..aaf278c84 --- /dev/null +++ b/CalculatorTests/MSTestSettings.cs @@ -0,0 +1 @@ +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] diff --git a/CalculatorTests/ProgramTests.cs b/CalculatorTests/ProgramTests.cs new file mode 100644 index 000000000..5dac2e542 --- /dev/null +++ b/CalculatorTests/ProgramTests.cs @@ -0,0 +1,44 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using GithubActionsLab; // Namespace of your console app + +namespace CalculatorTests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void TestAdd_Clausen() + { + double result = Program.Add("2", "3"); + Assert.AreEqual(5, result); + } + + [TestMethod] + public void TestSubtract_Clausen() + { + double result = Program.Subtract("5", "3"); + Assert.AreEqual(2, result); + } + + [TestMethod] + public void TestMultiply_Clausen() + { + double result = Program.Multiply("4", "3"); + Assert.AreEqual(12, result); + } + + [TestMethod] + public void TestDivide_Clausen() + { + double result = Program.Divide("10", "2"); + Assert.AreEqual(5, result); + } + + [TestMethod] + public void TestPower_Clausen() + { + double result = Program.Power("2", "3"); + Assert.AreEqual(8, result); + } + } +} \ No newline at end of file diff --git a/CalculatorTests/Test1.cs b/CalculatorTests/Test1.cs new file mode 100644 index 000000000..6edafe9ae --- /dev/null +++ b/CalculatorTests/Test1.cs @@ -0,0 +1,10 @@ +namespace CalculatorTests; + +[TestClass] +public sealed class Test1 +{ + [TestMethod] + public void TestMethod1() + { + } +} diff --git a/Console/Program.cs b/Console/Program.cs index 56bb86061..5a2bbd10e 100644 --- a/Console/Program.cs +++ b/Console/Program.cs @@ -63,29 +63,45 @@ private static string GetInput(string prompt) return Console.ReadLine()?.Trim() ?? throw new InvalidOperationException(); } - public static double Add(string x, string y) - { - return double.Parse(x) + double.Parse(y); - } + public static double Add(string? x, string? y) +{ + if (x == null || y == null) + throw new ArgumentNullException(); - public static double Subtract(string x, string y) - { - return double.Parse(x) - double.Parse(y); - } + return double.Parse(x) + double.Parse(y); +} - public static double Multiply(string x, string y) - { - return double.Parse(x) * double.Parse(y); - } +public static double Subtract(string? x, string? y) +{ + if (x == null || y == null) + throw new ArgumentNullException(); - public static double Divide(string x, string y) - { - return double.Parse(x) / double.Parse(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) - { - return 0.0; - } +public static double Multiply(string? x, string? y) +{ + if (x == null || y == null) + throw new ArgumentNullException(); + + return double.Parse(x) * double.Parse(y); +} + +public static double Divide(string? x, string? y) +{ + if (x == null || y == null) + throw new ArgumentNullException(); + + return double.Parse(x) / double.Parse(y); +} + +public static double Power(string? x, string? y) +{ + if (x == null || y == null) + throw new ArgumentNullException(); + + double baseNum = double.Parse(x); + double exponent = double.Parse(y); + return Math.Pow(baseNum, exponent); } +} \ No newline at end of file diff --git a/Tests/UnitTests.cs b/Tests/UnitTests.cs index a2d3bd18e..04f11c011 100644 --- a/Tests/UnitTests.cs +++ b/Tests/UnitTests.cs @@ -4,7 +4,7 @@ namespace GithubActionsLab; public class Addition { [TestMethod] - public void Add_Valid_Patino() + public void Add_Valid_Clausen() { Assert.AreEqual(3, Program.Add("1", "2")); Assert.AreEqual(5, Program.Add("3", "2")); @@ -12,7 +12,7 @@ public void Add_Valid_Patino() } [TestMethod] - public void Add_Invalid_Patino() + public void Add_Invalid_Clausen() { Assert.ThrowsException(() => Program.Add("1", "a")); Assert.ThrowsException(() => Program.Add("a", "1")); @@ -20,7 +20,7 @@ public void Add_Invalid_Patino() } [TestMethod] - public void Add_Null_Patino() + public void Add_Null_Clausen() { Assert.ThrowsException(() => Program.Add("1", null)); Assert.ThrowsException(() => Program.Add(null, "1")); diff --git a/global.json b/global.json index 2ddda36c2..0dcaf0132 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,5 @@ { "sdk": { - "version": "8.0.0", - "rollForward": "latestMinor", - "allowPrerelease": false + "version": "9.0.311" } } \ No newline at end of file