package eirb.pg203.weather.data; import eirb.pg203.weather.utils.City; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.MethodSource; import java.time.Instant; import java.util.stream.Stream; public class WeatherDataTest { private static final float epsilon = 0.01F; private WeatherData weatherData; @BeforeEach public void setWeatherData() { this.weatherData = new WeatherData(new City("f"), Instant.now(), 0f, 0, 0, WeatherData.Condition.SUNNY); } @Test void city() { String cityName = "Paris"; City city = new City(cityName); this.weatherData.setCity(city); /* check if the setter works */ Assertions.assertEquals(weatherData.getCity(), city); } @Test void temp() { float temp = 69.69f; this.weatherData.setTemp(temp); /* check if the setter works */ Assertions.assertEquals(temp, weatherData.getTemp(), epsilon); } @ParameterizedTest(name = "Set {0}") @EnumSource void condition(WeatherData.Condition condition) { this.weatherData.setCondition(condition); /* check if the setter works */ Assertions.assertEquals(condition, weatherData.getCondition()); } @Test void windSpeed() { float windSpeed = 69.69f; this.weatherData.setWindSpeed(windSpeed); /* check if the setter works */ Assertions.assertEquals(windSpeed, weatherData.getWindSpeed()); } @Test void windAngle() { float windAngle = 69.69f; this.weatherData.setWindDirectionAngle(windAngle); /* check if the setter works */ Assertions.assertEquals(windAngle, weatherData.getWindDirectionAngle()); } @Test void date() { Instant instant = Instant.now(); this.weatherData.setDate(instant); /* check if the setter works */ Assertions.assertEquals(instant, weatherData.getDate()); } @Test void stringRepresentation() { this.weatherData = new WeatherData(new City("f"), Instant.now(), 0f, 0, 0, WeatherData.Condition.SUNNY); Assertions.assertEquals("00.00° ☀️ 00.00km/h 000.00° 🡩", weatherData.toString()); } private static Stream windDirectionRepresentation() { return Stream.of( Arguments.arguments(0f, WeatherData.WindDirection.N), Arguments.arguments(45f, WeatherData.WindDirection.NE), Arguments.arguments(90f, WeatherData.WindDirection.E), Arguments.arguments(135f, WeatherData.WindDirection.SE), Arguments.arguments(180f, WeatherData.WindDirection.S), Arguments.arguments(225f, WeatherData.WindDirection.SW), Arguments.arguments(270f, WeatherData.WindDirection.W), Arguments.arguments(315f, WeatherData.WindDirection.NW), Arguments.arguments(999f, WeatherData.WindDirection.ERROR) ); } @ParameterizedTest @MethodSource void windDirectionRepresentation(float windDirection, WeatherData.WindDirection expectedWindDirection){ weatherData.setWindDirectionAngle(windDirection); Assertions.assertEquals(expectedWindDirection, weatherData.getWindDirection()); } }