Beispiel #1
0
        public void Can_Find_Time_Interval_Where_Martys_Meet_Each_Other()
        {
            // Arrange
            var time1            = DateTime.Parse("1985-10-21T10:05:00Z");
            var time2            = DateTime.Parse("1985-10-21T10:10:00Z");
            var time3            = DateTime.Parse("1985-10-21T10:09:00Z");
            var time4            = DateTime.Parse("1985-10-21T10:17:00Z");
            var expectedInterval = new TimePeriod(time3, time2);
            var events           = (new List <DateTime>(4)
            {
                time1, time3, time2, time4
            })
                                   //.OrderBy(dateTime => dateTime)
                                   .Select(dateTime => new TimeEvent(dateTime));
            GroupOfMarty gom    = new GroupOfMarty();
            var          marty1 = new Marty("MartyTimeline1", new List <(DateTime, DateTime)> {
                (time1, time2)
            });
            var marty2 = new Marty("MartyTimeline2", new List <(DateTime, DateTime)> {
                (time3, time4)
            });

            gom.AddMarty(marty1);
            gom.AddMarty(marty2);
            var deloreane = new TimeMachine();

            //Act
            MartysMeetEachOther mmeo = deloreane.PlayWithTime(gom, events);

            // Assert
            Assert.Single(mmeo.TimePeriods);
            Assert.Equal(mmeo.TimePeriods[0], expectedInterval);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var events = (new List <DateTime>(16)
            {
                DateTime.Parse("1985-10-21T10:05:00Z"), DateTime.Parse("1985-10-21T14:05:00Z"),
                DateTime.Parse("1955-11-12T13:50:00Z"), DateTime.Parse("1955-11-12T23:30:00Z"),
                DateTime.Parse("1985-10-21T15:07:00Z"), DateTime.Parse("1985-10-21T16:00:00Z"),
                DateTime.Parse("2015-10-21T15:00:00Z"), DateTime.Parse("2015-10-21T18:00:00Z"),
                DateTime.Parse("2015-01-01T00:00:00Z"), DateTime.Parse("2016-01-01T00:00:00Z"),
                DateTime.Parse("1955-11-12T17:00:00Z"), DateTime.Parse("1955-11-12T23:30:00Z"),
                DateTime.Parse("1885-10-21T10:00:00Z"), DateTime.Parse("1885-10-22T23:00:00Z"),
                DateTime.Parse("2015-10-22T15:05:00Z"), DateTime.Parse("2015-10-22T20:00:00Z")
            })
                         .OrderBy(d => d)
                         .Distinct()
                         .Select(date => new TimeEvent(date));
            var marty1 = new Marty("MartyTimeline1", new List <(DateTime, DateTime)> {
                (DateTime.Parse("1985-10-21T10:05:00Z"), DateTime.Parse("1985-10-21T14:05:00Z"))
            });
            var marty2 = new Marty("MartyTimeline2", new List <(DateTime, DateTime)> {
                (DateTime.Parse("1955-11-12T13:50:00Z"), DateTime.Parse("1955-11-12T23:30:00Z")),
                (DateTime.Parse("1985-10-21T15:07:00Z"), DateTime.Parse("1985-10-21T16:00:00Z")),
                (DateTime.Parse("2015-10-21T15:00:00Z"), DateTime.Parse("2015-10-21T18:00:00Z"))
            });
            var marty2prime = new Marty("MartyTimeline2'", new List <(DateTime, DateTime)> {
                (DateTime.Parse("2015-01-01T00:00:00Z"), DateTime.Parse("2016-01-01T00:00:00Z"))
            });
            var marty3 = new Marty("MartyTimeline3", new List <(DateTime, DateTime)> {
                (DateTime.Parse("1955-11-12T17:00:00Z"), DateTime.Parse("1955-11-12T23:30:00Z")),
                (DateTime.Parse("1885-10-21T10:00:00Z"), DateTime.Parse("1885-10-22T23:00:00Z")),
                (DateTime.Parse("2015-10-22T15:05:00Z"), DateTime.Parse("2015-10-22T20:00:00Z"))
            });
            var gom = new GroupOfMarty();

            gom.AddRangeOfMarty(new List <Marty>(4)
            {
                marty1, marty2, marty2prime, marty3
            });


            var deloreane = new TimeMachine();

            try
            {
                MartysMeetEachOther mmeo = deloreane.PlayWithTime(gom, events);
                Console.WriteLine(mmeo);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            Console.ReadKey();
        }