public void ParseInCard_FieldIsNull()
 {
     string data = "r:533|t:15.09|h:0|pt:19.43|p:983.65|g:10.60=r:470|t:15.08|h:84.22|pt:19.41|p:983.53|g:6.62=r:477|t:15.11|h:84.61|pt:19.41|p:983.61|g:21.19=";
     HistoryCard presentCard = new HistoryCard() { Temperature = 15, Humidity = 84.33f, Pressure = 983.6f, Radiation = 12.8f, Description = "-", WindDirection = "-", WindSpeed = 0 };
     var card = ParserMeteoData.ParseInCard(data);
     CheckHistoryCard(presentCard, card);
 }
Example #2
0
 public JsonPresentCard(HistoryCard card)
 {
     this.Temperature = card.Temperature;
     this.Humidity = card.Humidity;
     this.Pressure = card.Pressure;
     this.Radiation = card.Radiation;
     this.WindDirection = card.WindDirection;
     this.Description = card.Description;
 }
 public void CheckHistoryCard(HistoryCard historyCard, HistoryCard card)
 {
     Assert.AreEqual(historyCard.Temperature, card.Temperature);
     Assert.AreEqual(historyCard.Humidity, card.Humidity);
     Assert.AreEqual(historyCard.Pressure, card.Pressure);
     Assert.AreEqual(historyCard.Radiation, card.Radiation);
     Assert.AreEqual(historyCard.WindDirection, card.WindDirection);
     Assert.AreEqual(historyCard.WindSpeed, card.WindSpeed);
     Assert.AreEqual(historyCard.Description, card.Description);
 }
 public void AllValidation_CorrectHistoryCard()
 {
     HistoryCard card = new HistoryCard() { Temperature = 15,
                                            Humidity = 84.33f,
                                            Pressure = 983.6f,
                                            Radiation = 12.8f,
                                            Description = "-",
                                            WindDirection = "NE",
                                            WindSpeed = 23 };
     Assert.IsTrue(DataValidation.AllValidation(card));
 }
 public static bool AllValidation(HistoryCard historyCard)
 {
     if (historyCard == null)
         return false;
     if (TemperatureValidation(historyCard.Temperature) &&
         HumidityValidation(historyCard.Humidity) &&
         PressureValidation(historyCard.Pressure) &&
         RadiationValidation(historyCard.Radiation) &&
         WindDirectionValidation(historyCard.WindDirection) &&
         DescriptionValidation(historyCard.Description))
         return true;
     else
         return false;
 }
 public static HistoryCard ParseInCard(string data)
 {
     string pattern = @"r:[0-9]+\|t:([0-9]+|[0-9]+\.[0-9]+)\|h:([0-9]+|[0-9]+\.[0-9]+)\|pt:([0-9]+|[0-9]+\.[0-9]+)\|p:([0-9]+|[0-9]+\.[0-9]+)\|g:([0-9]+|[0-9]+\.[0-9]+)=";
     string measurement, field;
     int countMeasurementTemperature = 0, countMeasurementHumidity = 0, countMeasurementPressure = 0, countMeasurementRadiation = 0;
     HistoryCard presentCard = new HistoryCard() { Temperature = 0, Humidity = 0, Pressure = 0, Radiation = 0 };
     Regex regexPackage = new Regex(pattern);
     Regex regexTemperature = new Regex(@"t:([0-9]+\.[0-9]+|[0-9]+)");
     Regex regexHumidity = new Regex(@"h:([0-9]+\.[0-9]+|[0-9]+)");
     Regex regexPressure = new Regex(@"p:([0-9]+\.[0-9]+|[0-9]+)");
     Regex regexRadiation = new Regex(@"g:([0-9]+\.[0-9]+|[0-9]+)");
     Match match = regexPackage.Match(data);
     while (match.Success)
     {
         measurement = match.Value;
         field = regexTemperature.Match(measurement).Value.Remove(0, 2);
         presentCard.Temperature += (int)Convert.ToSingle(field, new CultureInfo("en-US"));
         field = regexHumidity.Match(measurement).Value.Remove(0, 2);
         presentCard.Humidity += Convert.ToSingle(field, new CultureInfo("en-US"));
         field = regexPressure.Match(measurement).Value.Remove(0, 2);
         presentCard.Pressure += Convert.ToSingle(field, new CultureInfo("en-US"));
         field = regexRadiation.Match(measurement).Value.Remove(0, 2);
         presentCard.Radiation += Convert.ToSingle(field, new CultureInfo("en-US"));
         match = match.NextMatch();
         countMeasurementHumidity++;
     }
     presentCard.Temperature /= countMeasurementHumidity;
     presentCard.Humidity = (float)Math.Round(presentCard.Humidity / countMeasurementHumidity, 2);
     presentCard.Pressure = (float)Math.Round(presentCard.Pressure / countMeasurementHumidity, 2);
     presentCard.Radiation = (float)Math.Round(presentCard.Radiation / countMeasurementHumidity, 2);
     presentCard.Description = "-";
     presentCard.WindDirection = "-";
     presentCard.WindSpeed = 0;
     HistoryCard card = new HistoryCard() { Temperature = 15, Humidity = 84.33f, Pressure = 983.6f, Radiation = 12.8f };
     presentCard.Description = "-";
     presentCard.WindDirection = "-";
     presentCard.WindSpeed = 0;
     return presentCard;
 }