Skip to content

Commit 734fb0a

Browse files
committed
added some more comments to exercise
1 parent 1f30cc1 commit 734fb0a

File tree

1 file changed

+22
-10
lines changed
  • first-class-functions/src/test/scala/scalaexamples/firstclassfunctions

1 file changed

+22
-10
lines changed

first-class-functions/src/test/scala/scalaexamples/firstclassfunctions/PersonTest.scala

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import org.junit.runners.JUnit4
77

88
// Comment in the tests below and make them run and pass
99

10+
// The objective in each exercise is to
11+
// transform the list 'persons' in some way,
12+
// using the functions filter, map etc. on the list
13+
1014
@RunWith(classOf[JUnit4])
1115
class PersonTest extends EmptyTest {
1216

@@ -18,7 +22,7 @@ class PersonTest extends EmptyTest {
1822

1923
// @Test
2024
def testAdults {
21-
// Find all adults
25+
// Filter the list of persons to find all adults
2226
val adults = Nil
2327

2428
assertEquals(List(alf, fredrik), adults)
@@ -34,15 +38,17 @@ class PersonTest extends EmptyTest {
3438

3539
// @Test
3640
def testNamesOfAdults {
37-
// Find the names of all adults
41+
// Create a list containing the names of the adults,
42+
// by combining the approaches in the two exercies above
3843
val names = Nil
3944

4045
assertEquals(List("Alf", "Fredrik"), names)
4146
}
4247

4348
// @Test
4449
def testAgeLimit {
45-
// Split the list of persons into two new lists containing adults and kids
50+
// Partition the list of persons into two new lists,
51+
// one containing the adults and one containing the kids
4652
val (adults, kids) = (Nil, Nil)
4753

4854
assertEquals(List(alf, fredrik), adults)
@@ -61,7 +67,7 @@ class PersonTest extends EmptyTest {
6167

6268
// @Test
6369
def testFindByName {
64-
// Find the person named "Johannes"
70+
// Find the person named "Johannes" in the list of persons
6571
val name = "Johannes"
6672
val person: Option[Person] = null
6773

@@ -85,7 +91,8 @@ class PersonTest extends EmptyTest {
8591

8692
// @Test
8793
def testFindEmailAddressesByName {
88-
// Find the e-mail addresses of the person named "Alf". Here you must first find the person,
94+
// Find the e-mail addresses of the person named "Alf".
95+
// Here you must first find the person,
8996
// then map the collection to a different type
9097
val name = "Alf"
9198
val addresses: Option[List[EmailAddress]] = null
@@ -98,8 +105,11 @@ class PersonTest extends EmptyTest {
98105

99106
// @Test
100107
def testFindPersonByEmail {
101-
// Find the person who has the e-mail address "fvr@knowit.no". Hint, try combinining
102-
// finding the person and check if the person has an email that exists according to the adress.
108+
// Find the person who has the e-mail address "fvr@knowit.no".
109+
110+
// Hint: Try combinining finding the person and checking if
111+
// there exists an email address matching the criteria in the
112+
// person's list of email addresses.
103113
val address = EmailAddress("fvr@knowit.no")
104114
val person: Option[Person] = null
105115

@@ -112,9 +122,11 @@ class PersonTest extends EmptyTest {
112122
// @Test
113123
def testGetFirstEmailAddress {
114124
// Create a new list of the first e-mail address of each person,
115-
// filtering out persons without e-mail addresses. Hint try combining
116-
// filtering the list and then mapping it to a different type, only
117-
// getting the head of the email address list.
125+
// filtering out persons without e-mail addresses.
126+
127+
// Hint: Try combining filtering the list and then
128+
// mapping it to a different type, only getting
129+
// the head of the email address list.
118130
val addresses = Nil
119131

120132
assertEquals(List(alf.emailAddresses.head, fredrik.emailAddresses.head), addresses)

0 commit comments

Comments
 (0)