public void GeneticComponentExtensions_CreateNewAndInitialize_CreateNewWrongType() { TestComponentWithCustomizableCreateNew component = new TestComponentWithCustomizableCreateNew { CreateNewReturnValue = new TestComponent() }; Assert.Throws <InvalidOperationException>(() => GeneticComponentExtensions.CreateNewAndInitialize(component)); }
public void GeneticComponentExtensions_CopyConfigurationStateTo() { TestComponent source = new TestComponent { MyProperty = 3 }; TestComponent target = new TestComponent(); GeneticComponentExtensions.CopyConfigurationStateTo(source, target); Assert.Equal(source.MyProperty, target.MyProperty); }
public void GeneticComponentExtensions_CreateNewAndInitialize() { TestComponent component = new TestComponent(); component.MyProperty = 5; TestComponent newComponent = (TestComponent)GeneticComponentExtensions.CreateNewAndInitialize(component); Assert.NotSame(component, newComponent); Assert.Equal(component.MyProperty, newComponent.MyProperty); TestComponentWithAlgorithm componentWithAlg = new TestComponentWithAlgorithm(); MockGeneticAlgorithm algorithm = new MockGeneticAlgorithm(); componentWithAlg.Initialize(algorithm); TestComponentWithAlgorithm newComponentWithAlg = (TestComponentWithAlgorithm)GeneticComponentExtensions.CreateNewAndInitialize(componentWithAlg); Assert.NotSame(componentWithAlg, newComponentWithAlg); Assert.Same(componentWithAlg.Algorithm, newComponentWithAlg.Algorithm); Assert.True(componentWithAlg.InitializeCalled); }
public void GeneticComponentExtensions_CopyConfigurationStateTo_MisconfiguredConfigProperty() { Assert.Throws <InvalidOperationException>(() => GeneticComponentExtensions.CopyConfigurationStateTo(new MisconfiguredTestComponent(), new MisconfiguredTestComponent())); Assert.Throws <InvalidOperationException>(() => GeneticComponentExtensions.CopyConfigurationStateTo(new MisconfiguredTest2Component(), new MisconfiguredTest2Component())); }
public void GeneticComponentExtensions_CreateNewAndInitialize_NullComponent() { Assert.Throws <ArgumentNullException>(() => GeneticComponentExtensions.CreateNewAndInitialize(null)); }
public void GeneticComponentExtensions_CopyConfigurationStateTo_NullTarget() { Assert.Throws <ArgumentNullException>(() => GeneticComponentExtensions.CopyConfigurationStateTo(new TestComponent(), null)); }