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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
using System.Linq;
using System.Linq;
using Algorithms.Problems.DynamicProgramming.CoinChange;
using FluentAssertions;
using NUnit.Framework;

namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange
namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange;

[TestFixture]
public class GenerateChangesDictionaryTests
{
[TestFixture]
public class GenerateChangesDictionaryTests
[Test]
public void GenerateChangesDictionaryTest_Success()
{
[Test]
public void GenerateChangesDictionaryTest_Success()
{
const int coin = 6;
var coins = new[] { 1, 3, 4 };
var changeDictionary = DynamicCoinChangeSolver.GenerateChangesDictionary(coin, coins);
const int coin = 6;
var coins = new[] { 1, 3, 4 };
var changeDictionary = DynamicCoinChangeSolver.GenerateChangesDictionary(coin, coins);

changeDictionary[1].SequenceEqual(new[] { 0 }).Should().BeTrue();
changeDictionary[2].SequenceEqual(new[] { 1 }).Should().BeTrue();
changeDictionary[3].SequenceEqual(new[] { 0, 2 }).Should().BeTrue();
changeDictionary[4].SequenceEqual(new[] { 0, 1, 3 }).Should().BeTrue();
changeDictionary[5].SequenceEqual(new[] { 1, 2, 4 }).Should().BeTrue();
changeDictionary[6].SequenceEqual(new[] { 2, 3, 5 }).Should().BeTrue();
}
changeDictionary[1].SequenceEqual(new[] { 0 }).Should().BeTrue();
changeDictionary[2].SequenceEqual(new[] { 1 }).Should().BeTrue();
changeDictionary[3].SequenceEqual(new[] { 0, 2 }).Should().BeTrue();
changeDictionary[4].SequenceEqual(new[] { 0, 1, 3 }).Should().BeTrue();
changeDictionary[5].SequenceEqual(new[] { 1, 2, 4 }).Should().BeTrue();
changeDictionary[6].SequenceEqual(new[] { 2, 3, 5 }).Should().BeTrue();
}
}
Original file line number Diff line number Diff line change
@@ -1,96 +1,95 @@
using System;
using System;
using System.Linq;
using Algorithms.Problems.DynamicProgramming.CoinChange;
using FluentAssertions;
using NUnit.Framework;

namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange
namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange;

