Skip to content

Commit

Permalink
Merge pull request #6 from patHyatt/master
Browse files Browse the repository at this point in the history
Added testing
  • Loading branch information
jsvazic committed Oct 12, 2011
2 parents f2bc075 + a12ca85 commit 27dad7b
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
73 changes: 73 additions & 0 deletions C#/GAHelloWorld/GAHelloWorldTest/ChromosomeTest.cs
@@ -0,0 +1,73 @@
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using GAHelloWorld;

namespace GAHelloWorldTest
{
[TestClass]
public class ChromosomeTest
{
[TestMethod]
public void TestMutate()
{
Chromosome.SetTargetGene("ADE");

Chromosome first = new Chromosome("ABC");
Chromosome second = new Chromosome("DEF");

var children = first.Mate(second);

Console.WriteLine(children.First().Gene);
Console.WriteLine(children.Last().Gene);
}

[TestMethod]
public void TestFitnessMatch()
{
Chromosome.SetTargetGene("ABCD");

Chromosome first = new Chromosome("ABCD");

System.Diagnostics.Debug.Assert(first.Fitness == 0);
}

[TestMethod]
public void TestFitnessNoMatch()
{
Chromosome.SetTargetGene("ABCF");

Chromosome first = new Chromosome("ABCE");

System.Diagnostics.Debug.Assert(first.Fitness == 1);
}

[TestMethod]
public void TestSelfComparison()
{
Chromosome test = new Chromosome("#$A12");

System.Diagnostics.Debug.Assert(test.CompareTo(test) == 0);
}

[TestMethod]
public void TestMutationDifferences()
{
Chromosome.SetTargetGene("1234ABCD");

Chromosome chrome1 = new Chromosome("!@ACE345");
Chromosome chrome2 = new Chromosome("789XYZ89");

var children = chrome1.Mate(chrome2);

foreach (Chromosome child in children)
{
System.Diagnostics.Debug.Assert(child.CompareTo(chrome1) != 0);
System.Diagnostics.Debug.Assert(child.CompareTo(chrome2) != 0);
}
}
}
}
65 changes: 65 additions & 0 deletions C#/GAHelloWorld/GAHelloWorldTest/GAHelloWorldTest.csproj
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0EA38C02-4993-41DF-96ED-2C303D38D63F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>GAHelloWorldTest</RootNamespace>
<AssemblyName>GAHelloWorldTest</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
<Visible>False</Visible>
</CodeAnalysisDependentAssemblyPaths>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ChromosomeTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\GAHelloWorld.csproj">
<Project>{68AF64D4-69B2-492F-90B6-B0DBE6A7EA43}</Project>
<Name>GAHelloWorld</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
35 changes: 35 additions & 0 deletions C#/GAHelloWorld/GAHelloWorldTest/Properties/AssemblyInfo.cs
@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("GAHelloWorldTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GAHelloWorldTest")]
[assembly: AssemblyCopyright("Copyright © 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4c04a577-6dab-4af2-88f7-d8d4d4973045")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 27dad7b

Please sign in to comment.