public async Task <DateTime> GetTimeOfArival(DateTime departureTime, Kilometer distanceToCover) { var request = _estimatedTimeOfArrivalRequestMapper.Map(departureTime, distanceToCover); var response = await _httpClient.PostAsync(etaEndpointAddress, request); return(_estimatedTimeOfArrivalResponseMapper.Map(response)); }
static float calculateFastestKilometreSpeed(List <int> metreSplits) { var km = new Kilometer(); foreach (var split in metreSplits) { km.Distance += split; km.IncrementTime(); if (km.Distance >= 1000) { kilometerSplits.Add(km); km = new Kilometer(); } } var fastest = float.MinValue; foreach (var kilometer in kilometerSplits) { if (kilometer.Speed > fastest) { fastest = kilometer.Speed; } } return(fastest); }
public void TestKnots() { // initialize value. Knots ten = 10; // convert from. KilometerPerHour tenInKilometerPerHour = 18.52; MeterPerSecond tenInMeterPerSecond = 5.14444444444; MilesPerHour tenInMilesPerHour = 11.50779; // test converts to. Assert.AreEqual(ten.Value, ((Knots)tenInKilometerPerHour).Value, 0.000001); Assert.AreEqual(ten.Value, ((Knots)tenInMeterPerSecond).Value, 0.000001); Assert.AreEqual(ten.Value, ((Knots)tenInMilesPerHour).Value, 0.000001); // tests division of distance with time resulting in speed. Kilometer distance = ten * (Hour)2; Assert.AreEqual(18.52 * 2.0, distance.Value); // tests some parsing functions. Knots tenPointFive = 10.5; Knots tenPointFiveParsed; Assert.IsTrue(Knots.TryParse(tenPointFive.ToString(), out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(Knots.TryParse("10.5", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(Knots.TryParse("10.5 knots", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsFalse(Knots.TryParse("10.5 m/s", out tenPointFiveParsed)); Assert.IsFalse(Knots.TryParse("10.5 mph", out tenPointFiveParsed)); Assert.IsFalse(Knots.TryParse("10.5 k/h", out tenPointFiveParsed)); }
public void Initialize() { _sut = new EstimatedTimeOfArrivalRequestMapper(); _timeOfDeparture = _fixture.Create <DateTime>(); _distance = _fixture.Create <Kilometer>(); }
//Returns reference to unit t be created private Unit createUnit(string originalUnit) { Unit unit; switch (originalUnit) { case "cm": unit = new Centimeter(); break; case "ft": unit = new Foot(); break; case "in": unit = new Inch(); break; case "km": unit = new Kilometer(); break; case "m": unit = new Meter(); break; case "mile": unit = new Mile(); break; default: throw new InvalidEnumArgumentException(); } return(unit); }
public void WhenKilometersNone_ShouldEqualZeroKilomters() { // Act var actual = Kilometer.None; // Assert actual.Should().Be(Kilometer.FromDecimal(0)); }
public void Initialize() { _distance1InDecimals = _fixture.Create <decimal>() * _fixture.Create <decimal>(); _distance1 = Kilometer.FromDecimal(_distance1InDecimals); _distance2InDecimals = _fixture.Create <decimal>(); _distance2 = Kilometer.FromDecimal(_distance2InDecimals); }
private void setclear() { NameVehicle.Clear(); BranchVehicle.Clear(); typeVehicledetail.ResetText(); registration.Clear(); costperdatetext.Clear(); descriptiontext.Clear(); Kilometer.Clear(); }
public void WhenSubtracting_ResultShouldBeDistanceMinusOtherDistance() { // Act var actual = _distance1 - _distance2; // Assert var expected = Kilometer.FromDecimal(_distance1InDecimals - _distance2InDecimals); actual.Should().Be(expected); }
public void WhenAdding_ResultShouldBeSumOfDistances() { // Act var actual = _distance1 + _distance2; // Assert var expected = Kilometer.FromDecimal(_distance1InDecimals + _distance2InDecimals); actual.Should().Be(expected); }
public void WhenSameInstance_ShouldBeEqual() { // Arrange var instance = Kilometer.FromDecimal(_distance); // Act var actual = instance.Equals(instance); // Assert actual.Should().BeTrue(); }
public void WhenDistanceProvided_ShouldDisplayDistanceAsKilometers() { // Arrange var distance = _fixture.Create <decimal>(); // Act var actual = Kilometer.FromDecimal(distance); // Assert actual.ToString().Should().Be($"{distance} km"); }
public void WhenDistanceProvided_ShouldSetDistance() { // Arrange var distance = _fixture.Create <decimal>(); // Act var actual = Kilometer.FromDecimal(distance); // Assert actual.ToDecimal().Should().Be(distance); }
public void WhenNegativeDistance_ShouldThrowArgumentException() { // Arrange var negativeDistance = -1 * _fixture.Create <decimal>(); // Act Action act = () => Kilometer.FromDecimal(negativeDistance); // Asset act.Should().Throw <ArgumentException>("Distance must be bigger than 0 km."); }
public void WhenDifferentDistance_ShouldNotBeEqual() { // Arrange var instance1 = Kilometer.FromDecimal(_distance); var instance2 = Kilometer.FromDecimal(_fixture.Create <decimal>()); // Act var actual = instance1.Equals(instance2); // Assert actual.Should().BeFalse(); }
public void WhenSameDistance_ComparisonShouldBeTrue() { // Arrange var instance1 = Kilometer.FromDecimal(_distance); var instance2 = Kilometer.FromDecimal(_distance); // Act var actual = instance1 == instance2; // Assert actual.Should().BeTrue(); }
public void WhenCastedToObjectAndSameDistance_ShouldBeEqual() { // Arrange var instance1 = Kilometer.FromDecimal(_distance); var instance2 = Kilometer.FromDecimal(_distance); // Act var actual = instance1.Equals((object)instance2); // Assert actual.Should().BeTrue(); }
public void WhenDifferentDistances_ComparisonShouldBeTrue() { // Arrange var instance1 = Kilometer.FromDecimal(_distance); var instance2 = Kilometer.FromDecimal(_fixture.Create <decimal>()); // Act var actual = instance1 != instance2; // Assert actual.Should().BeTrue(); }
public HttpContent Map(DateTime departureTime, Kilometer distance) { var request = new EstimatedTimeOfArrivalRequest { TimeOfDeparture = departureTime, Kilometers = (int)distance.ToDecimal() }; var jsonString = JsonConvert.SerializeObject(request); return(new StringContent(jsonString, Encoding.UTF8, "application/json")); }
public void WhenSameInstance_ComparisonShouldBeTrue() { // Arrange var instance = Kilometer.FromDecimal(_distance); // Act #pragma warning disable CS1718 // Comparison made to same variable var actual = instance == instance; #pragma warning disable CS1718 // Comparison made to same variable // Assert actual.Should().BeTrue(); }
public void WhenDifferentObjects_ShouldHaveDifferentHashcodes() { // Arrange var distance = Kilometer.FromDecimal(_fixture.Create <decimal>()); var otherDistance = Kilometer.FromDecimal(_fixture.Create <decimal>()); // Act var actual1 = distance.GetHashCode(); var actual2 = otherDistance.GetHashCode(); // Asset actual1.Should().NotBe(actual2); }
public void Initialize() { _httpClient = Substitute.For <IHttpClient>(); _estimatedTimeOfArrivalRequestMapper = Substitute.For <IEstimatedTimeOfArrivalRequestMapper>(); _estimatedTimeOfArrivalResponseMapper = Substitute.For <IEstimatedTimeOfArrivalResponseMapper>(); _getDistanceRequestMapper = Substitute.For <IGetDistanceRequestMapper>(); _getDistanceResponseMapper = Substitute.For <IGetDistanceResponseMapper>(); _departureTime = _fixture.Create <DateTime>(); _distanceToCover = _fixture.Create <Kilometer>(); _sut = new AaaServiceProxy(_httpClient, _estimatedTimeOfArrivalRequestMapper, _estimatedTimeOfArrivalResponseMapper, _getDistanceRequestMapper, _getDistanceResponseMapper); }
public void WhenAaaPopulatesEtaField_ShouldDeserializeTheirJsonToKilometers() { // Arrange var httpResponseMessage = _theirResponse.ToHttpResponseMessage(); // Act var actual = _mapper.Map(httpResponseMessage); // Assert var expected = Kilometer.FromDecimal(_theirResponse.Kilometers); actual.Should().Be(expected); }
public void TestKilometerPerHour() { // initialize value. KilometerPerHour ten = 10; // convert from. Knots tenInKnots = 5.39956803; MeterPerSecond tenInMeterPerSecond = 2.77777777778; MilesPerHour tenInMilesPerHour = 6.21371192; // test converts to. Assert.AreEqual(ten.Value, ((KilometerPerHour)tenInKnots).Value, 0.000001); Assert.AreEqual(ten.Value, ((KilometerPerHour)tenInMeterPerSecond).Value, 0.000001); Assert.AreEqual(ten.Value, ((KilometerPerHour)tenInMilesPerHour).Value, 0.000001); // tests division of distance with time resulting in speed. Kilometer twenty = ten * (Hour)2; Assert.AreEqual(20, twenty.Value); // tests some parsing functions. KilometerPerHour tenPointFive = 10.5; KilometerPerHour tenPointFiveParsed; Assert.IsTrue(KilometerPerHour.TryParse(tenPointFive.ToString(), out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5 km/h", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5 kmh", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5 kph", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5 kmph", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5km/h", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5kmh", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5kph", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(KilometerPerHour.TryParse("10.5kmph", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsFalse(KilometerPerHour.TryParse("10.5 m/s", out tenPointFiveParsed)); Assert.IsFalse(KilometerPerHour.TryParse("10.5 mph", out tenPointFiveParsed)); Assert.IsFalse(KilometerPerHour.TryParse("10.5 knots", out tenPointFiveParsed)); }
public Kilometer Map(HttpResponseMessage responseMessage) { if (responseMessage.StatusCode != System.Net.HttpStatusCode.OK) { throw new ApplicationException($"Failed to get data from AAA service: {responseMessage.ReasonPhrase}"); } var response = responseMessage.Content.ReadAsStringAsync() .GetAwaiter() .GetResult(); var distanceResponse = JsonConvert.DeserializeObject <GetDistanceResponse>(response); return(Kilometer.FromDecimal(distanceResponse.Kilometers)); }
public void MultiplyDivide() { MPH speed = (MPH)100.0; // 100 mph Minute duration = (Minute)30.0; // 30 minutes Mile miles = speed * (Hour)duration; Assert.AreEqual((Mile)50.0, miles); Assert.AreEqual("50 mil", miles.ToString(CultureInfo.InvariantCulture)); Kilometer kilometers = (Kilometer)miles; Assert.AreEqual((Kilometer)80.467199999999991, kilometers); Assert.AreEqual("80.4672 km", kilometers.ToString(CultureInfo.InvariantCulture)); speed = miles / (Hour)duration; Assert.AreEqual((MPH)100.0, speed); Assert.AreEqual("100 mph", speed.ToString(CultureInfo.InvariantCulture)); Assert.AreEqual("160.9344 km/h", ((Kilometer_Hour)speed).ToString(CultureInfo.InvariantCulture)); Assert.AreEqual("44.704 m/s", ((Meter_Sec)speed).ToString(CultureInfo.InvariantCulture)); }
public void TestMeterPerSecond() { // initialize value. MeterPerSecond ten = 10; // convert from. Knots tenInKnots = 19.43844492440605; KilometerPerHour tenInKilometerPerHour = 36; MilesPerHour tenInMilesPerHour = 22.36936292054402; // test converts to. Assert.AreEqual(ten.Value, ((MeterPerSecond)tenInKnots).Value, 0.000001); Assert.AreEqual(ten.Value, ((MeterPerSecond)tenInKilometerPerHour).Value, 0.000001); Assert.AreEqual(ten.Value, ((MeterPerSecond)tenInMilesPerHour).Value, 0.000001); // tests division of distance with time resulting in speed. Kilometer twenty = ten * (Hour)2; Assert.AreEqual(tenInKilometerPerHour.Value * 2.0, twenty.Value); // tests some parsing functions. MeterPerSecond tenPointFive = 10.5; MeterPerSecond tenPointFiveParsed; Assert.IsTrue(MeterPerSecond.TryParse(tenPointFive.ToString(), out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(MeterPerSecond.TryParse("10.5", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(MeterPerSecond.TryParse("10.5 m/s", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsTrue(MeterPerSecond.TryParse("10.5m/s", out tenPointFiveParsed)); Assert.AreEqual(tenPointFive.Value, tenPointFiveParsed.Value); Assert.IsFalse(MeterPerSecond.TryParse("10.5 km/h", out tenPointFiveParsed)); Assert.IsFalse(MeterPerSecond.TryParse("10.5 mph", out tenPointFiveParsed)); Assert.IsFalse(MeterPerSecond.TryParse("10.5 knots", out tenPointFiveParsed)); }
public OdometerMessage(byte[] payload) { payload.RequireBytes(RequireBytes); Odometer = new Kilometer(BitConverter.ToUInt32(payload) / 1000m); }
public void TestKm(double expected, double given, string text) { Kilometer kilometer = new Kilometer(); Assert.AreEqual(expected, kilometer.Calculate(given, text)); }