public void Test_ConvertFromLiterToGallon() { Assert.Multiple(() => { Assert.That(service.ConvertFromLiterToGallon(1), Is.EqualTo(0.264172047).Within(0.005)); Assert.That(service.ConvertFromLiterToGallon(20), Is.EqualTo(5.28344107).Within(0.005)); Assert.That(service.ConvertFromLiterToGallon(15), Is.EqualTo(3.96258068f).Within(0.005)); Assert.That(service.ConvertFromLiterToGallon(3), Is.EqualTo(0.792516112f).Within(0.005)); Assert.That(service.ConvertFromLiterToGallon(24.42f), Is.EqualTo(6.45108128f).Within(0.005)); }); }
static void showLiterGallonMenu() { ConverterService converter = new ConverterService(); float Gallon; float Liter; int choiceFormat = 0; while (choiceFormat != 5) { Console.WriteLine("\nHuvudmeny/2:Gallons-Liter/"); Console.WriteLine("1: Gallon till liter"); Console.WriteLine("2: Liter till Gallon"); Console.WriteLine("3: Gå tillbaka"); Console.WriteLine("4: Avsluta"); if (int.TryParse(Console.ReadLine(), out choiceFormat)) { if (choiceFormat == 1) { Console.WriteLine("Skriv in dina Gallons"); Gallon = ifLetterInput(); Console.WriteLine("så här många liter blir det {0}", converter.ConvertFromGallonToLiter(Gallon)); } if (choiceFormat == 2) { Console.WriteLine("skriv in dina liter"); Liter = ifLetterInput(); Console.WriteLine("så här många gallons blir det {0}", converter.ConvertFromLiterToGallon(Liter)); } if (choiceFormat == 3) { break; } // Avsluta if (choiceFormat == 4) { Console.WriteLine("Avsluta"); Environment.Exit(0); } } else { Console.WriteLine("Endast siffror godtas, försök igen"); } } }
static void ConvertFromLiterToGallon(ConverterService converter) { Console.WriteLine("You wanna convert from metric liters to imperial gallons huh?"); Console.WriteLine("Okay, hom many liters is it?"); bool LiterCheck = Single.TryParse(Console.ReadLine(), out float Liters); //creates a bool that's true if it's possible to parse it and outputs it to a float if (LiterCheck) //If there is correct data it goes here and if it's incorrect it sends ya back to tha main menu { float Gallons = converter.ConvertFromLiterToGallon(Liters); Console.WriteLine("Okay, it's {0} gallons if it's {1} liters", Gallons, Liters); } else { Console.WriteLine("Bruh, you just entered the wrong data. You're gonna get sent back to the main menu."); } }
static void Main(string[] args) { string str = "Vänligen välj ett alternativ\n" + "1. Beräkna Ampere\n" + "2. Beräkna Resistans\n" + "3. Beräkna Diameter\n" + "4. Beräkna Radie\n" + "5. Beräkna Restid\n" + "6. Beräkna Förflyttning\n" + "7. Beräkna Hastighet\n" + "8. Beräkna Spänning\n" + "9. Konvertera Celcius till Fahrenheit\n" + "10. Konvertera Fahrenheit till Celcius\n" + "11. Konvertera Gallon till Liter\n" + "12. Konvertera Liter till Gallon\n" + "13. Konvertera Timmar till Minuter\n" + "14. Konvertera Minuter till Timmar\n" + "0. Avsluta"; ConverterService converter = new ConverterService(); int val; float result; while (true) { Console.WriteLine(str); while (!Int32.TryParse(Console.ReadLine(), out val)) { Console.WriteLine("Felaktigt val {0}\n" + str, val); } switch (val) { case 1: result = converter.CalculateAmps(ReadUserData("Ange spänningen"), ReadUserData("Ange resistansen")); Console.WriteLine("Strömmen blir {0} A", result); Console.ReadLine(); break; case 2: result = converter.CalculateResistance(ReadUserData("Ange Spänningen"), ReadUserData("Ange ampere")); Console.WriteLine("Resistansen blir {0} Ohm", result); Console.ReadLine(); break; case 3: result = converter.CalculateDiameterFromArea(ReadUserData("Ange area")); Console.WriteLine("Diametern blir {0}", result); Console.ReadLine(); break; case 4: result = converter.CalculateRadiusFromArea(ReadUserData("Ange area")); Console.WriteLine("Radien blir {0}", result); Console.ReadLine(); break; case 5: result = converter.CalculateTravelTime(ReadUserData("Ange avståndet"), ReadUserData("Ange Hastigheten")); Console.WriteLine("Resetiden blir {0}", result); Console.ReadLine(); break; case 6: result = converter.CalculateTraveledDistance(ReadUserData("Ange hastigheten"), ReadUserData("Ange tiden")); Console.WriteLine("Avståndet blir {0}", result); Console.ReadLine(); break; case 7: result = converter.CalculateSpeed(ReadUserData("Ange tiden"), ReadUserData("Ange avståndet")); Console.WriteLine("Hastigheten blir {0}", result); Console.ReadLine(); break; case 8: result = converter.CalculateVoltage(ReadUserData("Ange ampere"), ReadUserData("Ange resistans")); Console.WriteLine("Spänningen blir {0} V", result); Console.ReadLine(); break; case 9: result = converter.ConvertCelciusToFahrenheit(ReadUserData("Ange Celsius")); Console.WriteLine("Angivet värde blir {0} farhenheit", result); Console.ReadLine(); break; case 10: result = converter.ConvertFahrenheitToCelcius(ReadUserData("Ange Fahrenheit")); Console.WriteLine("Angivet värde blir blir {0} celcius", result); Console.ReadLine(); break; case 11: result = converter.ConvertFromGallonToLiter(ReadUserData("Ange mängden gallon du vill konvertera till liter")); Console.WriteLine("Angivna gallon är {0} liter", result); Console.ReadLine(); break; case 12: result = converter.ConvertFromLiterToGallon(ReadUserData("Ange mängden liter du vill konvertera till gallon")); Console.WriteLine("Angivna liter är {0} gallon", result); Console.ReadLine(); break; case 13: result = converter.ConvertFromHoursToMinutes(ReadUserData("Ange antalet timmar du vill konvertera till minuter")); Console.WriteLine("Angivna timmar blir {0} minuter", result); Console.ReadLine(); break; case 14: result = converter.ConvertFromMinutesToHours(ReadUserData("Ange antalet minuter du vill konvertera till timmar")); Console.WriteLine("Angivna minuter blir {0} timmar", result); Console.ReadLine(); break; case 0: return; default: Console.WriteLine("Feaktigt val försök igen!"); Console.ReadLine(); break; } } }