@@ -7,6 +7,10 @@ import org.junit.runners.JUnit4
7
7
8
8
// Comment in the tests below and make them run and pass
9
9
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
+
10
14
@ RunWith (classOf [JUnit4 ])
11
15
class PersonTest extends EmptyTest {
12
16
@@ -18,7 +22,7 @@ class PersonTest extends EmptyTest {
18
22
19
23
// @Test
20
24
def testAdults {
21
- // Find all adults
25
+ // Filter the list of persons to find all adults
22
26
val adults = Nil
23
27
24
28
assertEquals(List (alf, fredrik), adults)
@@ -34,15 +38,17 @@ class PersonTest extends EmptyTest {
34
38
35
39
// @Test
36
40
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
38
43
val names = Nil
39
44
40
45
assertEquals(List (" Alf" , " Fredrik" ), names)
41
46
}
42
47
43
48
// @Test
44
49
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
46
52
val (adults, kids) = (Nil , Nil )
47
53
48
54
assertEquals(List (alf, fredrik), adults)
@@ -61,7 +67,7 @@ class PersonTest extends EmptyTest {
61
67
62
68
// @Test
63
69
def testFindByName {
64
- // Find the person named "Johannes"
70
+ // Find the person named "Johannes" in the list of persons
65
71
val name = " Johannes"
66
72
val person : Option [Person ] = null
67
73
@@ -85,7 +91,8 @@ class PersonTest extends EmptyTest {
85
91
86
92
// @Test
87
93
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,
89
96
// then map the collection to a different type
90
97
val name = " Alf"
91
98
val addresses : Option [List [EmailAddress ]] = null
@@ -98,8 +105,11 @@ class PersonTest extends EmptyTest {
98
105
99
106
// @Test
100
107
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.
103
113
val address = EmailAddress (" fvr@knowit.no" )
104
114
val person : Option [Person ] = null
105
115
@@ -112,9 +122,11 @@ class PersonTest extends EmptyTest {
112
122
// @Test
113
123
def testGetFirstEmailAddress {
114
124
// 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.
118
130
val addresses = Nil
119
131
120
132
assertEquals(List (alf.emailAddresses.head, fredrik.emailAddresses.head), addresses)
0 commit comments