Created
November 2, 2014 21:44
-
-
Save vfarcic/4b4a4eb9507deceb2b6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.technologyconversations.java8exercises.streams; | |
import org.junit.Test; | |
import java.util.List; | |
import static com.technologyconversations.java8exercises.streams.PeopleStats.*; | |
import static java.util.Arrays.asList; | |
import static org.assertj.core.api.Assertions.assertThat; | |
/* | |
Get people statistics: average age, count, maximum age, minimum age and sum og all ages. | |
*/ | |
public class PeopleStatsSpec { | |
Person sara = new Person("Sara", 4); | |
Person viktor = new Person("Viktor", 40); | |
Person eva = new Person("Eva", 42); | |
List<Person> collection = asList(sara, eva, viktor); | |
@Test | |
public void getStatsShouldReturnAverageAge() { | |
assertThat(getStats(collection).getAverage()) | |
.isEqualTo((double)(4 + 40 + 42) / 3); | |
} | |
@Test | |
public void getStatsShouldReturnNumberOfPeople() { | |
assertThat(getStats(collection).getCount()) | |
.isEqualTo(3); | |
} | |
@Test | |
public void getStatsShouldReturnMaximumAge() { | |
assertThat(getStats(collection).getMax()) | |
.isEqualTo(42); | |
} | |
@Test | |
public void getStatsShouldReturnMinimumAge() { | |
assertThat(getStats(collection).getMin()) | |
.isEqualTo(4); | |
} | |
@Test | |
public void getStatsShouldReturnSumOfAllAges() { | |
assertThat(getStats(collection).getSum()) | |
.isEqualTo(40 + 42 + 4); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment