Beispiel #1
0
        public void TotalRuntimeOfFinishedInstancesIsCorrect()
        {
            var totalRuntime = TimeSpan.Zero;
            var instances    = Enumerable.Range(0, 4).Select(i => new TestInstance($"{i}")).ToList();
            var results      = Enumerable.Range(1, instances.Count).Select(i => new TestResult(TimeSpan.FromSeconds(i * 10))).ToList();

            var stats = new GenomeStats <TestInstance, TestResult>(GenomeStatsTest._genome, Enumerable.Empty <TestInstance>(), instances);

            for (var i = 0; i < instances.Count; i++)
            {
                totalRuntime += results[i].Runtime;
                stats.FinishInstance(instances[i], results[i]).ShouldBeTrue();
            }

            stats.HasOpenInstances.ShouldBeFalse();
            stats.HasOpenOrRunningInstances.ShouldBeFalse();

            stats.FinishedInstances.Count.ShouldBe(instances.Count);
            stats.RuntimeOfFinishedInstances.ShouldBe(totalRuntime);
        }
Beispiel #2
0
        /// <summary>
        /// Creates genome stats for testing.
        /// </summary>
        /// <param name="genome">The genome.</param>
        /// <param name="instances">The instances.</param>
        /// <param name="indexToResult">A function to provide a result by instance index.</param>
        /// <param name="numInstancesToUse">The number of instances to use from the list.</param>
        /// <returns>The genome stats.</returns>
        private GenomeStats <TestInstance, ContinuousResult> CreateStats(
            ImmutableGenome genome,
            IReadOnlyList <TestInstance> instances,
            Func <int, double> indexToResult,
            int?numInstancesToUse = null)
        {
            if (numInstancesToUse == null || numInstancesToUse > instances.Count)
            {
                numInstancesToUse = instances.Count;
            }

            var stats = new GenomeStats <TestInstance, ContinuousResult>(genome, Enumerable.Empty <TestInstance>(), instances);

            for (var i = 0; i < numInstancesToUse; i++)
            {
                var result = new ContinuousResult(indexToResult(i), TimeSpan.Zero);
                stats.FinishInstance(instances[i], result);
            }

            return(stats);
        }