Exemplo n.º 1
0
        public void GeneticComponentExtensions_CreateNewAndInitialize_CreateNewWrongType()
        {
            TestComponentWithCustomizableCreateNew component = new TestComponentWithCustomizableCreateNew
            {
                CreateNewReturnValue = new TestComponent()
            };

            Assert.Throws <InvalidOperationException>(() => GeneticComponentExtensions.CreateNewAndInitialize(component));
        }
Exemplo n.º 2
0
        public void GeneticComponentExtensions_CopyConfigurationStateTo()
        {
            TestComponent source = new TestComponent
            {
                MyProperty = 3
            };

            TestComponent target = new TestComponent();

            GeneticComponentExtensions.CopyConfigurationStateTo(source, target);

            Assert.Equal(source.MyProperty, target.MyProperty);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public void GeneticComponentExtensions_CopyConfigurationStateTo_MisconfiguredConfigProperty()
 {
     Assert.Throws <InvalidOperationException>(() => GeneticComponentExtensions.CopyConfigurationStateTo(new MisconfiguredTestComponent(), new MisconfiguredTestComponent()));
     Assert.Throws <InvalidOperationException>(() => GeneticComponentExtensions.CopyConfigurationStateTo(new MisconfiguredTest2Component(), new MisconfiguredTest2Component()));
 }
Exemplo n.º 5
0
 public void GeneticComponentExtensions_CreateNewAndInitialize_NullComponent()
 {
     Assert.Throws <ArgumentNullException>(() => GeneticComponentExtensions.CreateNewAndInitialize(null));
 }
Exemplo n.º 6
0
 public void GeneticComponentExtensions_CopyConfigurationStateTo_NullTarget()
 {
     Assert.Throws <ArgumentNullException>(() => GeneticComponentExtensions.CopyConfigurationStateTo(new TestComponent(), null));
 }