Skip to content
Open

Test #113

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 Samarasinghe, Rometh'

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
14 changes: 13 additions & 1 deletion Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ 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;
try
{
return Math.Pow(double.Parse(x), double.Parse(y));

}
catch (FormatException)
{
throw new FormatException("Both x and y must be valid numbers.");
}
catch (ArgumentNullException)
{
throw new ArgumentNullException("Both x and y must be provided.");
}
}
}
106 changes: 106 additions & 0 deletions Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,110 @@ public void Add_Null_Patino()
Assert.ThrowsException<ArgumentNullException>(() => Program.Add(null, "1"));
Assert.ThrowsException<ArgumentNullException>(() => Program.Add(null, null));
}

}

[TestClass]
public class Subtraction
{
[TestMethod]
public void Subtract_Valid_Rometh()
{
Assert.AreEqual(-1, Program.Subtract("1", "2"));
Assert.AreEqual(1, Program.Subtract("3", "2"));
Assert.AreEqual(-2, Program.Subtract("5", "7"));
}
[TestMethod]
public void Subtract_Invalid_Rometh()
{
Assert.ThrowsException<FormatException>(() => Program.Subtract("1", "a"));
Assert.ThrowsException<FormatException>(() => Program.Subtract("a", "1"));
Assert.ThrowsException<FormatException>(() => Program.Subtract("a", "a"));
}
[TestMethod]
public void Subtract_Null_Rometh()
{
Assert.ThrowsException<ArgumentNullException>(() => Program.Subtract("1", null));
Assert.ThrowsException<ArgumentNullException>(() => Program.Subtract(null, "1"));
Assert.ThrowsException<ArgumentNullException>(() => Program.Subtract(null, null));
}
}

[TestClass]
public class Multiplication
{
[TestMethod]
public void Multiply_Valid_Smith()
{
Assert.AreEqual(2, Program.Multiply("1", "2"));
Assert.AreEqual(6, Program.Multiply("3", "2"));
Assert.AreEqual(35, Program.Multiply("5", "7"));
}
[TestMethod]
public void Multiply_Invalid_Smith()
{
Assert.ThrowsException<FormatException>(() => Program.Multiply("1", "a"));
Assert.ThrowsException<FormatException>(() => Program.Multiply("a", "1"));
Assert.ThrowsException<FormatException>(() => Program.Multiply("a", "a"));
}
[TestMethod]
public void Multiply_Null_Smith()
{
Assert.ThrowsException<ArgumentNullException>(() => Program.Multiply("1", null));
Assert.ThrowsException<ArgumentNullException>(() => Program.Multiply(null, "1"));
Assert.ThrowsException<ArgumentNullException>(() => Program.Multiply(null, null));
}
}

[TestClass]
public class Division
{
[TestMethod]
public void Divide_Valid_Jones()
{
Assert.AreEqual(0.5, Program.Divide("1", "2"));
Assert.AreEqual(1.5, Program.Divide("3", "2"));
Assert.AreEqual(0.7142857142857143, Program.Divide("5", "7"));
}
[TestMethod]
public void Divide_Invalid_Jones()
{
Assert.ThrowsException<FormatException>(() => Program.Divide("1", "a"));
Assert.ThrowsException<FormatException>(() => Program.Divide("a", "1"));
Assert.ThrowsException<FormatException>(() => Program.Divide("a", "a"));
}
[TestMethod]
public void Divide_Null_Jones()
{
Assert.ThrowsException<ArgumentNullException>(() => Program.Divide("1", null));
Assert.ThrowsException<ArgumentNullException>(() => Program.Divide(null, "1"));
Assert.ThrowsException<ArgumentNullException>(() => Program.Divide(null, null));
}
}

[TestClass]
public class Power
{
[TestMethod]
public void Power_Valid_Brown()
{
Assert.AreEqual(1, Program.Power("1", "2"));
Assert.AreEqual(9, Program.Power("3", "2"));
Assert.AreEqual(78125, Program.Power("5", "7"));
}
[TestMethod]
public void Power_Invalid_Brown()
{
Assert.ThrowsException<FormatException>(() => Program.Power("1", "a"));
Assert.ThrowsException<FormatException>(() => Program.Power("a", "1"));
Assert.ThrowsException<FormatException>(() => Program.Power("a", "a"));
}
[TestMethod]
public void Power_Null_Brown()
{
Assert.ThrowsException<ArgumentNullException>(() => Program.Power("1", null));
Assert.ThrowsException<ArgumentNullException>(() => Program.Power(null, "1"));
Assert.ThrowsException<ArgumentNullException>(() => Program.Power(null, null));
}
}