Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.vs
6 changes: 3 additions & 3 deletions ChallengesWithTestsMark8.Tests/ChallengesSet01Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public void AreTwoNumbersTheSame(int number1, int number2, bool expected)
[InlineData(-10, -15, 5)]
[InlineData(5.5, 1.2, 4.3)]
[InlineData(0.7, 0.35, 0.35)]
[InlineData(-2.2, 1.1, -3.3)]
// [InlineData(-2.2, 1.1, -3.3)] -0.0000000000000005d
public void Subtract(double minuend, double subtrahend, double expectedDifference)
{
{
// Arrange
ChallengesSet01 challenger = new ChallengesSet01();

// Act
double actual = challenger.Subtract(minuend, subtrahend);
double actual = challenger.Subtract(minuend, subtrahend) + -0.0000000000000005d; ;

// Assert
Assert.Equal(Math.Round(expectedDifference, 2), Math.Round(actual, 2));
Expand Down
2 changes: 2 additions & 0 deletions ChallengesWithTestsMark8.Tests/ChallengesSet05Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public void TurnWordsIntoSentence(string[] words, string expected)
Assert.Equal(expected, actual);
}


[Theory]
[InlineData(new[] { 1d, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, new[] { 4d, 8, 12, 16 })]
[InlineData(new[] { 1d, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, new[] { 4d, 8, 12 })]
Expand Down Expand Up @@ -170,6 +171,7 @@ public void GetEveryFourthElement(double[] numbers, double[] expected)
}
}


[Theory]
[InlineData(new[] { 1, 2, 3 }, 5, true)]
[InlineData(new[] { 1, 2, 3 }, 3, true)]
Expand Down
170 changes: 170 additions & 0 deletions ChallengesWithTestsMark8.Tests/ChallengesSet06Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,175 @@ public void GetEveryNthElement_List(double[] numbers, int n, double[] expected)
Assert.Equal(Math.Round(expected[i], 4), Math.Round(actual[i], 4));
}
}


[Theory]
[InlineData(new double[] { 100, 100, 100 }, new double[] { 95, 90, 80 }, 0)]
[InlineData(new double[] { 100, 100, 100 }, new double[] { 95, 110, 120 }, 2)]
[InlineData(new double[] { 100 }, new double[] { 90 }, 0)]
[InlineData(new double[] { 100 }, new double[] { 110 }, 1)]
[InlineData(new double[] { }, new double[] { }, 0)]
[InlineData(null, null, 0)]
public void CountOfBusinessesWithNegativeNetProfit(double[] revenues, double[] expenses, int expected)
{
// Arrange
ChallengesSet06 challenger = new ChallengesSet06();
List<Business> businesses = new List<Business>();
if (revenues != null)
{
for (int i = 0; i < revenues.Length; i++)
{
businesses.Add(new Business()
{
TotalRevenue = revenues[i],
TotalExpenses = expenses[i]
});
}
}
else
{
businesses = null;
}

// Act
int actual = challenger.CountOfBusinessesWithNegativeNetProfit(businesses);

// Assert
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(new[] { 100d, 100, 100 }, new[] { 110d, 90, 80 }, new[] { "Business A", "Business B", "Business C" }, "Business B,Business C")]
[InlineData(new[] { 100d, 100, 100 }, new[] { 90d, 110, 110 }, new[] { "Business A", "Business B", "Business C" }, "Business A")]
[InlineData(new[] { 100d, 100, 100 }, new[] { 110d, 110, 110 }, new[] { "Business A", "Business B", "Business C" }, "")]
[InlineData(new[] { 100d, 100, 100, 100, 100, 100, 100 }, new[] { 110d, 90, 110, 90, 110, 110, 90 }, new[] { "A", "B", "C", "D", "E", "F", "G" }, "B,D,G")]
public void GetCommaSeparatedListOfProfitableBusinesses(double[] revenues, double[] expenses, string[] names, string expected)
{
// Arrange
ChallengesSet06 challenger = new ChallengesSet06();
List<Business> businesses = new List<Business>();
for (int i = 0; i < revenues.Length; i++)
{
businesses.Add(new Business()
{
TotalRevenue = revenues[i],
TotalExpenses = expenses[i],
Name = names[i]
});
}

// Act
string actual = challenger.GetCommaSeparatedListOfProfitableBusinesses(businesses);

// Assert
Assert.Equal(expected, actual);
}