[TestFixture]
public class GenerateSingleCoinChangesTests
{
[TestFixture]
public class GenerateSingleCoinChangesTests
[Test]
public void GenerateSingleCoinChangesTests_Success()
{
DynamicCoinChangeSolver
.GenerateSingleCoinChanges(6, new[] { 1, 2, 3 })
.SequenceEqual(new[] { 3, 4, 5 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(10, new[] { 1, 2, 3, 7, 12, 15, 14 })
.SequenceEqual(new[] { 3, 7, 8, 9 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(1, new[] { 1, 2, 3, 7, 12, 15, 14 })
.SequenceEqual(new[] { 0 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(2, new[] { 1, 2, 3, 7, 12, 15, 14 })
.SequenceEqual(new[] { 0, 1 })
.Should().BeTrue();
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinCannotBeLesserOrEqualZero()
{
const int coin = 0;
var arr = new[] { 1, 2, 3 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, arr);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"The coin cannot be lesser or equal to zero {nameof(coin)}.");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayCannotBeEmpty()
{
const int coin = 10;
var coinsAsArray = Array.Empty<int>();

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"Coins array cannot be empty {nameof(coinsAsArray)}.");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayMustContainOne()
{
[Test]
public void GenerateSingleCoinChangesTests_Success()
{
DynamicCoinChangeSolver
.GenerateSingleCoinChanges(6, new[] { 1, 2, 3 })
.SequenceEqual(new[] { 3, 4, 5 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(10, new[] { 1, 2, 3, 7, 12, 15, 14 })
.SequenceEqual(new[] { 3, 7, 8, 9 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(1, new[] { 1, 2, 3, 7, 12, 15, 14 })
.SequenceEqual(new[] { 0 })
.Should().BeTrue();

DynamicCoinChangeSolver
.GenerateSingleCoinChanges(2, new[] { 1, 2, 3, 7, 12, 15, 14 })
.SequenceEqual(new[] { 0, 1 })
.Should().BeTrue();
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinCannotBeLesserOrEqualZero()
{
const int coin = 0;
var arr = new[] { 1, 2, 3 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, arr);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"The coin cannot be lesser or equal to zero {nameof(coin)}.");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayCannotBeEmpty()
{
const int coin = 10;
var coinsAsArray = Array.Empty<int>();

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"Coins array cannot be empty {nameof(coinsAsArray)}.");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayMustContainOne()
{
const int coin = 10;
var coinsAsArray = new[] { 2, 3, 4 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"Coins array must contain coin 1 {nameof(coinsAsArray)}.");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayCannotContainNegativeValues()
{
const int coin = 10;
var coinsAsArray = new[] { 1, 2, -3, 4 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"{nameof(coinsAsArray)} cannot contain numbers less than or equal to zero");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayCannotContainDuplicates()
{
const int coin = 10;
var coinsAsArray = new[] { 1, 2, 3, 3, 4 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"Coins array cannot contain duplicates {nameof(coinsAsArray)}.");
}
const int coin = 10;
var coinsAsArray = new[] { 2, 3, 4 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"Coins array must contain coin 1 {nameof(coinsAsArray)}.");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayCannotContainNegativeValues()
{
const int coin = 10;
var coinsAsArray = new[] { 1, 2, -3, 4 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"{nameof(coinsAsArray)} cannot contain numbers less than or equal to zero");
}

[Test]
public void GenerateSingleCoinChangesTests_ShouldThrow_CoinsArrayCannotContainDuplicates()
{
const int coin = 10;
var coinsAsArray = new[] { 1, 2, 3, 3, 4 };

Func<int[]> act = () => DynamicCoinChangeSolver.GenerateSingleCoinChanges(coin, coinsAsArray);

act.Should().Throw<InvalidOperationException>()
.WithMessage($"Coins array cannot contain duplicates {nameof(coinsAsArray)}.");
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using Algorithms.Problems.DynamicProgramming.CoinChange;
using Algorithms.Problems.DynamicProgramming.CoinChange;
using FluentAssertions;
using NUnit.Framework;

namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange
namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange;

public class GetMinimalNextCoinTests
{
public class GetMinimalNextCoinTests
[Test]
public void GetMinimalNextCoinTest_Success()
{
[Test]
public void GetMinimalNextCoinTest_Success()
{
const int coin = 6;
var coins = new[] { 1, 3, 4 };
var exchangeDict = DynamicCoinChangeSolver.GenerateChangesDictionary(coin, coins);
var nextCoin = DynamicCoinChangeSolver.GetMinimalNextCoin(6, exchangeDict);
const int coin = 6;
var coins = new[] { 1, 3, 4 };
var exchangeDict = DynamicCoinChangeSolver.GenerateChangesDictionary(coin, coins);
var nextCoin = DynamicCoinChangeSolver.GetMinimalNextCoin(6, exchangeDict);

nextCoin.Should().Be(3);
}
nextCoin.Should().Be(3);
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
using System.Linq;
using System.Linq;
using Algorithms.Problems.DynamicProgramming.CoinChange;
using FluentAssertions;
using NUnit.Framework;

namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange
namespace Algorithms.Tests.Problems.DynamicProgramming.CoinChange;

[TestFixture]
public class MakeCoinChangeDynamicTests
{
[TestFixture]
public class MakeCoinChangeDynamicTests
[Test]
public void MakeCoinChangeDynamicTest_Success()
{
[Test]
public void MakeCoinChangeDynamicTest_Success()
{
DynamicCoinChangeSolver
.MakeCoinChangeDynamic(6, new[] { 1, 3, 4 })
.SequenceEqual(new[] { 3, 3 })
.Should().BeTrue();
DynamicCoinChangeSolver
.MakeCoinChangeDynamic(6, new[] { 1, 3, 4 })
.SequenceEqual(new[] { 3, 3 })
.Should().BeTrue();

DynamicCoinChangeSolver
.MakeCoinChangeDynamic(8, new[] { 1, 3, 4 })
.SequenceEqual(new[] { 4, 4 })
.Should().BeTrue();
DynamicCoinChangeSolver
.MakeCoinChangeDynamic(8, new[] { 1, 3, 4 })
.SequenceEqual(new[] { 4, 4 })
.Should().BeTrue();

DynamicCoinChangeSolver
.MakeCoinChangeDynamic(25, new[] { 1, 3, 4, 12, 13, 14 })
.SequenceEqual(new[] { 13, 12 })
.Should().BeTrue();
DynamicCoinChangeSolver
.MakeCoinChangeDynamic(25, new[] { 1, 3, 4, 12, 13, 14 })
.SequenceEqual(new[] { 13, 12 })
.Should().BeTrue();

DynamicCoinChangeSolver
.MakeCoinChangeDynamic(26, new[] { 1, 3, 4, 12, 13, 14 })
.SequenceEqual(new[] { 14, 12 })
.Should().BeTrue();
}
DynamicCoinChangeSolver
.MakeCoinChangeDynamic(26, new[] { 1, 3, 4, 12, 13, 14 })
.SequenceEqual(new[] { 14, 12 })
.Should().BeTrue();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using NUnit.Framework;
using Algorithms.Problems.DynamicProgramming;

namespace Algorithms.Tests.DynamicProgramming
namespace Algorithms.Tests.DynamicProgramming;

public class LevenshteinDistanceTests
{
public class LevenshteinDistanceTests
[TestCase("kitten", "sitting", 3)]
[TestCase("bob", "bond", 2)]
[TestCase("algorithm", "logarithm", 3)]
[TestCase("star", "", 4)]
[TestCase("", "star", 4)]
[TestCase("abcde", "12345", 5)]
public void Calculate_ReturnsCorrectLevenshteinDistance(string source, string destination, int expectedDistance)
{
[TestCase("kitten", "sitting", 3)]
[TestCase("bob", "bond", 2)]
[TestCase("algorithm", "logarithm", 3)]
[TestCase("star", "", 4)]
[TestCase("", "star", 4)]
[TestCase("abcde", "12345", 5)]
public void Calculate_ReturnsCorrectLevenshteinDistance(string source, string destination, int expectedDistance)
{
var result = LevenshteinDistance.Calculate(source, destination);
Assert.AreEqual(expectedDistance, result);
}
var result = LevenshteinDistance.Calculate(source, destination);
Assert.AreEqual(expectedDistance, result);
}
}
Loading