Пример #1
0
        public async Task RunDirectTest()
        {
            var experimentPipeline = new ExperimentPipeline(
                new ExperimentGenerator(new RandomizeService()),
                Mock.Of <IWorkerExperimentService>(),
                Mock.Of <IExperimentTestResultService>(),
                Mock.Of <IReportsService>(),
                Mock.Of <ILogger <ExperimentPipeline> >(),
                Mock.Of <IOptions <DbSettings> >(),
                new OnlineExecutor());

            var experiments = new List <Experiment>
            {
                new Experiment
                {
                    Id = Guid.NewGuid(),
                    N1 = 10, N2 = 40, N12 = 10, N21 = 40,
                    RequirementsAmount   = 10000,
                    TestsAmount          = 100,
                    BorderGenerationType = Distribution.Uniform, PGenerationType = Distribution.Uniform,
                    MinPercentageFromA   = 50, MaxPercentageFromA = 50,
                    MinBoundaryRange     = 10, MaxBoundaryRange = 1000
                }
            };

            await experimentPipeline.Run(experiments, false, true);
        }
Пример #2
0
        public async Task Test1(
            IEnumerable <Detail> j1,
            IEnumerable <Detail> j2,
            IEnumerable <LaboriousDetail> j12,
            IEnumerable <LaboriousDetail> j21)
        {
            // Arrange
            var experimentInfo = new ExperimentInfo();

            experimentInfo.J1.AddRange(j1);
            experimentInfo.J2.AddRange(j2);
            experimentInfo.J12.AddRange(j12);
            experimentInfo.J21.AddRange(j21);

            var experiment = new Experiment
            {
                Id          = Guid.NewGuid(),
                TestsAmount = 1
            };

            var generatorMock = new Mock <IExperimentGenerator>();

            generatorMock.Setup(g =>
                                g.GenerateDataForTest(It.Is <Experiment>(ex => ex.Id == experiment.Id), It.IsAny <int>()))
            .Returns(() => experimentInfo);

            var originalGenerator = new ExperimentGenerator(new RandomizeService());

            generatorMock.Setup(g => g.GenerateP(It.IsAny <IOnlineChainNode>()))
            .Callback <IOnlineChainNode>(node => originalGenerator.GenerateP(node));

            ExperimentInfo resultInfo = null;

            var experimentTestResultService = new Mock <IExperimentTestResultService>();

            experimentTestResultService
            .Setup(e => e.SaveExperimentTestResult(It.Is <Guid>(id => id == experiment.Id),
                                                   It.IsAny <ExperimentInfo>()))
            .Callback <Guid, ExperimentInfo>((id, info) => resultInfo = info);

            var experimentPipeline = new ExperimentPipeline(
                generatorMock.Object,
                Mock.Of <IWorkerExperimentService>(),
                experimentTestResultService.Object,
                Mock.Of <IReportsService>(),
                Mock.Of <ILogger <ExperimentPipeline> >(),
                Mock.Of <IOptions <DbSettings> >(),
                new OnlineExecutor());

            // Act
            await experimentPipeline.Run(Enumerable.Empty <Experiment>().Append(experiment));

            // Assert
            Assert.NotNull(resultInfo);
        }
Пример #3
0
        public async Task Experiment_ShouldBeFinishedWithoutAnyExceptions(string path, ExperimentInfo experimentInfo)
        {
            // Arrange
            _outputHelper.WriteLine($"Running test with data from '{path}'");

            var experiment = new Experiment
            {
                Id          = Guid.NewGuid(),
                TestsAmount = 1
            };

            var generatorMock = new Mock <IExperimentGenerator>();

            generatorMock.Setup(g =>
                                g.GenerateDataForTest(It.Is <Experiment>(ex => ex.Id == experiment.Id), It.IsAny <int>()))
            .Returns(() => experimentInfo);
            ExperimentInfo resultInfo = null;
            var            experimentTestResultService = new Mock <IExperimentTestResultService>();

            experimentTestResultService
            .Setup(e => e.SaveExperimentTestResult(It.Is <Guid>(id => id == experiment.Id),
                                                   It.IsAny <ExperimentInfo>()))
            .Callback <Guid, ExperimentInfo>((id, info) => resultInfo = info);

            ExperimentReport experimentReport = null;
            var reportServiceMock             = new Mock <IReportsService>();

            reportServiceMock.Setup(x => x.Save(It.Is <ExperimentReport>(r => r.ExperimentId == experiment.Id)))
            .Callback <ExperimentReport>((report) => experimentReport = report);

            var experimentPipeline = new ExperimentPipeline(
                generatorMock.Object,
                Mock.Of <IWorkerExperimentService>(),
                experimentTestResultService.Object,
                reportServiceMock.Object,
                Mock.Of <ILogger <ExperimentPipeline> >(),
                Mock.Of <IOptions <DbSettings> >(),
                new OnlineExecutor());

            // Act
            await experimentPipeline.Run(new[]
            {
                experiment
            }, false, true);

            // Assert
            resultInfo.Should().NotBeNull();
            experimentReport.Should().NotBeNull();
        }
Пример #4
0
        public static void Main(string[] args)
        {
            var experiment = ReadExperimentFromConsole();

            if (experiment == null)
            {
                return;
            }

            var reportsServiceMock  = new Mock <IReportsService>();
            ExperimentReport report = null;

            reportsServiceMock
            .Setup(r => r.Save(It.Is <ExperimentReport>(e => e.ExperimentId == experiment.Id)))
            .Callback <ExperimentReport>(rep => report = rep);

            var pipeline = new ExperimentPipeline(
                new ExperimentGenerator(new RandomizeService()),
                Mock.Of <IWorkerExperimentService>(),
                new ExperimentTestResultFileService(),
                reportsServiceMock.Object,
                Mock.Of <ILogger <ExperimentPipeline> >(),
                Mock.Of <IOptions <DbSettings> >(),
                new OnlineExecutor());

            var stopwatch = Stopwatch.StartNew();

            pipeline.Run(new List <Experiment> {
                experiment
            }).ConfigureAwait(false);
            stopwatch.Stop();

            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("\n\n---------   RESULTS OF EXPERIMENTS' EXECUTION   ---------");

            Console.WriteLine(
                $"Time of execution experiments: {TimeSpan.FromMilliseconds(stopwatch.ElapsedMilliseconds):%m' minute(s) '%s' second(s)'}\n\n");

            Console.WriteLine($"Amounts of tests: {experiment.TestsAmount}");
            Console.WriteLine(
                $"Amounts of resolved tests in offline mode: {experiment.Results.Count}, {experiment.Results.Count * 100 / (double) experiment.TestsAmount:0.###}%");
            Console.WriteLine($"Amounts of resolved tests in STOP 1.1: {report?.Stop1Percentage}%");
            Console.WriteLine($"Amounts of resolved tests in STOP 1.2: {report?.Stop2Percentage}%");
            Console.WriteLine($"Amounts of resolved tests in STOP 1.3: {report?.Stop3Percentage}%");
            Console.WriteLine($"Amounts of resolved tests in STOP 1.4: {report?.Stop4Percentage}%");

            Console.ReadKey();