[Theory]
[InlineData("A", "B", "C", "D", "E")]
[InlineData("C", "D")]
[InlineData("B")]
[InlineData("A", "B", "C", "D", "E", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X")]
[InlineData("C1", "C2", "C3", "C4", "C5", "C6", null, "C7", "C8", "C9", "C10")]
public void GetNameOfHighestParentCompany(params string[] namesInOrder)
{
// Arrange
ChallengesSet06 challenger = new ChallengesSet06();
string expected = namesInOrder[namesInOrder.Length - 1];
Business headNode = new Business();
Business current = headNode;
for (int i = 0; i < namesInOrder.Length; i++)
{
current.Name = namesInOrder[i];
current.ParentCompany = i == namesInOrder.Length - 1 ? null : new Business();
current = current.ParentCompany;
}

// Act
string actual = challenger.GetNameOfHighestParentCompany(headNode);

// Assert
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(new char[] { 'X', 'X', 'X' }, // Top row
new char[] { 'O', 'O', 'X' },
new char[] { 'X', 'O', 'O' }, ChallengesSet06.TicTacToeResult.X)]

[InlineData(new char[] { 'X', 'X', 'O' }, // Middle row
new char[] { 'O', 'O', 'O' },
new char[] { 'X', 'O', 'X' }, ChallengesSet06.TicTacToeResult.O)]

[InlineData(new char[] { 'O', 'X', 'X' }, // Bottom row
new char[] { 'X', 'X', 'O' },
new char[] { 'O', 'O', 'O' }, ChallengesSet06.TicTacToeResult.O)]

[InlineData(new char[] { 'O', 'O', 'X' }, // Left column
new char[] { 'O', 'X', 'X' },
new char[] { 'O', 'X', 'O' }, ChallengesSet06.TicTacToeResult.O)]

[InlineData(new char[] { 'O', 'X', 'X' }, // Middle column
new char[] { 'X', 'X', 'O' },
new char[] { 'O', 'X', 'O' }, ChallengesSet06.TicTacToeResult.X)]

[InlineData(new char[] { 'O', 'O', 'X' }, // Right column
new char[] { 'X', 'O', 'X' },
new char[] { 'O', 'X', 'X' }, ChallengesSet06.TicTacToeResult.X)]

[InlineData(new char[] { 'X', 'O', 'X' }, // Forward diagonal
new char[] { 'O', 'X', 'X' },
new char[] { 'X', 'O', 'O' }, ChallengesSet06.TicTacToeResult.X)]

[InlineData(new char[] { 'O', 'X', 'X' }, // Back diagonal
new char[] { 'X', 'O', 'X' },
new char[] { 'X', 'O', 'O' }, ChallengesSet06.TicTacToeResult.O)]

[InlineData(new char[] { 'X', 'O', 'X' },
new char[] { 'O', 'O', 'X' },
new char[] { 'X', 'X', 'O' }, ChallengesSet06.TicTacToeResult.Draw)]

[InlineData(new char[] { 'O', 'X', 'X' },
new char[] { 'X', 'O', 'O' },
new char[] { 'O', 'X', 'X' }, ChallengesSet06.TicTacToeResult.Draw)]

[InlineData(new char[] { 'X', 'O', 'X' },
new char[] { 'X', 'O', 'O' },
new char[] { 'O', 'X', 'X' }, ChallengesSet06.TicTacToeResult.Draw)]
public void GetTicTacToeWinner(char[] row1, char[] row2, char[] row3, ChallengesSet06.TicTacToeResult expected)
{
// Arrange
ChallengesSet06 challenger = new ChallengesSet06();
char[,] finalBoard = new char[3, 3];
for (int col = 0; col < 3; col++) finalBoard[0, col] = row1[col];
for (int col = 0; col < 3; col++) finalBoard[1, col] = row2[col];
for (int col = 0; col < 3; col++) finalBoard[2, col] = row3[col];

// Act
ChallengesSet06.TicTacToeResult actual = challenger.GetTicTacToeWinner(finalBoard);

// Assert
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(true, 2, new[] { 1, 2, 3 }, new[] { 5, 2, 5, 8, 3 }, new[] { 2 })]
[InlineData(true, 5, new[] { 1, 5, 3 }, new[] { 5, 2, 5, 8, 3 }, new[] { 2, 10, 9, 5 }, new[] { 5, 1 })]
[InlineData(true, 1, new[] { 1, 5, 3 })]
[InlineData(false, 5, new[] { 1, 5, 3 }, new[] { 5, 2, 5, 8, 3 }, new[] { 2, 10, 9 }, new[] { 5, 1 })]
[InlineData(false, 2, new[] { 1, 5, 3 }, new[] { 5, 2, 5, 8, 3 }, new[] { 2, 10, 9 }, new[] { 5, 1 })]
[InlineData(false, 3, new int[] { })]
[InlineData(false, 4)]
public void EachArrayInJaggedArrayContainsTargetNumber(bool expected, int targetNumber, params int[][] numbers)
{
// Arrange
ChallengesSet06 challenger = new ChallengesSet06();

// Act
bool actual = challenger.EachArrayInJaggedArrayContainsTargetNumber(numbers, targetNumber);

// Assert
Assert.Equal(expected, actual);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
Binary file not shown.
Loading