Exemplo n.º 1
0
        public void Ctor_01()
        {
            // arrange:
            UnLocode  dpLocode   = new UnLocode("DPLOC");
            ILocation dpLocation = MockRepository.GenerateStrictMock <ILocation>();

            dpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            DateTime  dpTime     = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            UnLocode  arLocode   = new UnLocode("ARLOC");
            ILocation arLocation = MockRepository.GenerateStrictMock <ILocation>();

            arLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            // act:
            ICarrierMovement target = new CarrierMovement(dpLocation, dpTime, arLocation, arTime);

            // assert:
            Assert.AreEqual(dpTime, target.DepartureTime);
            Assert.AreEqual(arTime, target.ArrivalTime);
            Assert.AreSame(dpLocode, target.DepartureLocation);
            Assert.AreSame(arLocode, target.ArrivalLocation);
            dpLocation.VerifyAllExpectations();
            arLocation.VerifyAllExpectations();
        }
Exemplo n.º 2
0
            public void Add(CarrierMovement carrierMovement)
            {
                AddNode(carrierMovement.ArrivalLocationId.Value);
                AddNode(carrierMovement.DepartureLocationId.Value);

                Nodes[carrierMovement.DepartureLocationId.Value].AddEdge(Nodes[carrierMovement.ArrivalLocationId.Value], carrierMovement);
            }
Exemplo n.º 3
0
        public void Equals_06()
        {
            // arrange:
            UnLocode  dpLocode         = new UnLocode("DPLOC");
            UnLocode  arLocode         = new UnLocode("ARLOC");
            ILocation targetDpLocation = MockRepository.GenerateStrictMock <ILocation>();
            ILocation targetArLocation = MockRepository.GenerateStrictMock <ILocation>();

            targetDpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            targetArLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime dpTime = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            ICarrierMovement mock = MockRepository.GenerateStrictMock <ICarrierMovement>();

            mock.Expect(m => m.DepartureLocation).Return(dpLocode).Repeat.Once();
            mock.Expect(m => m.ArrivalLocation).Return(arLocode).Repeat.Once();
            mock.Expect(m => m.ArrivalTime).Return(arTime).Repeat.Once();
            mock.Expect(m => m.DepartureTime).Return(dpTime).Repeat.Once();


            // act:
            ICarrierMovement target    = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);
            bool             areEquals = target.Equals((object)mock);

            // assert:
            Assert.IsTrue(areEquals);
            targetDpLocation.VerifyAllExpectations();
            targetArLocation.VerifyAllExpectations();
            mock.VerifyAllExpectations();
        }
Exemplo n.º 4
0
 public Edge(
     Node target,
     CarrierMovement carrierMovement)
 {
     Target          = target;
     CarrierMovement = carrierMovement;
 }
Exemplo n.º 5
0
        public void Equals_07()
        {
            // arrange:
            UnLocode  dpLocode         = new UnLocode("DPLOC");
            UnLocode  arLocode         = new UnLocode("ARLOC");
            ILocation targetDpLocation = MockRepository.GenerateStrictMock <ILocation>();
            ILocation targetArLocation = MockRepository.GenerateStrictMock <ILocation>();

            targetDpLocation.Expect(l => l.UnLocode).Return(dpLocode).Repeat.AtLeastOnce();
            targetArLocation.Expect(l => l.UnLocode).Return(arLocode).Repeat.AtLeastOnce();
            DateTime dpTime = DateTime.UtcNow - new TimeSpan(48, 0, 0);
            DateTime arTime = DateTime.UtcNow + new TimeSpan(48, 0, 0);

            // act:
            ICarrierMovement target1 = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);
            ICarrierMovement target2 = new CarrierMovement(targetDpLocation, dpTime, targetArLocation, arTime);

            // assert:
            Assert.IsTrue(target1.Equals(target2));
            Assert.IsTrue(target2.Equals(target1));
            Assert.IsTrue(target1.Equals((object)target2));
            Assert.IsTrue(target2.Equals((object)target1));
            Assert.AreEqual(target1.GetHashCode(), target2.GetHashCode());
            targetDpLocation.VerifyAllExpectations();
            targetArLocation.VerifyAllExpectations();
        }
Exemplo n.º 6
0
 private static TransitEdge ToEdge(Voyage voyage, CarrierMovement movement)
 {
     return(new TransitEdge(voyage,
                            movement.TransportLeg.DepartureLocation.UnLocode.CodeString,
                            movement.TransportLeg.ArrivalLocation.UnLocode.CodeString,
                            movement.DepartureTime,
                            movement.ArrivalTime));
 }
