-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlusMinusTests.cs
56 lines (45 loc) · 1.27 KB
/
PlusMinusTests.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
52
53
54
55
56
using FluentAssertions;
using ProblemSolving_HackerRank_.Easy;
namespace HackerRankProblems.Tests.Easy
{
public class PlusMinusTests
{
[Fact]
public void PlusMinus_plusMinus_ReturnString1()
{
//Arrange - variables, classes, mocks
var testArray = new List<int>() { 1, -2, 0, 3, -4 };
string expectedResult = "0.400000\n0.400000\n0.200000";
//Redirect console output to capture it
using (StringWriter sw = new StringWriter())
{
Console.SetOut(sw);
//Act
PlusMinus.plusMinus(testArray);
//Get the captured console output
string consoleOutput = sw.ToString().Trim();
//Assert
consoleOutput.Should().NotBeNullOrWhiteSpace();
consoleOutput.Should().Be(expectedResult);
}
}
[Fact]
public void PlusMinus_plusMinus_ReturnString2()
{
//Arrange - variables, classes, mocks
var testArray = new List<int>() { -4, 3, -9, 0, 4, 1 };
string expectedResult = "0.500000\n0.333333\n0.166667";
//Redirect console output to capture it
using (StringWriter sw = new StringWriter())
{
Console.SetOut(sw);
//Act
PlusMinus.plusMinus(testArray);
//Get the captured console output
string consoleOutput = sw.ToString().Trim();
//Assert
consoleOutput.Should().Be(expectedResult);
}
}
}
}