-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e55d1b9
commit bffc489
Showing
37 changed files
with
868 additions
and
159 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
GeneticAlgorithm.UnitTests/Components/CrossoverManagers/AlternatingPositionCrossoverTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using GeneticAlgorithm.Components.CrossoverManagers; | ||
using GeneticAlgorithm.Interfaces; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GeneticAlgorithm.UnitTests.Components.CrossoverManagers | ||
{ | ||
[TestClass] | ||
public class AlternatingPositionCrossoverTests | ||
{ | ||
private readonly ICrossoverManager crossoverManager = new AlternatingPositionCrossover<string>(null, null); | ||
|
||
[TestMethod] | ||
[DataRow(20)] | ||
public void OrderCrossover_AllElementsInEachVector(int vectors) | ||
{ | ||
crossoverManager.TestThatAllElementsInEachVector(vectors); | ||
} | ||
|
||
[TestMethod] | ||
public void OrderCrossover_ChildChanged() | ||
{ | ||
crossoverManager.TestThatChildChanged(); | ||
} | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
GeneticAlgorithm.UnitTests/Components/CrossoverManagers/OrderBasedCrossoverTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using GeneticAlgorithm.Components.CrossoverManagers; | ||
using GeneticAlgorithm.Interfaces; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GeneticAlgorithm.UnitTests.Components.CrossoverManagers | ||
{ | ||
[TestClass] | ||
public class OrderBassedCrossoverTests | ||
{ | ||
private readonly ICrossoverManager crossoverManager = new OrderBasedCrossover<string>(null, null); | ||
|
||
[TestMethod] | ||
[DataRow(20)] | ||
public void OrderBasedCrossover_AllElementsInEachVector(int vectors) | ||
{ | ||
crossoverManager.TestThatAllElementsInEachVector(vectors); | ||
} | ||
|
||
[TestMethod] | ||
public void OrderBasedCrossover_ChildChanged() | ||
{ | ||
crossoverManager.TestThatChildChanged(); | ||
} | ||
} | ||
} |
38 changes: 3 additions & 35 deletions
38
GeneticAlgorithm.UnitTests/Components/CrossoverManagers/OrderCrossoverTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GeneticAlgorithm.Components.Chromosomes; | ||
using GeneticAlgorithm.Components.CrossoverManagers; | ||
using GeneticAlgorithm.Components.PopulationGenerators; | ||
using GeneticAlgorithm.Components.CrossoverManagers; | ||
using GeneticAlgorithm.Interfaces; | ||
using GeneticAlgorithm.UnitTests.TestUtils; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GeneticAlgorithm.UnitTests.Components.CrossoverManagers | ||
{ | ||
[TestClass] | ||
public class OrderCrossoverTests | ||
{ | ||
private static readonly List<string> elements = new List<string>() { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; | ||
private readonly IPopulationGenerator generator = new AllElementsVectorChromosomePopulationGenerator<string>(elements, null, null); | ||
private readonly ICrossoverManager crossoverManager = new OrderCrossover<string>(null, null); | ||
|
||
[TestMethod] | ||
[DataRow(20)] | ||
public void OrderCrossover_AllElementsInEachVector(int vectors) | ||
{ | ||
for (int i = 0; i < vectors; i++) | ||
{ | ||
var parentChromosomes = generator.GeneratePopulation(2); | ||
var child = (VectorChromosome<string>)crossoverManager.Crossover(parentChromosomes.ElementAt(0), parentChromosomes.ElementAt(1)); | ||
child.AssertContainSameElements(elements); | ||
} | ||
crossoverManager.TestThatAllElementsInEachVector(vectors); | ||
} | ||
|
||
[TestMethod] | ||
public void OrderCrossover_ChildChanged() | ||
{ | ||
// Since there's a certain chance that this test will fail, I want to run it twice | ||
var passed = false; | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
var parentChromosomes = generator.GeneratePopulation(2); | ||
var child = (VectorChromosome<string>) crossoverManager.Crossover(parentChromosomes.ElementAt(0), | ||
parentChromosomes.ElementAt(1)); | ||
|
||
try | ||
{ | ||
((VectorChromosome<string>)parentChromosomes.ElementAt(0)).AssertAreNotTheSame(child); | ||
((VectorChromosome<string>)parentChromosomes.ElementAt(1)).AssertAreNotTheSame(child); | ||
passed = true; | ||
} | ||
catch | ||
{ | ||
// Do nothing | ||
} | ||
} | ||
Assert.IsTrue(passed); | ||
crossoverManager.TestThatChildChanged(); | ||
} | ||
} | ||
} |
37 changes: 3 additions & 34 deletions
37
GeneticAlgorithm.UnitTests/Components/CrossoverManagers/PartiallyMappedCrossoverTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,25 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using GeneticAlgorithm.Components.Chromosomes; | ||
using GeneticAlgorithm.Components.CrossoverManagers; | ||
using GeneticAlgorithm.Components.PopulationGenerators; | ||
using GeneticAlgorithm.Components.CrossoverManagers; | ||
using GeneticAlgorithm.Interfaces; | ||
using GeneticAlgorithm.UnitTests.TestUtils; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GeneticAlgorithm.UnitTests.Components.CrossoverManagers | ||
{ | ||
[TestClass] | ||
public class PartiallyMappedCrossoverTests | ||
{ | ||
private static readonly List<string> elements = new List<string>() { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; | ||
private readonly IPopulationGenerator generator = new AllElementsVectorChromosomePopulationGenerator<string>(elements, null, null); | ||
private readonly ICrossoverManager crossoverManager = new PartiallyMappedCrossover<string>(null, null); | ||
|
||
[TestMethod] | ||
[DataRow(20)] | ||
public void PartiallyMatchedCrossover_AllElementsInEachVector(int vectors) | ||
{ | ||
for (int i = 0; i < vectors; i++) | ||
{ | ||
var parentChromosomes = generator.GeneratePopulation(2); | ||
var child = (VectorChromosome<string>)crossoverManager.Crossover(parentChromosomes.ElementAt(0), parentChromosomes.ElementAt(1)); | ||
child.AssertContainSameElements(elements); | ||
} | ||
crossoverManager.TestThatAllElementsInEachVector(vectors); | ||
} | ||
|
||
[TestMethod] | ||
public void PartiallyMatchedCrossover_ChildChanged() | ||
{ | ||
// Since there's a certain chance that this test will fail, I want to run it twice | ||
var passed = false; | ||
for (int i = 0; i < 2; i++) | ||
{ | ||
var parentChromosomes = generator.GeneratePopulation(2); | ||
var child = (VectorChromosome<string>)crossoverManager.Crossover(parentChromosomes.ElementAt(0), | ||
parentChromosomes.ElementAt(1)); | ||
|
||
try | ||
{ | ||
((VectorChromosome<string>)parentChromosomes.ElementAt(0)).AssertAreNotTheSame(child); | ||
((VectorChromosome<string>)parentChromosomes.ElementAt(1)).AssertAreNotTheSame(child); | ||
passed = true; | ||
} | ||
catch | ||
{ | ||
// Do nothing | ||
} | ||
} | ||
Assert.IsTrue(passed); | ||
crossoverManager.TestThatChildChanged(); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ticAlgorithm.UnitTests/Components/CrossoverManagers/PositionBasedCrossoverManagerTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using GeneticAlgorithm.Components.CrossoverManagers; | ||
using GeneticAlgorithm.Interfaces; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GeneticAlgorithm.UnitTests.Components.CrossoverManagers | ||
{ | ||
[TestClass] | ||
public class PositionBasedCrossoverManagerTests | ||
{ | ||
private readonly ICrossoverManager crossoverManager = new PositionBasedCrossoverManager<string>(null, null); | ||
|
||
[TestMethod] | ||
[DataRow(20)] | ||
public void PositionBasedCrossover_AllElementsInEachVector(int vectors) | ||
{ | ||
crossoverManager.TestThatAllElementsInEachVector(vectors); | ||
} | ||
|
||
[TestMethod] | ||
public void PositionBasedCrossover_ChildChanged() | ||
{ | ||
crossoverManager.TestThatChildChanged(); | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
GeneticAlgorithm.UnitTests/Components/MutationManagers/DisplacementMutationManagerTests.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using GeneticAlgorithm.Components.Interfaces; | ||
using GeneticAlgorithm.Components.MutationManagers; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace GeneticAlgorithm.UnitTests.Components.MutationManagers | ||
{ | ||
[TestClass] | ||
public class DisplacementMutationManagerTests | ||
{ | ||
private readonly IMutationManager<string> mutationManager = new DisplacementMutationManager<string>(); | ||
|
||
[TestMethod] | ||
[DataRow(20)] | ||
public void DisplacementMutationManager_AllElementsInEachVector(int vectors) | ||
{ | ||
mutationManager.TestAllElementsInEachVector(vectors); | ||
} | ||
|
||
// This test is probabilistic, so there's a certain chance that this test will fail even if the code is okay. | ||
[TestMethod] | ||
public void DisplacementMutationManager_ChromosomeChanged() | ||
{ | ||
mutationManager.TestChromosomeChanged(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.