Skip to content

Commit

Permalink
Test for Q2331
Browse files Browse the repository at this point in the history
  • Loading branch information
febinjoy committed Jan 2, 2024
1 parent 8178d35 commit 9d978a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions LeetCodeSolutions/Questions/Easy/Q2331.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ private class TreeNode
public TreeNode left;
public TreeNode right;
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.

public TreeNode(int val = 0, TreeNode left = null, TreeNode right = null)
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
{
Expand All @@ -38,7 +39,7 @@ public IResult Execute()
{
TreeNode node = new TreeNode(2, new TreeNode(1), new TreeNode(3, new TreeNode(0), new TreeNode(1)));
bool output = EvaluateTree(node);
if (output == true)
if (output)
return new SuccessResult();
else
return new ErrorResult("Expected True. But was False.");
Expand All @@ -56,5 +57,4 @@ private bool EvaluateTree(TreeNode root)
return true;
}
}
}

}
28 changes: 28 additions & 0 deletions LeetCodeSolutionsTest/QuestionServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using LeetCodeSolutions;
using LeetCodeSolutions.Classes;
using LeetCodeSolutions.Enums;
using LeetCodeSolutions.Exceptions;
using LeetCodeSolutions.Interfaces;
using LeetCodeSolutions.Questions.Easy;
Expand All @@ -11,12 +13,18 @@ public class QuestionServiceTests
{
private QuestionService questionService;

#region Setup

[SetUp]
public void Setup()
{
questionService = new QuestionService();
}

#endregion Setup

#region Exception Tests

[Test]
public void ExecuteQuestion_UnknownQuestionNumber_ThrowsQuestionNotFoundException()
{
Expand All @@ -41,5 +49,25 @@ public void ExecuteQuestion_NotImplementedQuestion_ThrowsNotImplementedException
// Act + Assert
Assert.Throws<NotImplementedException>(() => questionService.ExecuteQuestion(questionNumber));
}

#endregion Exception Tests

#region Easy Questions

[Test]
public void ExecuteQuestion_Q2331_ReturnsSuccessResult()
{
// Arrange
int questionNumber = 2331;

// Act
IResult result = questionService.ExecuteQuestion(questionNumber);

// Assert
Assert.IsInstanceOf<SuccessResult>(result);
Assert.That(result.Status, Is.EqualTo(ResultStatus.Passed));
}

#endregion Easy Questions
}
}

0 comments on commit 9d978a7

Please sign in to comment.