Last active
February 17, 2022 08:56
-
-
Save mehmetalierol/361d94dee0e80aca67cda6a3bbf83f23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Application.Domain.Concrete; | |
using Application.Domain.Concrete.Directions; | |
using System; | |
using System.Linq; | |
using Xunit; | |
namespace Application.Tests.Domain | |
{ | |
public class NasaRoverTests | |
{ | |
private readonly NasaRover nasaRover; | |
public NasaRoverTests() | |
{ | |
nasaRover = new NasaRover(); | |
} | |
[Theory] | |
[InlineData("1 2 N", 1, 2, 'N')] | |
[InlineData("3 3 E", 3, 3, 'E')] | |
public void SetInitialCoordinateTest(string input, int expectedX, int expectedY, char expectedOrientation) | |
{ | |
//Act | |
nasaRover.SetInitialCoordinate(input); | |
var result = nasaRover.AxisX == expectedX && nasaRover.AxisY == expectedY && nasaRover.Orientation == expectedOrientation; | |
//Assert | |
Assert.True(result); | |
} | |
[Fact] | |
public void SetCoordinatesEmptyTest() | |
{ | |
//Assert | |
Assert.Throws<InvalidOperationException>(() => nasaRover.SetInitialCoordinate("")); | |
} | |
[Fact] | |
public void SetCoordinatesNonNumberTest() | |
{ | |
//Assert | |
Assert.Throws<FormatException>(() => nasaRover.SetInitialCoordinate("A A A")); | |
} | |
[Fact] | |
public void SetCoordinatesWrongInputTest() | |
{ | |
//Assert | |
Assert.Throws<InvalidOperationException>(() => nasaRover.SetInitialCoordinate("1 1")); | |
} | |
[Theory] | |
[InlineData("LMLMLMLMM", new char[] { 'L', 'M', 'L', 'M', 'L', 'M', 'L', 'M', 'M' })] | |
[InlineData("MMRMMRMRRM", new char[] { 'M', 'M', 'R', 'M', 'M', 'R', 'M', 'R', 'R', 'M' })] | |
public void SetCommandSetTest(string input, char[] expectedArray) | |
{ | |
//Act | |
nasaRover.SetCommandSet(input); | |
//Assert | |
Assert.True(nasaRover.CommandSet.SequenceEqual(expectedArray)); | |
} | |
[Fact] | |
public void SetCommandSetEmptyTest() | |
{ | |
//Assert | |
Assert.Throws<InvalidOperationException>(() => nasaRover.SetCommandSet("")); | |
} | |
[Theory] | |
[InlineData('N', typeof(NorthDirection))] | |
[InlineData('S', typeof(SouthDirection))] | |
[InlineData('W', typeof(WestDirection))] | |
[InlineData('E', typeof(EastDirection))] | |
public void CurrentDirectionTest(char input, Type expectedDirection) | |
{ | |
//Act | |
nasaRover.Orientation = input; | |
var result =nasaRover.CurrentDirection(); | |
//Assert | |
Assert.True(result.GetType() == expectedDirection); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment