コード例 #1
0
ファイル: MetricTest.cs プロジェクト: mthalman/GenFx.NET
        public void Metric_Serialization()
        {
            MockMetric metric = new MockMetric();

            PrivateObject privObj = new PrivateObject(metric, new PrivateType(typeof(Metric)));

            Dictionary <int, ObservableCollection <MetricResult> > popResults = (Dictionary <int, ObservableCollection <MetricResult> >)privObj.GetField("populationResults");

            ObservableCollection <MetricResult> metricResults = new ObservableCollection <MetricResult>
            {
                new MetricResult(1, 2, 3, metric)
            };

            popResults.Add(0, metricResults);

            MockMetric result = (MockMetric)SerializationHelper.TestSerialization(metric, new Type[0]);

            PrivateObject resultPrivObj = new PrivateObject(result, new PrivateType(typeof(Metric)));

            Dictionary <int, ObservableCollection <MetricResult> > resultPopResults = (Dictionary <int, ObservableCollection <MetricResult> >)resultPrivObj.GetField("populationResults");

            ObservableCollection <MetricResult> resultStatResults = resultPopResults[0];

            Assert.Equal(metricResults[0].GenerationIndex, resultStatResults[0].GenerationIndex);
            Assert.Equal(metricResults[0].PopulationIndex, resultStatResults[0].PopulationIndex);
            Assert.Equal(metricResults[0].ResultValue, resultStatResults[0].ResultValue);
            Assert.Same(result, resultStatResults[0].Metric);
        }
コード例 #2
0
        public void MetricResult_Ctor()
        {
            MockMetric   metric = new MockMetric();
            MetricResult result = new MetricResult(1, 2, 3, metric);

            Assert.Equal(1, result.GenerationIndex);
            Assert.Equal(2, result.PopulationIndex);
            Assert.Equal(3, result.ResultValue);
            Assert.Same(metric, result.Metric);
        }
コード例 #3
0
ファイル: MetricTest.cs プロジェクト: mthalman/GenFx.NET
        public void Metric_Ctor()
        {
            GeneticAlgorithm algorithm = new MockGeneticAlgorithm
            {
                GeneticEntitySeed = new MockEntity(),
                PopulationSeed    = new MockPopulation(),
                SelectionOperator = new MockSelectionOperator(),
                FitnessEvaluator  = new MockFitnessEvaluator(),
            };

            algorithm.Metrics.Add(new MockMetric());

            Metric metric = new MockMetric();

            metric.Initialize(algorithm);
            PrivateObject accessor = new PrivateObject(metric, new PrivateType(typeof(Metric)));

            Assert.Same(accessor.GetProperty("Algorithm"), algorithm);
        }
コード例 #4
0
ファイル: MetricTest.cs プロジェクト: mthalman/GenFx.NET
        public void Metric_Ctor_NullAlgorithm()
        {
            MockMetric metric = new MockMetric();

            Assert.Throws <ArgumentNullException>(() => metric.Initialize(null));
        }