using System;
using System.Collections.Generic;
using PartA.Models;
using Xunit;
namespace PartA.Tests
{
public class FizzBuzzTests
{
private readonly FizzBuzz _fizzBuzz;
public FizzBuzzTests()
{
_fizzBuzz = new FizzBuzz();
}
// 1st test - Returns list 1 to 100[cite: 3]
[Fact]
public void GetList_ReturnsList1To100_WhenNoParametersPassed()
{
// ACT
List<string> result = _fizzBuzz.getList();
// ASSERT
Assert.Equal(100, result.Count);
Assert.Equal("1", result[0]);
Assert.Equal("Buzz", result[99]); // Number 100
}
// 2nd test - Fizz for 3 multiples[cite: 3]
[Fact]
public void GetList_ReturnsFizz_ForMultiplesOfThree()
{
// ACT
List<string> result = _fizzBuzz.getList();
// ASSERT
Assert.Equal("Fizz", result[2]); // Index 2 represents number 3
Assert.Equal("Fizz", result[8]); // Index 8 represents number 9
}
// 3rd test - Buzz for 5 multiples[cite: 3]
[Fact]
public void GetList_ReturnsBuzz_ForMultiplesOfFive()
{
// ACT
List<string> result = _fizzBuzz.getList();
// ASSERT
Assert.Equal("Buzz", result[4]); // Index 4 represents number 5
Assert.Equal("Buzz", result[9]); // Index 9 represents number 10
}
// 4th test - FizzBuzz for 3&5[cite: 3]
[Fact]
public void GetList_ReturnsFizzBuzz_ForMultiplesOfThreeAndFive()
{
// ACT
List<string> result = _fizzBuzz.getList();
// ASSERT
Assert.Equal("FizzBuzz", result[14]); // Index 14 represents number 15
Assert.Equal("FizzBuzz", result[29]); // Index 29 represents number 30
}
// 5th test - Upper limit with default[cite: 3]
[Fact]
public void GetList_RespectsUpperLimit_WhenPassed()
{
// ARRANGE
int bramUpperLimit = 10;
// ACT
List<string> result = _fizzBuzz.getList(bramUpperLimit);
// ASSERT
Assert.Equal(10, result.Count);
Assert.Equal("Buzz", result[9]); // Number 10
}
// 6th test - Lower limit with default[cite: 3]
[Fact]
public void GetList_RespectsLowerLimit_WhenPassed()
{
// ARRANGE
int bramUpperLimit = 20;
int bramLowerLimit = 15;
// ACT
List<string> result = _fizzBuzz.getList(bramUpperLimit, bramLowerLimit);
// ASSERT
Assert.Equal(6, result.Count); // 15, 16, 17, 18, 19, 20
Assert.Equal("FizzBuzz", result[0]); // Number 15
}
// 7th test - Argument out of Range exception[cite: 3]
[Fact]
public void GetList_ThrowsArgumentOutOfRangeException_WhenLowerGreaterThanUpper()
{
// ARRANGE
int bramUpperLimit = 10;
int bramLowerLimit = 20;
// ACT & ASSERT
Assert.Throws<ArgumentOutOfRangeException>(() => _fizzBuzz.getList(bramUpperLimit, bramLowerLimit));
}
}
}
Top comments (0)