public void TestSuccessfulConversion(ConversionResult expected) { var conversion = new TemperatureConversion(); var convertResult = conversion.DoConversion("kelvin", "celsius", 100); expected.Should().BeEquivalentTo(expected); }
public void GivenTemperatureinFaherenheit_shouldConvertintoCelsius() { TemperatureConversion temperatureConversion = new TemperatureConversion(); double output = temperatureConversion.tempConversion(212, Temparature.Faherenheit, Temparature.celsius); Assert.AreEqual(100, output, 0.01); }
public void TestIncompatibleConversion(string from, string to, decimal value) { var conversion = new TemperatureConversion(); Assert.Throws <IncompatibleConversionException>(() => { conversion.DoConversion(from, to, value); }); }
public void FarenheitToCelcius_PerformsCorrectConversion() { const double tempFarenheit = 98.6; var tempCelcius = TemperatureConversion.FarenheitToCelcius(tempFarenheit); const double tolerance = 0.001; const double expected = 37.0; Assert.InRange(tempCelcius, expected - tolerance, expected + tolerance); }
public void CelciusToFarenheight_PerformsCorrectConversion() { const double tempCelcius = 37.0; var tempFarenheit = TemperatureConversion.CelciusToFarenheight(tempCelcius); const double expected = 98.6; const double tolerance = 0.001; Assert.InRange(tempFarenheit, expected - tolerance, expected + tolerance); }
private void convertTemperature(TemperatureConversion conversion) { double inputTemperature; double outputTemperature; string temperatureUnit; string plural; // Convert the input to a double. if (double.TryParse(textBoxInputTemperature.Text, out inputTemperature)) { labelResult.ForeColor = Color.Black; if (conversion == TemperatureConversion.CelsiusToFahrenheit) { outputTemperature = inputTemperature * 1.8 + 32.0; temperatureUnit = "Fahrenheit"; } else { outputTemperature = (inputTemperature - 32.0) / 1.8; temperatureUnit = "Celsius"; } plural = Math.Abs(outputTemperature - 1.0) < 0.05 ? "" : "s"; labelResult.Text = string.Format("{0:0.#} degree{1} {2}", outputTemperature, plural, temperatureUnit); } else { displayError("Invalid temperature"); } // Send focus to the TextBox textBoxInputTemperature.Select(); // Must always call Select() before calling SelectAll() // even if TextBox already has focus // Select all text in the TextBox. textBoxInputTemperature.SelectAll(); }
public static void Main(string[] args) { Console.WriteLine(" 1. Replace String \n 2. FlipCoin \n 3. LeapYear \n 4. PowerOf2 \n 5. HarmonicNo." + " \n 6. PrimeFactor \n 7. WindChill Temperature \n 8. Euclidean distance \n 9. QuadraticEquation " + "\n 10. FindTriplets \n 11. Gambler \n 12. 2DArray \n 13. CouponNumber \n 14. StopWatch \n 15. TicTaeToe" + "\n 16. Vending Machine \n 17. Day of week \n 18. TemperatureConversion \n 19. MonthlyPayment \n 20. SquareRoot" + "\n 21. BinaryConversion \n 22. SwapNibbles \n 23. ResultantNo is Power of two \n 24. BinarySearch \n 25. BubbleSort" + "\n 26. Insertion Sort \n 27. Merge Sort \n 28. Anagram \n 29. Prime btw 1-1000 \n 30. Permutation Recursive \n 31. Permutation Iterartion "); int option = Utility.readInt(); switch (option) { case 1: ReplaceString.Replace(); break; case 2: FlipCoin.flipCoin(); break; case 3: LeapYear.LeapYears(); break; case 4: PowerOf2.PrintTable(); break; case 5: Harmonic.HarmonicNo(); break; case 6: PrimeFactor.Primefactor(); break; case 7: WindChill.Chill(); break; case 8: Distance.EuclideanDistance(); break; case 9: QuadraticEquation.Quadratic(); break; case 10: Sumof3No.SumZero(); break; case 11: Gambler.Gambling(); break; case 12: Array2D.IntegerArray(); break; case 13: CouponNumber.couponNumber(); break; case 14: StopWatch.Watch(); break; case 15: TicTacToe.TictaeToeGame(); break; case 16: VendingMachine.Atm(); break; case 17: DayOfWeek.checkday(); break; case 18: TemperatureConversion.Conversion(); break; case 19: MonthlyPayment.PaymentMonthly(); break; case 20: Sqrt.Root(); break; case 21: Binary.DecToBinary(); break; case 22: BinarySwaapNibble.SwapNibble(); break; case 23: ResultantPower2.Resultant(); break; case 24: BinarySearch.Search(); break; case 25: BubbleSort.Bubblesort(); break; case 26: Insertion.InsertionSorting(); break; case 27: MergeSort.Mergesorting(); break; case 28: Anagram.AnagramString(); break; case 29: PrimeNoRange.Range(); break; case 30: Permutation.Recursion(); break; case 31: permutationIterative.Iterative(); break; case 32: PlaindromePrimeNo.AnagramPrime(); //PlaindromePrimeNo.Palindrome(); break; } }
/// <summary> /// Queries the configured services /// </summary> /// <param name="selectedTemperatureUnitId">Id of the selected temperature UOM</param> /// <param name="selectedWindSpeedUnitId">Id of the selected temperature UOM</param> /// <param name="location">The location being searched</param> /// <param name="queryServiceDelegate">Callback for querying a service</param> public async Task <QueryResults> QueryServices(int selectedTemperatureUnitId, int selectedWindSpeedUnitId, string location, QueryServiceDelegate queryServiceDelegate = null) { if (queryServiceDelegate == null) { queryServiceDelegate = new QueryServiceDelegate(QueryService); } QueryResults returnValue = new QueryResults() { ServicesOffline = 0, TotalServices = 0, TemperatureResult = 0, TemperatureUOM = WeatherTestDb.TemperatureUom.FirstOrDefault(i => i.Id == selectedTemperatureUnitId).Title, WindSpeedResult = 0, WindSpeedUOM = WeatherTestDb.WindSpeedUom.FirstOrDefault(i => i.Id == selectedWindSpeedUnitId).Title }; IEnumerable <WeatherService> services = WeatherTestDb.WeatherService; returnValue.TotalServices = services.Count(); List <decimal> temperatures = new List <decimal>(); List <decimal> windSpeeds = new List <decimal>(); foreach (WeatherService service in services) { try { ServiceResult serviceResult = await queryServiceDelegate(service, location); if (selectedTemperatureUnitId != service.TemperatureUomid) { TemperatureConversion conversion = WeatherTestDb.TemperatureConversion.First(i => i.FromTemperatureUomid == service.TemperatureUomid && i.ToTemperatureUomid == selectedTemperatureUnitId); string calculation = string.Format(conversion.Formula.Replace("{value}", "{0}"), serviceResult.TemperatureResult); serviceResult.TemperatureResult = EvaluateExpression(calculation); } temperatures.Add(serviceResult.TemperatureResult); if (selectedWindSpeedUnitId != service.WindSpeedUomid) { WindSpeedConversion conversion = WeatherTestDb.WindSpeedConversion.First(i => i.FromWindSpeedUomid == service.WindSpeedUomid && i.ToWindSpeedUomid == selectedWindSpeedUnitId); string calculation = string.Format(conversion.Formula.Replace("{value}", "{0}"), serviceResult.WindSpeedResult); serviceResult.WindSpeedResult = EvaluateExpression(calculation); } windSpeeds.Add(serviceResult.WindSpeedResult); } catch (HttpRequestException) { returnValue.ServicesOffline++; } } if (temperatures.Count > 0) { returnValue.TemperatureResult = temperatures.Average(); } if (windSpeeds.Count > 0) { returnValue.WindSpeedResult = windSpeeds.Average(); } return(returnValue); }
public void TemperatureConversionPositiveFahrenheit() { var x = TemperatureConversion.Get(10, Unit.Fahrenheit); Assert.IsTrue(x == 50); }
public void TemperatureConversionNegativeCelsius() { var x = TemperatureConversion.Get(-10, Unit.Celsius); Assert.IsTrue(x <-23.333 && x> -23.334); }
public void TemperatureConversionPositiveCelsius() { var x = TemperatureConversion.Get(10, Unit.Celsius); Assert.IsTrue(x <-12.222 && x> -12.223); }
public void TemperatureConversionNegativeFahrenheit() { var x = TemperatureConversion.Get(-10, Unit.Fahrenheit); Assert.IsTrue(x == 14); }