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
8 changes: 4 additions & 4 deletions Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ 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;
}
public static double Power(string x, string y)
{
return Math.Pow(double.Parse(x), double.Parse(y));
}
}
72 changes: 50 additions & 22 deletions Tests/UnitTests.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,57 @@
namespace GithubActionsLab;

//
[TestClass]
public class Addition
{
[TestMethod]
public void Add_Valid_Patino()
{
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_Valid_Patino()
{
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()
{
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()
{
Assert.ThrowsException<ArgumentNullException>(() => Program.Add("1", null));

Check warning on line 25 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.

Check warning on line 25 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.
Assert.ThrowsException<ArgumentNullException>(() => Program.Add(null, "1"));

Check warning on line 26 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.

Check warning on line 26 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.
Assert.ThrowsException<ArgumentNullException>(() => Program.Add(null, null));

Check warning on line 27 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.

Check warning on line 27 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.

Check warning on line 27 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.

Check warning on line 27 in Tests/UnitTests.cs

View workflow job for this annotation

GitHub Actions / build-and-test

Cannot convert null literal to non-nullable reference type.
}

[TestMethod]
public void Subtract_Valid()
{
Assert.AreEqual(1, Program.Subtract("3", "2"));
Assert.AreEqual(0, Program.Subtract("2", "2"));
}

[TestMethod]
public void Multiply_Valid()
{
Assert.AreEqual(6, Program.Multiply("2", "3"));
Assert.AreEqual(10, Program.Multiply("5", "2")); // ✅ FIXED
}

[TestMethod]
public void Add_Invalid_Patino()
{
Assert.ThrowsException<FormatException>(() => Program.Add("1", "a"));
Assert.ThrowsException<FormatException>(() => Program.Add("a", "1"));
Assert.ThrowsException<FormatException>(() => Program.Add("a", "a"));
}
[TestMethod]
public void Divide_Valid()
{
Assert.AreEqual(2, Program.Divide("6", "3"));
Assert.AreEqual(5, Program.Divide("10", "2"));
}

[TestMethod]
public void Add_Null_Patino()
{
Assert.ThrowsException<ArgumentNullException>(() => Program.Add("1", null));
Assert.ThrowsException<ArgumentNullException>(() => Program.Add(null, "1"));
Assert.ThrowsException<ArgumentNullException>(() => Program.Add(null, null));
}
[TestMethod]
public void Power_Valid()
{
Assert.AreEqual(8, Program.Power("2", "3"));
Assert.AreEqual(9, Program.Power("3", "2"));
}
}
Loading