Helper methods for temperature conversion
Exemplo n.º 1
0
 public NowWeather(double temp, string con, PcpnTotal pcpn, WindTotal wind)
 {
     Now = new NowCondition(con);
     BodyTemprature = null;
     Precipitation = (float)pcpn.local.intensity;
     Wind = new Wind(wind);
     Pressure = null;
     Temprature = Temperature.FromCelsius((float)temp);
 }
Exemplo n.º 2
0
 public static Tennis Make(Outlook outlook, Temperature temperature, Humidity humidity, bool windy, bool play)
 {
     return new Tennis
     {
         Outlook = outlook,
         Temperature = temperature,
         Humidity = humidity,
         Windy = windy,
         Play = play
     };
 }
Exemplo n.º 3
0
        public static double CalculateAverageTemperatureBasedOnMaxValues(Temperature[] temp)
        {
            double average = 0;

            for (int i =0; i< temp.Length; i++)
            {
                average += temp[i].tempMax;
            }

            average = (double) Math.Round((average / temp.Length),2);

            return average;
        }
Exemplo n.º 4
0
 static void Main(string[] args)
 {
     Temperature temp = new Temperature();
     try
     {
         temp.showTemp();
     }
     catch (TempIsZeroException e)
     {
         Console.WriteLine("TempIsZeroException: {0}", e.Message);
     }
     Console.ReadKey();
 }
Exemplo n.º 5
0
        public static Temperature[] AddNewEntry(Temperature[] temp, int newDay, int max, int min)
        {
            Temperature[] newTemp = new Temperature[temp.Length];

            for (int i = 0; i < temp.Length; i++)
            {
                newTemp[i] = temp[i];
            }

            Array.Resize(ref newTemp, newTemp.Length + 1);
            newTemp[newTemp.Length-1] = new Temperature { day = newDay,tempMax = max, tempMin = min };

            return newTemp;
        }
        public void CanConvertTemperature_ToString()
        {
            // arrange
            Mock<IWeatherDao> mock = new Mock<IWeatherDao>();
            WeatherService service = new WeatherService(mock.Object);
            Temperature temp = new Temperature()
                                   {
                                       temp = 75,
                                       scale = "F"
                                   };
            mock.Setup(x => x.ConvertToString(It.IsAny<Temperature>())).Returns("75 F");

            // act
            string result = service.convert(temp);

            // assert
            Assert.AreEqual("75 F", result);
        }
 public Activity(string name, DateTime openingHour, DateTime closingHour, DaysOpen daysOpen,
                 int minParticipants, int maxParticipants, Price studentPrice, Price adultPrice,
                 string address, EnergyNeeded energyNeeded, string materialNeeded, Transport transport,
                 Duration duration, Temperature temperature, Category category)
 {
     Name = name;
     OpeningHour = openingHour;
     ClosingHour = closingHour;
     DaysOpen = daysOpen;
     MinimumParticipants = minParticipants;
     MaximumParticipants = maxParticipants;
     StudentPrice = studentPrice;
     AdultPrice = adultPrice;
     Address = address;
     EnergyNeeded = energyNeeded;
     MaterialNeeded = materialNeeded;
     Transport = transport;
     Duration = duration;
     Temperature = temperature;
     Category = category;
 }
Exemplo n.º 8
0
        public static Temperature[] ReturnDaysWithMinTemp(Temperature[] temp)
        {
            Temperature[] daysWithMinTemp = new Temperature[0];
            int minTemp = ReturnMinValue(temp);

            int daysWithMinValue = 0;
            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i].tempMin == minTemp)
                {
                    daysWithMinValue++;
                    Array.Resize(ref daysWithMinTemp, daysWithMinValue);

                    daysWithMinTemp[daysWithMinValue - 1] =

                        new Temperature { day = temp[i].day, tempMax = temp[i].tempMax, tempMin = temp[i].tempMin };
                }
            }

            return daysWithMinTemp;
        }
Exemplo n.º 9
0
        public static Temperature[] ReturnDaysWithMaxDiffBetweenMinValAndMaxVal(Temperature[] temp)
        {
            Temperature[] days = new Temperature[0];
            int diff = ReturnMaxDiff(temp);

            int daysWithMaxDiff = 0;
            for (int i = 0; i < temp.Length; i++)
            {
                if ((temp[i].tempMax - temp[i].tempMin) == diff)
                {
                    daysWithMaxDiff++;
                    Array.Resize(ref days, daysWithMaxDiff);

                    days[daysWithMaxDiff - 1] =

                        new Temperature { day = temp[i].day, tempMax = temp[i].tempMax, tempMin = temp[i].tempMin };
                }
            }

            return days;
        }
Exemplo n.º 10
0
 public NowWeather(JsonContract.NowWeatherContract now)
 {
     if (now == null)
     {
         return;
     }
     CultureInfo provider = CultureInfo.InvariantCulture;
     Now = new NowCondition(now.cond);
     int fl;
     if (int.TryParse(now.fl, NumberStyles.Any, provider, out fl))
         BodyTemprature = Temperature.FromCelsius(fl);
     float pcpn;
     if (float.TryParse(now.pcpn, NumberStyles.Any, provider, out pcpn))
         Precipitation = pcpn;
     if (float.TryParse(now.vis, NumberStyles.Any, provider, out pcpn))
         Visibility = Length.FromKM(pcpn);
     Wind = new Wind(now.wind);
     if (float.TryParse(now.pres, NumberStyles.Any, provider, out pcpn))
         Pressure = Pressure.FromHPa(pcpn);
     if (int.TryParse(now.tmp, NumberStyles.Any, provider, out fl))
         Temprature = Temperature.FromCelsius(fl);
 }
