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(); }
public void Add(CarrierMovement carrierMovement) { AddNode(carrierMovement.ArrivalLocationId.Value); AddNode(carrierMovement.DepartureLocationId.Value); Nodes[carrierMovement.DepartureLocationId.Value].AddEdge(Nodes[carrierMovement.ArrivalLocationId.Value], carrierMovement); }
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(); }
public Edge( Node target, CarrierMovement carrierMovement) { Target = target; CarrierMovement = carrierMovement; }
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(); }
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)); }
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()); }
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()); }
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()); }
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()); }
public void AddEdge(Node node, CarrierMovement carrierMovement) { Edges.Add(new Edge(node, carrierMovement)); }
public static TimeSpan TravelTime(this CarrierMovement carrierMovement) { return(carrierMovement.ArrivalTime - carrierMovement.DepartureTime); }
private bool IsLastMovementOfLeg(CarrierMovement x) { return(x.ArrivalTime == UnloadDate && x.TransportLeg.ArrivalLocation == UnloadLocation); }
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})); }
public Edge( Node target, CarrierMovement carrierMovement) { Target = target; CarrierMovement = carrierMovement; }
public void AddEdge(Node node, CarrierMovement carrierMovement) { Edges.Add(new Edge(node, carrierMovement)); }
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 Path AppendAndCreate(double distance, DateTimeOffset currentTime, Node node, CarrierMovement carrierMovement) { return(new Path( Distance + distance, currentTime, Directions.Concat(new[] { node }), CarrierMovements.Concat(new [] { carrierMovement }))); }
public void Add(CarrierMovement carrierMovement) { AddNode(carrierMovement.ArrivalLocationId.Value); AddNode(carrierMovement.DepartureLocationId.Value); Nodes[carrierMovement.DepartureLocationId.Value].AddEdge(Nodes[carrierMovement.ArrivalLocationId.Value], carrierMovement); }
private bool IsFirstMovementOfLeg(CarrierMovement x) { return(x.DepartureTime == LoadDate && x.TransportLeg.DepartureLocation == LoadLocation); }