//Parametri prosleđeni u okviru [TestCase] dekoratora prihvataju se u potpisu same metode //U ovom primeru, parametar sa vrednošću 4.5351473922902494d biće smešten u promenljivu expectedValue, dok će parametar sa vrednošću 10 biti smešten u promenljivu input //Suština parametrizovanih testova je korišćenje tih parametara u daljem telu testne metode //S obzirom na to da ova testna metoda void, ovaj tip parametrizovanih testova je bez povratne vrednosti public void Convert_Success_Params(int input, double expectedValue) { MassConverter mass = new MassConverter(); double result = mass.Convert(input); //Umesto prosleđenog broja (kao u prvom testu u okviru ove klase), prosleđuje se promenljiva dobijena kroz potpis metode Assert.AreEqual(expectedValue, result); //Koriščenje klase Assert i neke od njenih metoda jer je reč o parametrizovanim testovima bez povratne vrednosti }
public void Convert_Success() { MassConverter mass = new MassConverter(); //Za testiranje metode Convert iz klase MassConvertor, potreban je objekat te klase s obzirom na to da metoda nije statička double result = mass.Convert(10); //Metodi Convert prosleđuje se proizvoljan broj (u ovom primeru će biti broj 10) Assert.AreEqual(4.5351473922902494d, result); //Klasa Assert omogućava pozivanje velikog broja statičkih metoda koje služe za testiranje. Metoda AreEqual prima dva parametra: očekivanu vrednost i stvarnu vrednost (dobijenu pozivom funkcije Convert). }
[TestCase(0, 0)] // jos jedan test case omogucava nam da pozivamo dva razlicita testa nad istom jednom metodom! public void Convert_TestSuccessParams(int input, double result) { MassConverter mass = new MassConverter(); double value = mass.Convert(input); Assert.AreEqual(result, value); }
// Testovi ce biti metode koje testiraju metode iz samog core projekta // najosnovniji testovi ce biti bez return statmenta tj bice void // naziv testa treba da bude jasan za onoga koji nije pisao program public void Convert_TestSuccess() { MassConverter mass = new MassConverter(); double result = mass.Convert(10); Assert.AreEqual(4.5351473922902494d, result); }
public ActionResult <IEnumerable <string> > Get(double unitVal, string UnitOfMeasureFrom, string UnitOfMeasureTo) { double lbValue; var convertor = new MassConverter(UnitOfMeasureFrom, UnitOfMeasureTo); lbValue = convertor.LeftToRight(unitVal); return(new string[] { unitVal.ToString() + " " + UnitOfMeasureFrom, lbValue.ToString() + " " + UnitOfMeasureTo }); }
public void kg_lb() { converter = new MassConverter("kg", "lbs"); double valL = 1; double valR = 2.20462; Assert.AreEqual(valR, converter.LeftToRight(valL, 5)); Assert.AreEqual(valL, converter.RightToLeft(valR, 5)); }
public void kg_uston() { converter = new MassConverter("us ton", "kg"); double valL = 1; double valR = 907.18582; Assert.AreEqual(valR, converter.LeftToRight(valL, 5)); Assert.AreEqual(valL, converter.RightToLeft(valR, 5)); }
public void kg_oz() { converter = new MassConverter("kg", "ounce"); double valL = 1; double valR = 35.274; Assert.AreEqual(valR, converter.LeftToRight(valL, 3)); Assert.AreEqual(valL, converter.RightToLeft(valR, 3)); }
public void kg_imperialton() { converter = new MassConverter("imperial ton", "kg"); double valL = 1; double valR = 1016.04642; Assert.AreEqual(valR, converter.LeftToRight(valL, 5)); Assert.AreEqual(valL, converter.RightToLeft(valR, 5)); }
public void Convert_ExpectedFormatException() { MassConverter mass = new MassConverter(); //Metoda Throws klase Assert, zahteva da se definiše tip Exceptiona koji se očekuje. U slučaju ovog primera, to je System.Format Exception. //Throws metoda sastoji se iz dva dela: preambule - koja u ovom primeru predstavlja prazne zagrade pre strelice (=>) i u preambuli se mogu pozivati metode ili setovati promenljive koje će kasnije uticati na samo hvatanje Exceptiona //Drugi deo Throws metode (sa desne strane strelice - =>) obuhvata poziv metode koja treba da podigne Exception. U ovom primeru, to je poziv metode Convert i prosleđivanje slova kao inputa metode Assert.Throws <System.FormatException>(() => mass.Convert(double.Parse("s"))); }
public void kg_st() { converter = new MassConverter("kg", "stone"); double valL = 1; double valR = 0.157473; Assert.AreEqual(valR, converter.LeftToRight(valL, 6)); Assert.AreEqual(valL, converter.RightToLeft(valR, 6)); }
public void kg_quintal() { converter = new MassConverter("quintal", "kg"); double valL = 1; double valR = 100; Assert.AreEqual(valR, converter.LeftToRight(valL)); Assert.AreEqual(valL, converter.RightToLeft(valR)); }
public IActionResult MassConvert(string type, decimal numIn) { ViewData["length"] = "Result: "; IMassConversions massConvert = new MassConverter(); var result = massConvert.GetMass(type, numIn); ViewData["result"] = result; return(View()); }
public async Task liveTestMassConverter() { var apiFactory = new ConverterAPIFactory(); var tempConverter = new MassConverter(apiFactory); var converterRequest = new ConverterRequest { fromType = "Kilograms", fromValue = 1, toType = "Pounds" }; var result = await tempConverter.convert(converterRequest).ConfigureAwait(true); Assert.Equal(2.20462, result.resultValue); Assert.NotEqual(2, result.resultValue); }
public void UpdateUnitSystem(UnitSystem unitSystem) { this.unitSystem = unitSystem; this.TextBox.Clear(); if (unitSystem != null) { string temperature = "Temperature: \t\t" + TemperatureConverter.GetUnitAsString(unitSystem.TemperatureUnit); string pressure = "Pressure: \t\t\t" + PressureConverter.GetUnitAsString(unitSystem.PressureUnit); string massFlowRate = "Mass Flow Rate: \t\t" + MassFlowRateConverter.GetUnitAsString(unitSystem.MassFlowRateUnit); string volumeFlowRate = "Volume Flow Rate: \t\t" + VolumeFlowRateConverter.GetUnitAsString(unitSystem.VolumeFlowRateUnit); string moistureContent = "Moisture Content: \t\t" + MoistureContentConverter.GetUnitAsString(unitSystem.MoistureContentUnit); string relativeHumidity = "Fraction: \t\t\t" + FractionConverter.GetUnitAsString(unitSystem.FractionUnit); string enthalpy = "Specific Energy: \t\t" + SpecificEnergyConverter.GetUnitAsString(unitSystem.SpecificEnergyUnit); string specificHeat = "Specific Heat: \t\t" + SpecificHeatConverter.GetUnitAsString(unitSystem.SpecificHeatUnit); string energy = "Energy: \t\t\t" + EnergyConverter.GetUnitAsString(unitSystem.EnergyUnit); string power = "Power: \t\t\t" + PowerConverter.GetUnitAsString(unitSystem.PowerUnit); string density = "Density: \t\t\t" + DensityConverter.GetUnitAsString(unitSystem.DensityUnit); string dynamicViscosity = "Dynamic Viscosity: \t\t" + DynamicViscosityConverter.GetUnitAsString(unitSystem.DynamicViscosityUnit); string kinematicViscosity = "Kinematic Viscosity: \t" + KinematicViscosityConverter.GetUnitAsString(unitSystem.KinematicViscosityUnit); string conductivity = "Thermal Conductivity: \t" + ThermalConductivityConverter.GetUnitAsString(unitSystem.ThermalConductivityUnit); string diffusivity = "Diffusivity: \t\t" + DiffusivityConverter.GetUnitAsString(unitSystem.DiffusivityUnit); string mass = "Mass: \t\t\t" + MassConverter.GetUnitAsString(unitSystem.MassUnit); string length = "Length: \t\t\t" + LengthConverter.GetUnitAsString(unitSystem.LengthUnit); string area = "Area: \t\t\t" + AreaConverter.GetUnitAsString(unitSystem.AreaUnit); string volume = "Volume: \t\t\t" + VolumeConverter.GetUnitAsString(unitSystem.VolumeUnit); string time = "Time: \t\t\t" + TimeConverter.GetUnitAsString(unitSystem.TimeUnit); this.TextBox.AppendText(temperature + "\r\n"); this.TextBox.AppendText(pressure + "\r\n"); this.TextBox.AppendText(massFlowRate + "\r\n"); this.TextBox.AppendText(volumeFlowRate + "\r\n"); this.TextBox.AppendText(moistureContent + "\r\n"); this.TextBox.AppendText(relativeHumidity + "\r\n"); this.TextBox.AppendText(enthalpy + "\r\n"); this.TextBox.AppendText(specificHeat + "\r\n"); this.TextBox.AppendText(energy + "\r\n"); this.TextBox.AppendText(power + "\r\n"); this.TextBox.AppendText(density + "\r\n"); this.TextBox.AppendText(dynamicViscosity + "\r\n"); this.TextBox.AppendText(kinematicViscosity + "\r\n"); this.TextBox.AppendText(conductivity + "\r\n"); this.TextBox.AppendText(diffusivity + "\r\n"); this.TextBox.AppendText(mass + "\r\n"); this.TextBox.AppendText(length + "\r\n"); this.TextBox.AppendText(area + "\r\n"); this.TextBox.AppendText(volume + "\r\n"); this.TextBox.AppendText(time); } }
public void MassConverter_Convert() { decimal result = MassConverter.Convert(MassUnit.Ounce, MassUnit.Pound, 12); Assert.AreEqual(0.75m, result); result = MassConverter.Convert(MassUnit.Pound, MassUnit.Ounce, 0.75m); Assert.AreEqual(12m, result); result = MassConverter.Convert(MassUnit.Kilogram, MassUnit.Pound, 1); Assert.AreEqual(2.2046226218487758072297380135m, result); result = MassConverter.Convert(MassUnit.Ton, MassUnit.Pound, 1); Assert.AreEqual(2_000m, result); }
/// <summary>Convert the numbers to the new unit.</summary> /// <param name="numbers">The numbers used in the convertion.</param> /// <returns>The result of the convertion execution.</returns> /// <exception cref="ArgumentNullException">When numbers is null.</exception> /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception> public double Convert(double[] numbers) { base.Validate(numbers); double fromValue = numbers[0]; switch (current.UnitType) { case UnitType.Length: return(LengthConverter.Convert( (LengthUnit)current.FromUnit, (LengthUnit)current.ToUnit, fromValue)); case UnitType.Mass: return(MassConverter.Convert( (MassUnit)current.FromUnit, (MassUnit)current.ToUnit, fromValue)); case UnitType.Speed: return(SpeedConverter.Convert( (SpeedUnit)current.FromUnit, (SpeedUnit)current.ToUnit, fromValue)); case UnitType.Temperature: return(TemperatureConverter.Convert( (TemperatureUnit)current.FromUnit, (TemperatureUnit)current.ToUnit, fromValue)); case UnitType.Time: return(TimeConverter.Convert( (TimeUnit)current.FromUnit, (TimeUnit)current.ToUnit, fromValue)); case UnitType.Volume: return(VolumeConverter.Convert( (VolumeUnit)current.FromUnit, (VolumeUnit)current.ToUnit, fromValue)); default: throw new ArgumentOutOfRangeException("numbers"); } }
public void Convert() { double result = MassConverter.Convert( MassUnit.Ounce, MassUnit.Pound, 12); Assert.AreEqual(0.75, result); result = MassConverter.Convert( MassUnit.Pound, MassUnit.Ounce, 0.75); Assert.AreEqual(12, result); result = MassConverter.Convert( MassUnit.Kilogram, MassUnit.Pound, 1); Assert.AreEqual(2.2046226218487757d, result); result = MassConverter.Convert( MassUnit.Ton, MassUnit.Pound, 1); Assert.AreEqual(2000d, result); }
/// <summary> /// Calculate the Intensity of Gravity at the Surface of the object /// I = (G*M)/(r^2) /// </summary> /// <param name="massOfObject">The mass of the object</param> /// <param name="radiusOfObject">The radius of the object</param> /// <returns></returns> public static ExponentialNotation IntensityAtSurface(ExponentialNotation massOfObject, ExponentialNotation radiusOfObject) { ExponentialNotation intensity = null; //Calculate the numerator: Graviational Constant * Mass (in kg) ExponentialNotation massOfObjectInKilograms = MassConverter.Convert(massOfObject, SIUnit.Kilograms); intensity = GravitationalConstantOfTheUniverse * massOfObjectInKilograms; //Square the radius ExponentialNotation radiusOfObjectInMeters = DistanceConverter.Convert(radiusOfObject, SIUnit.Meters); radiusOfObjectInMeters = radiusOfObjectInMeters * radiusOfObjectInMeters; //Divide the numerator by the radius squared intensity = intensity / radiusOfObjectInMeters; intensity.MeasurementUnits = SIUnit.MetersCubed_PerSecondsSquared_PerKilograms; //I = (G*M)/(r^2) return(intensity); }
/// <summary>Convert the numbers to the new unit.</summary> /// <param name="numbers">The numbers used in the conversion.</param> /// <returns>The result of the conversion execution.</returns> /// <exception cref="ArgumentNullException">When numbers is null.</exception> /// <exception cref="ArgumentException">When the length of numbers do not equal <see cref="ArgumentCount"/>.</exception> public PreciseNumber Evaluate(PreciseNumber[] operands) { ((IExpression)this).Validate(operands); PreciseNumber fromValue = operands[0]; if (!fromValue.HasValue) { return(fromValue); } return(_current.UnitType switch { UnitType.Length => new PreciseNumber(LengthConverter.Convert((LengthUnit)_current.FromUnit, (LengthUnit)_current.ToUnit, fromValue.Value)), UnitType.Mass => new PreciseNumber(MassConverter.Convert((MassUnit)_current.FromUnit, (MassUnit)_current.ToUnit, fromValue.Value)), UnitType.Speed => new PreciseNumber(SpeedConverter.Convert((SpeedUnit)_current.FromUnit, (SpeedUnit)_current.ToUnit, fromValue.Value)), UnitType.Temperature => new PreciseNumber(TemperatureConverter.Convert((TemperatureUnit)_current.FromUnit, (TemperatureUnit)_current.ToUnit, fromValue.Value)), UnitType.Time => new PreciseNumber(TimeConverter.Convert((TimeUnit)_current.FromUnit, (TimeUnit)_current.ToUnit, fromValue.Value)), UnitType.Volume => new PreciseNumber(VolumeConverter.Convert((VolumeUnit)_current.FromUnit, (VolumeUnit)_current.ToUnit, fromValue.Value)), _ => throw new ArgumentOutOfRangeException(nameof(operands)), });
public static void Main(string[] args) { double kgValue; double lbValue; // Simple programmatic approach to conversion, using string `Synonyms` var kgToLbs = new MassConverter("kg", "lbs"); kgValue = 452; lbValue = kgToLbs.LeftToRight(kgValue); Console.WriteLine("452kg in pounds is " + lbValue); // Converting both ways is easy kgValue = kgToLbs.RightToLeft(lbValue); Console.WriteLine("Converted back: " + kgValue); // Rounding is part of conversion lbValue = kgToLbs.LeftToRight(kgValue, 2); Console.WriteLine("452kg in pounds (to 2 decimal places) is " + lbValue); // You can easily customise converters to support Synonyms used in // business logic, such as those stored on a database kgToLbs.AddSynonym("kg", "MTOW (KG)"); kgValue = 3000; kgToLbs.UnitLeft = "MTOW (KG)"; lbValue = kgToLbs.LeftToRight(kgValue); Console.WriteLine("3000 MTOW (KG) in lbs is " + lbValue); // Add a new unit with a custom conversion factor kgToLbs.AddUnit("Chuck Norris", 9001); kgToLbs.UnitRight = "Chuck Norris"; kgValue = 7; var chucks = kgToLbs.LeftToRight(kgValue); Console.WriteLine("7kg is equal to " + lbValue + " chucks"); Console.Read(); }
public double Convert_Success_ParamsWithReturnStatement(int input) { MassConverter mass = new MassConverter(); return(mass.Convert(input)); //Povratna vrednost koja mora biti identična vrednosti u okviru property-a ExpectedResult da bi test prošao }
[TestCase(0, 0)] // opet za jednu metodu moze isto vise testova public double Convert_TestSuccessParamsWithReturnStatment(int input) { MassConverter mass = new MassConverter(); return(mass.Convert(input)); }
private void Convert(double value) { switch (SelectedOp) { case "Length": { LengthunitConverter unit = new LengthunitConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Mass and Weight": { MassConverter unit = new MassConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Power": { PowerConverter unit = new PowerConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Pressure": { PressureConverter unit = new PressureConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Energy": { EnergyConveter unit = new EnergyConveter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Temperature": { TemperatureConverter unit = new TemperatureConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Volume": { VolumeConverter unit = new VolumeConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Angle": { AngleConverter unit = new AngleConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Area": { AreaConverter unit = new AreaConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Speed": { SpeedConverter unit = new SpeedConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } case "Time": { TimeunitsConverter unit = new TimeunitsConverter(); Result = unit.Convert(value, SelectedFrom, SelectedTo).ToString(); break; } } }
public void Cleanup() { converter = null; }
public void Convert_CatchException() { MassConverter mass = new MassConverter(); Assert.Throws <System.FormatException>(() => mass.Convert(double.Parse(""))); // prvi deo metode preambula deo uslov koji sprecava omogucavnanje metode } // primer passovanja nule ili range izvan double tipa