Exemplo n.º 11
0
 public void FromRankineTest()
 {
     double value = 10F;
     Temperature expected = new Temperature(5.55555555555556);
     Temperature actual;
     actual = Temperature.FromRankine(value);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 12
0
 public void op_SubtractionTest()
 {
     Temperature value1 = new Temperature(10F);
     Temperature value2 = new Temperature(10F);
     Temperature expected = new Temperature(0F);
     Temperature actual;
     actual = (value1 - value2);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 13
0
 public void GetHashCodeTest()
 {
     Temperature target = new Temperature(10F);
     int expected = 1076101120;
     int actual;
     actual = target.GetHashCode();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 14
0
 public void ParseStringTest()
 {
     double value = 10F;
     string s = value.ToString();
     Temperature expected = new Temperature(value);
     Temperature actual;
     actual = Temperature.Parse(s);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 15
0
 public void ToBooleanTest()
 {
     IConvertible target = new Temperature(10F);
     IFormatProvider provider = null;
     bool expected = true;
     bool actual;
     actual = target.ToBoolean(provider);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 16
0
 public void ToDecimalTest()
 {
     IConvertible target = new Temperature(10F);
     IFormatProvider provider = null;
     Decimal expected = new Decimal(10F);
     Decimal actual;
     actual = target.ToDecimal(provider);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 17
0
        public void ToByteTest()
        {
            IConvertible target = new Temperature(10F);
            IFormatProvider provider = null;
            byte expected = 10;
            byte actual;
            actual = target.ToByte(provider);
            Assert.AreEqual(expected, actual);

        }
Exemplo n.º 18
0
 public void ToFahrenheitTest()
 {
     double value = 10F;
     Temperature target = new Temperature(value);
     double expected = -441.67;
     double actual;
     actual = target.ToFahrenheit();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 19
0
 public void ParseProviderTest()
 {
     double value = 10F;
     string s = value.ToString();
     IFormatProvider provider = null;
     Temperature expected = new Temperature(value);
     Temperature actual;
     actual = Temperature.Parse(s, provider);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 20
0
 public void ToDelisleTest()
 {
     Temperature target = new Temperature(10F);
     double expected = 544.725;
     double actual;
     actual = target.ToDelisle();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 21
0
 public void GetTypeCodeTest()
 {
     Temperature target = new Temperature();
     TypeCode expected = new TypeCode();
     expected = Type.GetTypeCode(typeof(Double));
     TypeCode actual;
     actual = target.GetTypeCode();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 22
0
 public void ToCelsiusTest()
 {
     Temperature target = new Temperature(10F);
     double expected = -263.15;
     double actual;
     actual = target.ToCelsius();
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 23
0
 public void FromRømerTest()
 {
     double value = 10F;
     Temperature expected = new Temperature(277.911904761905);
     Temperature actual;
     actual = Temperature.FromRømer(value);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 24
0
 public void ToUInt64Test()
 {
     IConvertible target = new Temperature(10F);
     IFormatProvider provider = null;
     ulong expected = 10;
     ulong actual;
     actual = target.ToUInt64(provider);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 25
0
 public void FromRéaumurTest()
 {
     double value = 10F;
     Temperature expected = new Temperature(285.65);
     Temperature actual;
     actual = Temperature.FromRéaumur(value);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 26
0
 public void ToTypeTest()
 {
     IConvertible target = new Temperature(10F);
     Type conversionType = typeof(Double);
     IFormatProvider provider = null;
     object expected = new Temperature(10F);
     object actual;
     actual = target.ToType(conversionType, provider);
     Assert.AreEqual(expected, actual);
 }
Exemplo n.º 27
0
 public Weather(WeatherCondition weatherCondition, Temperature temperature)
 {
     WeatherCondition = weatherCondition;
     Temperature = temperature;
 }
Exemplo n.º 28
0
        public void ToSingleTest()
        {
            IConvertible target = new Temperature(10F);
            IFormatProvider provider = null;
            float expected = 10F;
            float actual;
            actual = target.ToSingle(provider);
            Assert.AreEqual(expected, actual);

        }
		public virtual void EmbeddingOfInstanceOfCustomValueTypeWithPropertiesIsCorrect()
		{
			// Arrange
			var temperature = new Temperature(-17.3, TemperatureUnits.Celsius);

			const string input1 = "temperature.Celsius";
			const double targetOutput1 = -17.3;

			const string input2 = "temperature.Kelvin";
			const double targetOutput2 = 255.85;

			const string input3 = "temperature.Fahrenheit";
			const double targetOutput3 = 0.86;

			// Act
			double output1;
			double output2;
			double output3;

			using (var jsEngine = CreateJsEngine())
			{
				jsEngine.EmbedHostObject("temperature", temperature);

				output1 = Math.Round(jsEngine.Evaluate<double>(input1), 2);
				output2 = Math.Round(jsEngine.Evaluate<double>(input2), 2);
				output3 = Math.Round(jsEngine.Evaluate<double>(input3), 2);
			}

			// Assert
			Assert.AreEqual(targetOutput1, output1);
			Assert.AreEqual(targetOutput2, output2);
			Assert.AreEqual(targetOutput3, output3);
		}
Exemplo n.º 30
0
 public void ToInt16Test()
 {
     IConvertible target = new Temperature(10F);
     IFormatProvider provider = null;
     short expected = 10;
     short actual;
     actual = target.ToInt16(provider);
     Assert.AreEqual(expected, actual);
 }