<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MOE.Common.Business.SplitFail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MOE.Common.Business.WCFServiceLibrary;
using MOE.CommonTests.Helpers;
using MOE.CommonTests.Models;

namespace MOE.Common.Business.SplitFail.Tests
{
    [TestClass()]
    public class SplitFailPhaseTests
    {
        private InMemoryMOEDatabase inMemoryMoeDatabase = new InMemoryMOEDatabase();
        public SplitFailPhaseTests()
        {
            AddControllerEventLogsToInMemoryDb.LoadControllerEventLogs(inMemoryMoeDatabase);
            inMemoryMoeDatabase.AddTestSignalForSplitFailTest();
        }
        [TestMethod()]
        public void SplitFailPhaseTest()
        {
            SplitFailOptions splitFailOptions = new SplitFailOptions{ EndDate = new DateTime(2017, 10,17, 17, 11, 1 ), StartDate = new DateTime(2017, 10, 17, 17, 8, 13), FirstSecondsOfRed = 1, SignalID = "7185", MetricTypeID = 12, ShowAvgLines = true, ShowPercentFailLines = true, ShowFailLines = true, Y2AxisMax = null, YAxisMin = 0, Y2AxisMin = 0, YAxisMax = null};
            var signal = inMemoryMoeDatabase.Signals.FirstOrDefault();
            SplitFailPhase splitFailPhase = new SplitFailPhase(signal.Approaches.FirstOrDefault(), splitFailOptions, true);
            Assert.IsTrue(splitFailPhase.Cycles[0].StartTime == new DateTime(2017,10, 17, 17, 9, 33));
            Assert.IsTrue(splitFailPhase.Cycles[0].YellowEvent == new DateTime(2017, 10, 17, 17, 10, 09));
            Assert.IsTrue(splitFailPhase.Cycles[0].RedEvent == new DateTime(2017, 10, 17, 17, 10, 13));
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringGreen.Count == 2);
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringGreen[0].DetectorOn == new DateTime(2017, 10, 17, 17, 1, 59, 5));
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringGreen[0].DetectorOff == new DateTime(2017, 10, 17, 17, 9, 43, 8));
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringGreen[0].DurationInMilliseconds == 10800);
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringGreen[1].DetectorOn == new DateTime(2017, 10, 17, 17, 1, 55, 4));
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringGreen[1].DetectorOff == new DateTime(2017, 10, 17, 17, 9, 06, 3));
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringGreen[1].DurationInMilliseconds == 10900);
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringRed.Count == 1);
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringRed[0].DetectorOn == new DateTime(2017, 10, 17, 17, 10, 9, 2));
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringRed[0].DetectorOff == new DateTime(2017, 10, 17, 17, 10, 13, 3));
            Assert.IsTrue(splitFailPhase.Cycles[0].ActivationsDuringRed[0].DurationInMilliseconds == 300);
            Assert.IsTrue(splitFailPhase.Cycles[0].GreenOccupancyPercent == 60.0);
            Assert.IsTrue(splitFailPhase.Cycles[0].GreenOccupancyTimeInMilliseconds == 3600.0);
            Assert.IsTrue(splitFailPhase.Cycles[0].RedOccupancyPercent == 6.0);
            Assert.IsTrue(splitFailPhase.Cycles[0].RedOccupancyTimeInMilliseconds == 300.0);
        }
    }
}<commit_msg>Auto stash before merge of "CyclesAndPlans" and "origin/CyclesAndPlans"<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using MOE.Common.Business.SplitFail;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MOE.Common.Business.WCFServiceLibrary;
using MOE.Common.Models.Repositories;
using MOE.CommonTests.Helpers;
using MOE.CommonTests.Models;

