Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
name: 'Run App <last name>, <first name>'
name: "Run App Clausen"

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
17 changes: 17 additions & 0 deletions .github/workflows/run-app.yaml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions CalculatorTests/CalculatorTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MSTest" Version="3.6.4" />
</ItemGroup>

<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Console\Console.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions CalculatorTests/MSTestSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
44 changes: 44 additions & 0 deletions CalculatorTests/ProgramTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
10 changes: 10 additions & 0 deletions CalculatorTests/Test1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace CalculatorTests;

[TestClass]
public sealed class Test1
{
[TestMethod]
public void TestMethod1()
{
}
}
58 changes: 37 additions & 21 deletions Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
6 changes: 3 additions & 3 deletions Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ 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"));
Assert.AreEqual(12, Program.Add("5", "7"));
}

[TestMethod]
public void Add_Invalid_Patino()
public void Add_Invalid_Clausen()
{
Assert.ThrowsException<FormatException>(() => Program.Add("1", "a"));
Assert.ThrowsException<FormatException>(() => Program.Add("a", "1"));
Assert.ThrowsException<FormatException>(() => Program.Add("a", "a"));
}

[TestMethod]
public void Add_Null_Patino()
public void Add_Null_Clausen()
{
Assert.ThrowsException<ArgumentNullException>(() => Program.Add("1", null));
Assert.ThrowsException<ArgumentNullException>(() => Program.Add(null, "1"));
Expand Down
4 changes: 1 addition & 3 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
"version": "9.0.311"
}
}