Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from Gitfoe/development-master
Browse files Browse the repository at this point in the history
v1.0.0
  • Loading branch information
RillJ authored Oct 23, 2021
2 parents c148916 + a95adc7 commit 2702bf4
Show file tree
Hide file tree
Showing 736 changed files with 37,319 additions and 1 deletion.
Binary file not shown.
Binary file added .vs/race_simulator_wafoe/v16/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 22 additions & 0 deletions Controller.Test/Controller.Test.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Controller\Controller.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\view\View.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
using NUnit.Framework;
using Model.Classes;
using Model.Interfaces;
using Controller.Classes;
using System.Collections.Generic;
using static Model.Classes.Section;

namespace ControllerTest
{
[TestFixture]
public class Controller_Race_DeterminePositionsOnTrackShould
{
// Fields
private Competition _competition;

// Methods
[SetUp]
public void SetUp()
{
_competition = new Competition();
_competition.Participants.AddRange(new IParticipant[] { // Add the list of new Driver classes to the Participants list
new Driver("Mario", new Kart(10), TeamColors.Mario),
new Driver("Toad", new Kart(10), TeamColors.Toad),
new Driver("Luigi", new Kart(10), TeamColors.Luigi),
new Driver("Peach", new Kart(10), TeamColors.Peach),
new Driver("Wafoe", new Kart(10), TeamColors.Wafoe),
new Driver("Bowser", new Kart(10), TeamColors.Bowser),
});
}

[TestCase(1, false)]
[TestCase(2, false)]
[TestCase(3, false)]
[TestCase(4, false)]
[TestCase(5, false)]
[TestCase(6, false)]
[TestCase(1, true)]
[TestCase(2, true)]
[TestCase(3, true)]
[TestCase(4, true)]
[TestCase(5, true)]
public void DeterminePositionsOnTrack_CheckForCorrectOutput(int roundsFinished, bool oneParticipantLapFurther)
{ // This test case always uses the first participant (in this case, Mario)
#region Preparation
Race race = new Race(new Track("Rainbow Road", 6, new Section.SectionTypes[] {
SectionTypes.Finish,
SectionTypes.RightCorner,
SectionTypes.Straight,
SectionTypes.LeftCorner,
SectionTypes.Straight,
SectionTypes.Straight,
SectionTypes.RightCorner,
SectionTypes.RightCorner,
SectionTypes.Straight,
SectionTypes.Straight,
SectionTypes.LeftCorner,
SectionTypes.RightCorner,
SectionTypes.Straight,
SectionTypes.LeftCorner,
SectionTypes.RightCorner,
SectionTypes.RightCorner,
SectionTypes.LeftCorner,
SectionTypes.Straight,
SectionTypes.RightCorner,
SectionTypes.Straight,
SectionTypes.Straight,
SectionTypes.Straight,
SectionTypes.RightCorner,
SectionTypes.StartGrid,
SectionTypes.StartGrid,
SectionTypes.StartGrid}), _competition.Participants); // Setup faux race

// First clear the _positions because by default it gets filled, but we want to manually control it
foreach (KeyValuePair<Section, SectionData> item in race._positions)
{
item.Value.Left = null;
item.Value.Right = null;
}

// Enqueue the participants so we can place them nicely
Queue<IParticipant> tempQueue = new Queue<IParticipant>(_competition.Participants);

// Fill the participants on straight sections
foreach (KeyValuePair<Section, SectionData> item in race._positions)
{
if (item.Key.SectionType == Section.SectionTypes.Straight)
{
item.Value.Left = tempQueue.Dequeue();
item.Value.Right = tempQueue.Dequeue();
}
if (tempQueue.Count == 0) // Break out of the loop if the queue is empty to save on resources
{
break;
}
}
#endregion

string firstDriverPlacement = "6th";
string secondDriverPlacement = "1st";
// Add all the participant to the _roundsFinished dictionary
foreach (IParticipant participant in race.Participants)
{
if (oneParticipantLapFurther) // If we want one participant to be a lap further to test the lap handling part of the function
{
race._roundsFinished.Add(participant, roundsFinished + 1);
firstDriverPlacement = "1st";
secondDriverPlacement = "2nd";
oneParticipantLapFurther = false;
}
else // If not, just add normally
{
race._roundsFinished.Add(participant, roundsFinished);
}

}

// Execute the method we want to test
race.DeterminePositionsOnTrack();

// Now, we test if the first one is last and the last one is first (reversed, because we didn't use the method to fix the positions by reversing the order of placement)
Assert.IsTrue(race.Participants[0].PositionOnTrack == firstDriverPlacement);
Assert.IsTrue(race.Participants[5].PositionOnTrack == secondDriverPlacement);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using NUnit.Framework;
using System.Collections.Generic;
using Model.Classes;
using static Model.Classes.Section;
using Model.Interfaces;
using Controller.Classes;
using System.Linq;

namespace ControllerTest
{
[TestFixture]
public class Controller_Race_CheckIfEveryoneFinishedRaceShould
{
// Fields
private Competition _competition;

// Methods
[SetUp]
public void SetUp()
{
_competition = new Competition();
_competition.Participants.AddRange(new IParticipant[] { // Add the list of new Driver classes to the Participants list
new Driver("Mario", new Kart(10), TeamColors.Mario),
new Driver("Toad", new Kart(10), TeamColors.Toad),
new Driver("Luigi", new Kart(10), TeamColors.Luigi),
new Driver("Peach", new Kart(10), TeamColors.Peach),
new Driver("Wafoe", new Kart(10), TeamColors.Wafoe),
new Driver("Bowser", new Kart(10), TeamColors.Bowser)
});
}

[TestCase(false, 1, 1)]
[TestCase(false, 2, 2)]
[TestCase(true, 3, 3)]
[TestCase(false, 1, 3)]
[TestCase(false, 2, 3)]
[TestCase(false, 3, 2)]
[TestCase(false, 4, 4)]
[TestCase(false, 0, 0)]
public void CheckIfEveryoneFinishedRace_CheckForTrueAndFalse(bool boolShould, int lapsOfParticipants, int lapsOfFirstParticipant)
{
Race race = new Race(new Track("Rainbow Road", 2, new Section.SectionTypes[] { // Setup a new temporary race
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.Finish, }), _competition.Participants); // Setup faux race

race._roundsFinished = new Dictionary<IParticipant, int>();

foreach (IParticipant participant in _competition.Participants)
{ // Add all participants to the _roundsFinished dictionary and set it to the lapsOfParticipants value
race._roundsFinished.Add(participant, lapsOfParticipants);

}

race._roundsFinished[race._roundsFinished.First().Key] = lapsOfFirstParticipant; // Set the laps of the first participant to lapsOfFirstParticipant

bool output = race.CheckIfEveryoneFinishedRace(); // Execute the method

Assert.AreEqual(boolShould, output);
}
}
}
45 changes: 45 additions & 0 deletions Controller.Test/Controller_Race_CountCertainSectionTypesShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NUnit.Framework;
using Model.Classes;
using static Model.Classes.Section;
using Model.Interfaces;
using Controller.Classes;

namespace ControllerTest
{
[TestFixture]
public class Controller_Race_CountCertainSectionTypesShould
{
// Fields
private Competition _competition;

// Methods
[SetUp]
public void SetUp()
{
_competition = new Competition();
_competition.Participants.AddRange(new IParticipant[] { });
}

[TestCase(SectionTypes.LeftCorner, 4)]
[TestCase(SectionTypes.RightCorner, 0)]
[TestCase(SectionTypes.StartGrid, 3)]
[TestCase(SectionTypes.Finish, 1)]
[TestCase(SectionTypes.Straight, 0)]
public void CountCertainSectionTypes_CheckIfCorrectSectionCount(SectionTypes sectionTypeToCount, int correctSectionTypeCount)
{
Race race = new Race(new Track("Rainbow Road", 4, new Section.SectionTypes[] { // Setup a new temporary race
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.Finish, }), _competition.Participants); // Setup faux race

int countedSectionTypes = race.CountCertainSectionTypes(race.Track.Sections, sectionTypeToCount); // Call the method and count the types

Assert.AreEqual(correctSectionTypeCount, countedSectionTypes); // Compare it to the actual correct result
}
}
}
76 changes: 76 additions & 0 deletions Controller.Test/Controller_Race_CountLapsOfParticipantShould.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using NUnit.Framework;
using System.Collections.Generic;
using Model.Classes;
using static Model.Classes.Section;
using Model.Interfaces;
using Controller.Classes;
using System.Linq;

namespace ControllerTest
{
[TestFixture]
public class Controller_Race_CountLapsOfParticipantShould
{
// Fields
private Competition _competition;

// Methods
[SetUp]
public void SetUp()
{
_competition = new Competition();
_competition.Participants.AddRange(new IParticipant[] { // Add the list of new Driver classes to the Participants list
new Driver("Mario", new Kart(10), TeamColors.Mario),
new Driver("Toad", new Kart(10), TeamColors.Toad),
new Driver("Luigi", new Kart(10), TeamColors.Luigi),
new Driver("Peach", new Kart(10), TeamColors.Peach),
new Driver("Wafoe", new Kart(10), TeamColors.Wafoe),
new Driver("Bowser", new Kart(10), TeamColors.Bowser)
});
}

[TestCase(false, -1)]
[TestCase(false, 0)]
[TestCase(false, 1)]
[TestCase(true, 2)] // Should only be true if it's the same as _amountOfLaps
[TestCase(false, 3)]
[TestCase(false, 4)]
public void CountLapsOfParticipant_CheckIfParticipantFinishedRace(bool boolShould, int lapsOfParticipant)
{
Race race = new Race(new Track("Rainbow Road", 2, new Section.SectionTypes[] { // Setup a new temporary race
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.Finish, }), _competition.Participants); // Setup faux race

race._roundsFinished = new Dictionary<IParticipant, int>();
race._roundsFinished.Add(_competition.Participants.First(), lapsOfParticipant); // Add the first participant with the laps from the test

bool output = race.CountLapsOfParticipant(_competition.Participants.First()); // Execute the method

Assert.AreEqual(boolShould, output);
}

[Test]
public void CountLapsOfParticipant_CheckIfAddsToDictionary()
{
Race race = new Race(new Track("Rainbow Road", 4, new Section.SectionTypes[] { // Setup a new temporary race
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.StartGrid,
SectionTypes.LeftCorner,
SectionTypes.Finish, }), _competition.Participants); // Setup faux race

race.CountLapsOfParticipant(_competition.Participants.First());

Assert.AreEqual(race._roundsFinished.First().Key, _competition.Participants.First());
}
}
}
Loading

0 comments on commit 2702bf4

Please sign in to comment.