-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStaircaseTests.cs
51 lines (41 loc) · 1.15 KB
/
StaircaseTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using FluentAssertions;
using ProblemSolving_HackerRank_.Easy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HackerRankProblems.Tests.Easy
{
public class StaircaseTests
{
public static IEnumerable<object[]> TestData()
{
string pattern = "#\r\n ##\r\n ###\r\n ####\r\n #####\r\n######";
yield return new object[] { 6, pattern };
}
[Theory]
[MemberData(nameof(TestData))]
public void Staircase_staircase_ReturnStaircaseString(int n, string expectedResult)
{
//Redirect console output to capture it
using (StringWriter sw = new StringWriter())
{
//Arrange
Console.SetOut(sw);
//Act
Staircase.staircase(n);
//Get the captured console output
string consoleOutput = sw.ToString().Trim();
// Count the number of '#' symbols in the output
int hashCount = consoleOutput.Count(c => c == '#');
int actualHashCount = (n * (n + 1)) / 2;
//Assert
consoleOutput.Should().NotBeNullOrWhiteSpace()
.And.Be(expectedResult);
hashCount.Should().Be(actualHashCount);
n.Should().BeInRange(0, 100);
}
}
}
}