/
FizzBuzzTests.cs
82 lines (68 loc) · 2.14 KB
/
FizzBuzzTests.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace TddLikeYouMeanIt
{
[TestClass]
public class FizzBuzzTests
{
private static readonly Random rand = new();
[TestMethod]
public void GivenInputReturnsStringOfInput()
{
//ARRANGE
Dictionary<int, string> regressionValues = new()
{
{ 1, "1" },
{ 2, "2" },
{ 4, "4" }
};
(int sourceInput, string expected) =
regressionValues.ElementAt(rand.Next(0, regressionValues.Count));
//ACT
string actual = Transform(sourceInput);
//ASSERT
actual.Should().Be(expected);
}
[TestMethod]
public void GivenMultipleOf3ReturnsFizz()
{
//ARRANGE
Dictionary<int, string> regressionValues = new()
{
{ 1 * 3, "Fizz" },
{ 2 * 3, "Fizz" },
{ 4 * 3, "Fizz" }
};
(int sourceInput, string expected) =
regressionValues.ElementAt(rand.Next(0, regressionValues.Count));
//ACT
string actual = Transform(sourceInput);
//ASSERT
actual.Should().Be(expected);
}
[TestMethod]
public void GivenMultipleOf5ReturnsFizz()
{
//ARRANGE
int multiplicand = 5;
string expected = "Buzz";
List<int> regressionValues = new() { 1, 2, 4 };
int randomIndex = rand.Next(0, regressionValues.Count);
int multiplier = regressionValues.ElementAt(randomIndex);
int sourceInput = multiplier * multiplicand;
//ACT
string actual = Transform(sourceInput);
//ASSERT
actual.Should().Be(expected);
}
public string Transform(int source)
{
if (0 == source % 5) return "Buzz";
if (0 == source % 3) return "Fizz";
return source.ToString();
}
}
}