Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Program.cs #144

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ 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)
{
throw new NotImplementedException();
return Math.Pow(double.Parse(x),double.Parse(y));
}
}

Expand Down
102 changes: 99 additions & 3 deletions Tests/UnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,125 @@ namespace TravisCILab
public class Math
{
[Test]
public void Add_Valid()
public void Add_Valid_Koranda()
{
Assert.AreEqual(3, Program.Add("1", "2"));
Assert.AreEqual(5, Program.Add("3", "2"));
Assert.AreEqual(12, Program.Add("5", "7"));
}

[Test]
public void Add_Invalid()
public void Add_Invalid_Koranda()
{
Assert.Throws<FormatException>(() => Program.Add("1", "a"));
Assert.Throws<FormatException>(() => Program.Add("a", "1"));
Assert.Throws<FormatException>(() => Program.Add("a", "a"));
}

[Test]
public void Add_Null()
public void Add_Null_Koranda()
{
Assert.Throws<ArgumentNullException>(() => Program.Add("1", null));
Assert.Throws<ArgumentNullException>(() => Program.Add(null, "1"));
Assert.Throws<ArgumentNullException>(() => Program.Add(null, null));
}

// Implement 3 tests per operation, following a similar pattern as above

[Test]
public void Subtract_Valid_Koranda()
{
Assert.AreEqual(3, Program.Subtract("5", "2"));
Assert.AreEqual(5, Program.Subtract("7", "2"));
Assert.AreEqual(12, Program.Subtract("19", "7"));
}

[Test]
public void Subtract_Invalid_Koranda()
{
Assert.Throws<FormatException>(() => Program.Subtract("1", "a"));
Assert.Throws<FormatException>(() => Program.Subtract("a", "1"));
Assert.Throws<FormatException>(() => Program.Subtract("a", "a"));
}

[Test]
public void Subtract_Null_Koranda()
{
Assert.Throws<ArgumentNullException>(() => Program.Subtract("1", null));
Assert.Throws<ArgumentNullException>(() => Program.Subtract(null, "1"));
Assert.Throws<ArgumentNullException>(() => Program.Subtract(null, null));
}

[Test]
public void Multiply_Valid_Koranda()
{
Assert.AreEqual(3, Program.Multiply("1", "3"));
Assert.AreEqual(6, Program.Multiply("3", "2"));
Assert.AreEqual(35, Program.Multiply("5", "7"));
}

[Test]
public void Multiply_Invalid_Koranda()
{
Assert.Throws<FormatException>(() => Program.Multiply("1", "a"));
Assert.Throws<FormatException>(() => Program.Multiply("a", "1"));
Assert.Throws<FormatException>(() => Program.Multiply("a", "a"));
}

[Test]
public void Multiply_Null_Koranda()
{
Assert.Throws<ArgumentNullException>(() => Program.Multiply("1", null));
Assert.Throws<ArgumentNullException>(() => Program.Multiply(null, "1"));
Assert.Throws<ArgumentNullException>(() => Program.Multiply(null, null));
}

[Test]
public void Divide_Valid_Koranda()
{
Assert.AreEqual(3, Program.Divide("6", "2"));
Assert.AreEqual(5, Program.Divide("10", "2"));
Assert.AreEqual(12, Program.Divide("60", "5"));
}

[Test]
public void Divide_Invalid_Koranda()
{
Assert.Throws<FormatException>(() => Program.Divide("1", "a"));
Assert.Throws<FormatException>(() => Program.Divide("a", "1"));
Assert.Throws<FormatException>(() => Program.Divide("a", "a"));
}

[Test]
public void Divide_Null_Koranda()
{
Assert.Throws<ArgumentNullException>(() => Program.Divide("1", null));
Assert.Throws<ArgumentNullException>(() => Program.Divide(null, "1"));
Assert.Throws<ArgumentNullException>(() => Program.Divide(null, null));
}

[Test]
public void Power_Valid_Koranda()
{
Assert.AreEqual(4, Program.Power("2", "2"));
Assert.AreEqual(9, Program.Power("3", "2"));
Assert.AreEqual(1, Program.Power("1", "7"));
}

[Test]
public void Power_Invalid_Koranda()
{
Assert.Throws<FormatException>(() => Program.Power("1", "a"));
Assert.Throws<FormatException>(() => Program.Power("a", "1"));
Assert.Throws<FormatException>(() => Program.Power("a", "a"));
}

[Test]
public void Power_Null_Koranda()
{
Assert.Throws<ArgumentNullException>(() => Program.Power("1", null));
Assert.Throws<ArgumentNullException>(() => Program.Power(null, "1"));
Assert.Throws<ArgumentNullException>(() => Program.Power(null, null));
}
}
}