Beispiel #1
0
        protected override void Context()
        {
            base.Context();
            _populationSimulation = A.Fake <PopulationSimulation>();
            _parameterValueCache  = new ParameterValuesCache();
            _parameterValueCache.Add(new[] { new ParameterValue("PATH1", 1, 0.1), new ParameterValue("PATH2", 2, 0.2) });
            _parameterValueCache.Add(new[] { new ParameterValue("PATH1", 11, 0.11), new ParameterValue("PATH2", 11, 0.22) });

            _population = CreateRandomPopulation();
            A.CallTo(() => _populationSimulation.BuildingBlock <RandomPopulation>()).Returns(_population);
            A.CallTo(() => _populationSimulation.ParameterValuesCache).Returns(_parameterValueCache);
        }
        protected override void Context()
        {
            base.Context();
            _originalValueCache = new ParameterValuesCache();

            //3 individuals to in original pop
            _originalIndividualIds = new List <int> {
                1, 2, 3
            };

            var parameterValues1 = new ParameterValues("Path1");

            parameterValues1.Add(new double[] { 2, 3, 4 });

            var parameterValues2 = new ParameterValues("Path2");

            parameterValues2.Add(new double[] { 4, 5, 6 });

            _originalValueCache.Add(parameterValues1);
            _originalValueCache.Add(parameterValues2);

            _originalCovariates = new CovariateValuesCache();
            _originalCovariates.Add("Gender", new[] { "Male", "Female", "Female" });

            _parameterCache = new PathCacheForSpecs <IParameter>();

            _cacheToMerge = new ParameterValuesCache();
            var parameterValuesToMerge1 = new ParameterValues("Path1");

            parameterValuesToMerge1.Add(new double[] { 10, 20 });
            _cacheToMerge.Add(parameterValuesToMerge1);

            var parameterValuesToMerge2 = new ParameterValues("Path3");

            parameterValuesToMerge2.Add(new double[] { 30, 40 });
            _cacheToMerge.Add(parameterValuesToMerge2);

            _covariatesToMerge = new CovariateValuesCache();
            _covariatesToMerge.Add("Gender", new[] { "Female", "Female" });
            _covariatesToMerge.Add("Population", new[] { "European", "American" });


            _individualIdsToMerge = new List <int> {
                10, 20
            };
            sut = new IndividualValuesCache(_originalValueCache, _originalCovariates, _originalIndividualIds);
            _individualPropertiesCacheToMerge = new IndividualValuesCache(_cacheToMerge, _covariatesToMerge, _individualIdsToMerge);
        }
Beispiel #3
0
        public void Convert(XElement element)
        {
            foreach (var parameterCacheElement in element.Descendants("ParameterValuesCache").ToList())
            {
                var parameterValuesCache = new ParameterValuesCache();

                foreach (var dataColumnNode in parameterCacheElement.Descendants(ConverterConstants.Serialization.DATA_TABLE_COLUMN))
                {
                    var parameterValues = new ParameterValues(dataColumnNode.GetAttribute(CoreConstants.Serialization.Attribute.Name));
                    parameterValuesCache.Add(parameterValues);
                }

                var documentElement = parameterCacheElement.Descendants("DocumentElement").First();
                foreach (var parameterValuesElement in documentElement.Descendants("ParameterValues"))
                {
                    int index = 0;
                    foreach (var parameterValue in parameterValuesElement.Descendants())
                    {
                        var parameterValues = parameterValuesCache.ParameterValuesAt(index);
                        parameterValues.Add(parameterValue.Value.ConvertedTo <double>());
                        index++;
                    }
                }

                var writer     = _container.Resolve <IXmlWriter <ParameterValuesCache> >();
                var newElement = writer.WriteFor(parameterValuesCache, SerializationTransaction.Create());

                var parent = parameterCacheElement.Parent;
                parameterCacheElement.Remove();
                parent.Add(newElement);
            }
        }
 public void should_have_added_the_existing_parameter_by_path_as_population_parameters()
 {
     A.CallTo(() => _parameterValueCache.Add(_value1)).MustHaveHappened();
     A.CallTo(() => _parameterValueCache.Add(_value2)).MustNotHaveHappened();
     A.CallTo(() => _parameterValueCache.Add(_value3)).MustHaveHappened();
 }