Exemplo n.º 7
0
        private static Path CreatePath(Route route, Path currentPath, CarrierMovement carrierMovement, Node target)
        {
            if (currentPath.CurrentTime.IsAfter(carrierMovement.DepartureTime))
            {
                return(null);
            }
            if (carrierMovement.ArrivalTime.IsAfter(route.ArrivalDeadline))
            {
                return(null);
            }

            var distance = (carrierMovement.ArrivalTime - currentPath.CurrentTime).TotalHours;

            return(currentPath.AppendAndCreate(
                       distance,
                       carrierMovement.ArrivalTime,
                       target,
                       carrierMovement));
        }
        public void TestSameValueAsEqualsHashCode()
        {
            var cm1 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm2 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm3 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());
            var cm4 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());            

            Assert.IsTrue(cm1.SameValueAs(cm2));
            Assert.IsFalse(cm2.SameValueAs(cm3));
            Assert.IsTrue(cm3.SameValueAs(cm4));

            Assert.IsTrue(cm1.Equals(cm2));
            Assert.IsFalse(cm2.Equals(cm3));
            Assert.IsTrue(cm3.Equals(cm4));

            Assert.IsTrue(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.IsFalse(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.IsTrue(cm3.GetHashCode() == cm4.GetHashCode());
        }
Exemplo n.º 9
0
        public void TestSameValueAsEqualsHashCode()
        {
            var cm1 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm2 = new CarrierMovement(SampleLocations.STOCKHOLM, SampleLocations.HAMBURG, new DateTime(), new DateTime());
            var cm3 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());
            var cm4 = new CarrierMovement(SampleLocations.HAMBURG, SampleLocations.STOCKHOLM, new DateTime(), new DateTime());

            Assert.IsTrue(cm1.SameValueAs(cm2));
            Assert.IsFalse(cm2.SameValueAs(cm3));
            Assert.IsTrue(cm3.SameValueAs(cm4));

            Assert.IsTrue(cm1.Equals(cm2));
            Assert.IsFalse(cm2.Equals(cm3));
            Assert.IsTrue(cm3.Equals(cm4));

            Assert.IsTrue(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.IsFalse(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.IsTrue(cm3.GetHashCode() == cm4.GetHashCode());
        }
Exemplo n.º 10
0
        public void testSameValueAsEqualsHashCode()
        {
            CarrierMovement cm1 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm2 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm3 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));
            CarrierMovement cm4 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));

            Assert.True(cm1.sameValueAs(cm2));
            Assert.False(cm2.sameValueAs(cm3));
            Assert.True(cm3.sameValueAs(cm4));

            Assert.True(cm1.Equals(cm2));
            Assert.False(cm2.Equals(cm3));
            Assert.True(cm3.Equals(cm4));

            Assert.True(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.False(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.True(cm3.GetHashCode() == cm4.GetHashCode());
        }
Exemplo n.º 11
0
        public void testSameValueAsEqualsHashCode()
        {
            CarrierMovement cm1 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm2 = new CarrierMovement(L.STOCKHOLM, L.HAMBURG, new DateTime(1), new DateTime(2));
            CarrierMovement cm3 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));
            CarrierMovement cm4 = new CarrierMovement(L.HAMBURG, L.STOCKHOLM, new DateTime(1), new DateTime(2));

            Assert.True(cm1.sameValueAs(cm2));
            Assert.False(cm2.sameValueAs(cm3));
            Assert.True(cm3.sameValueAs(cm4));

            Assert.True(cm1.Equals(cm2));
            Assert.False(cm2.Equals(cm3));
            Assert.True(cm3.Equals(cm4));

            Assert.True(cm1.GetHashCode() == cm2.GetHashCode());
            Assert.False(cm2.GetHashCode() == cm3.GetHashCode());
            Assert.True(cm3.GetHashCode() == cm4.GetHashCode());
        }
Exemplo n.º 12
0
 public void AddEdge(Node node, CarrierMovement carrierMovement)
 {
     Edges.Add(new Edge(node, carrierMovement));
 }
Exemplo n.º 13
0
 public static TimeSpan TravelTime(this CarrierMovement carrierMovement)
 {
     return(carrierMovement.ArrivalTime - carrierMovement.DepartureTime);
 }
Exemplo n.º 14
0
 private bool IsLastMovementOfLeg(CarrierMovement x)
 {
     return(x.ArrivalTime == UnloadDate && x.TransportLeg.ArrivalLocation == UnloadLocation);
 }
Exemplo n.º 15
0
 public Path AppendAndCreate(double distance, DateTimeOffset currentTime, Node node, CarrierMovement carrierMovement)
 {
     return new Path(
         Distance + distance,
         currentTime,
         Directions.Concat(new[] {node}),
         CarrierMovements.Concat(new [] { carrierMovement}));
 }
Exemplo n.º 16
0
 public Edge(
     Node target,
     CarrierMovement carrierMovement)
 {
     Target = target;
     CarrierMovement = carrierMovement;
 }
Exemplo n.º 17
0
 public void AddEdge(Node node, CarrierMovement carrierMovement)
 {
     Edges.Add(new Edge(node, carrierMovement));
 }
Exemplo n.º 18
0
        private static Path CreatePath(Route route, Path currentPath, CarrierMovement carrierMovement, Node target)
        {
            if (currentPath.CurrentTime.IsAfter(carrierMovement.DepartureTime))
            {
                return null;
            }
            if (carrierMovement.ArrivalTime.IsAfter(route.ArrivalDeadline))
            {
                return null;
            }

            var distance = (carrierMovement.ArrivalTime - currentPath.CurrentTime).TotalHours;

            return currentPath.AppendAndCreate(
                distance,
                carrierMovement.ArrivalTime,
                target,
                carrierMovement);
        }
Exemplo n.º 19
0
 public Path AppendAndCreate(double distance, DateTimeOffset currentTime, Node node, CarrierMovement carrierMovement)
 {
     return(new Path(
                Distance + distance,
                currentTime,
                Directions.Concat(new[] { node }),
                CarrierMovements.Concat(new [] { carrierMovement })));
 }
Exemplo n.º 20
0
            public void Add(CarrierMovement carrierMovement)
            {
                AddNode(carrierMovement.ArrivalLocationId.Value);
                AddNode(carrierMovement.DepartureLocationId.Value);

                Nodes[carrierMovement.DepartureLocationId.Value].AddEdge(Nodes[carrierMovement.ArrivalLocationId.Value], carrierMovement);
            }
Exemplo n.º 21
0
 private bool IsFirstMovementOfLeg(CarrierMovement x)
 {
     return(x.DepartureTime == LoadDate && x.TransportLeg.DepartureLocation == LoadLocation);
 }