namespace MOE.Common.Business.SplitFail.Tests
{
    [TestClass()]
    public class SplitFailPhaseTests
    {
        private InMemoryMOEDatabase inMemoryMoeDatabase = new InMemoryMOEDatabase();
        public SplitFailPhaseTests()
        {
            AddControllerEventLogsToInMemoryDb.LoadControllerEventLogs(inMemoryMoeDatabase);
            inMemoryMoeDatabase.AddTestSignalForSplitFailTest();
            XMLToListImporter
            //SignalsRepositoryFactory.SetSignalsRepository(new InMemorySignalsRepository(inMemoryMoeDatabase));
            //ControllerEventLogRepositoryFactory.SetRepository(new InMemoryControllerEventLogRepository(inMemoryMoeDatabase));
        }
        [TestMethod()]
        public void SplitFailPhaseTest()
        {
            SplitFailOptions splitFailOptions = new SplitFailOptions{StartDate = new DateTime(2017, 10, 17, 17, 0, 0), EndDate = new DateTime(2017, 10,17, 17, 11, 1 ),  FirstSecondsOfRed = 5, SignalID = "7185", MetricTypeID = 12, ShowAvgLines = true, ShowPercentFailLines = true, ShowFailLines = true, Y2AxisMax = null, YAxisMin = 0, Y2AxisMin = 0, YAxisMax = null};
            var signal = inMemoryMoeDatabase.Signals.FirstOrDefault();
            SplitFailPhase splitFailPhase = new SplitFailPhase(signal.Approaches.FirstOrDefault(), splitFailOptions, true);
            Assert.IsTrue(splitFailPhase.Cycles[4].StartTime == new DateTime(2017,10, 17, 17, 9, 33));
            Assert.IsTrue(splitFailPhase.Cycles[4].YellowEvent == new DateTime(2017, 10, 17, 17, 10, 09));
            Assert.IsTrue(splitFailPhase.Cycles[4].RedEvent == new DateTime(2017, 10, 17, 17, 10, 13));
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringGreen.Count == 2);
            DateTime date1 = new DateTime(2017, 10, 17, 17, 1, 59, 500);
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringGreen[0].DetectorOn == date1);
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringGreen[0].DetectorOff == new DateTime(2017, 10, 17, 17, 9, 43, 800));
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringGreen[0].DurationInMilliseconds == 464300);
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringGreen[1].DetectorOn == new DateTime(2017, 10, 17, 17, 9, 55, 400));
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringGreen[1].DetectorOff == new DateTime(2017, 10, 17, 17, 10, 6, 300));
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringGreen[1].DurationInMilliseconds == 10900);
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringRed.Count == 1);
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringRed[0].DetectorOn == new DateTime(2017, 10, 17, 17, 10, 9, 200));
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringRed[0].DetectorOff == new DateTime(2017, 10, 17, 17, 10, 13, 300));
            Assert.IsTrue(splitFailPhase.Cycles[4].ActivationsDuringRed[0].DurationInMilliseconds == 4100);
            Assert.IsTrue(splitFailPhase.Cycles[4].GreenOccupancyTimeInMilliseconds == 21700.0);
            Assert.IsTrue(splitFailPhase.Cycles[4].TotalGreenTimeMilliseconds == 36000.0);
            Assert.IsTrue(splitFailPhase.Cycles[4].RedOccupancyTimeInMilliseconds == 300.0);
            Assert.IsTrue(splitFailPhase.Cycles[4].RedOccupancyPercent == 6.0);
            Assert.IsTrue(splitFailPhase.Cycles[4].FirstSecondsOfRed == 5); 
            Assert.IsTrue(Math.Round(splitFailPhase.Cycles[4].GreenOccupancyPercent) == 60.0);
            splitFailOptions.CreateMetric();
        }
    }
}
{'fraction_non_alphanumeric': 0.11840324763193505, 'fraction_numerical': 0.06265223274695535, 'mean_word_length': 3.9670698924731185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '977435', 'n_tokens_mistral': 2649, 'n_tokens_neox': 2216, 'n_words': 385}