*
* @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
*/
-class WetterComState(val dateTime: ZonedDateTime) : AbstractState(true) {
+class WetterComState(val dateTime: ZonedDateTime) : AbstractState(true), Iterable<HourState> {
val hours: List<HourState> = mutableListOf()
(hours as MutableList<HourState>).add(hourState)
}
+ override fun iterator(): Iterator<HourState> {
+ return hours.iterator()
+ }
+
override fun equals(other: Any?): Boolean {
other as? WetterComState ?: return false
return (dateTime == other.dateTime) and (hours == other.hours)
assertThat(firstState, `is`(secondState))
}
+ @Test
+ fun iteratingDeliversHourStates() {
+ val now = Instant.now().atZone(ZoneId.of("UTC"))
+ val firstState = WetterComState(ZonedDateTime.from(now))
+ firstState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1"))
+ firstState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2"))
+ assertThat(firstState.iterator().asSequence().toList(), `is`(firstState.hours as Iterable<HourState>))
+ }
+
}