Skip to content

Commit 9d27949

Browse files
committed
Some more hopefulle helpful comments and hints on pattern matching.
1 parent 27b3623 commit 9d27949

File tree

5 files changed

+14
-3
lines changed

5 files changed

+14
-3
lines changed

pattern-matching/src/test/scala/scalaexamples/patternmatching/ListMatchingTest.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class ListMatchingTest extends EmptyTest {
1515

1616
// matchedElement must find the first element. It can also skip the rest (if you want to)
1717
val mathedElement = list match {
18+
// Insert you match statement(s) here
1819
case _ => "failed"
1920
}
2021

@@ -24,10 +25,10 @@ class ListMatchingTest extends EmptyTest {
2425
// @Test
2526
def matchSecondElementOfList {
2627

27-
// matchedElement should fint the second element of the list.
28+
// matchedElement should find the second element of the list.
2829
// You may ignore the first element and any subsequent elements if you want
2930
val mathedElement = list match {
30-
//case List(firstElement, middle, lastElement) => middle
31+
// Insert you match statement here
3132
case _ => "failed"
3233
}
3334

@@ -45,6 +46,7 @@ class ListMatchingTest extends EmptyTest {
4546

4647
// You must find the sublist to make the test pass.
4748
val mathedElement = nestedList match {
49+
// Insert you match statement here
4850
case _ => "failed"
4951
}
5052

@@ -58,6 +60,7 @@ class ListMatchingTest extends EmptyTest {
5860

5961
// Here you must find the first element of the second sublist
6062
val mathedElement = list match {
63+
// Insert you match statement here
6164
case _ => "failed"
6265
}
6366
assertEquals(subList(0), mathedElement)

pattern-matching/src/test/scala/scalaexamples/patternmatching/MyCaseClassMatchingTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class MyCaseClassMatchingTest extends EmptyTest {
2727
case _ => error("Should never reach this")
2828
}
2929

30+
// You should not change the following code at all. Only add matches which will make the tests match.
3031
var theClass: MyCaseClass = FirstSubClass(10)
3132
var foundElement = mathSubType(theClass)
3233
assertEquals(10, foundElement)

pattern-matching/src/test/scala/scalaexamples/patternmatching/RegexMatchingTest.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class RegexMatchingTest extends EmptyTest {
1818
val matchRegex = "(.+)".r
1919

2020
val mathedElement = string match {
21+
// Insert you match statement here
2122
case _ => "Failed"
2223
}
2324

@@ -31,6 +32,7 @@ class RegexMatchingTest extends EmptyTest {
3132
val matchRegex = """""".r
3233

3334
val mathedElement = string match {
35+
// Insert you match statement here
3436
case _ => "Failed"
3537
}
3638

@@ -42,6 +44,8 @@ class RegexMatchingTest extends EmptyTest {
4244
val start = "This"
4345
val end = "for"
4446
val string = start + " is the string to find a match " + end
47+
48+
// Create a regular expression which will make the folliwing match and assertions correct.
4549
val matchRegex = """""".r
4650

4751
val (first, last) = string match {
@@ -58,9 +62,11 @@ class RegexMatchingTest extends EmptyTest {
5862

5963
// Create a regex which identifies email (may be really simple)
6064
// val emailRegex = """([^@]+)@(.+)""".r
65+
// You may use the regex above.
6166
val emailRegex = "".r
6267

6368
def isValidEmail(stringToTest: String) = stringToTest match {
69+
// Insert you match statement here
6470
case _ => false
6571
}
6672

pattern-matching/src/test/scala/scalaexamples/patternmatching/TupleTestMatchTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TupleTestMatchTest extends EmptyTest {
2424

2525
simpleTuple match {
2626
case (one, _) => assertEquals(2, one)
27-
// Comment in this line and make this run, (hint create guard on the previous match)
27+
// Comment in this line and make this run, (hint create guard on the previous match, so that it won't hit)
2828
// case (one, _) => assertEquals(1, one)
2929
case _ => error("Couldnt match it")
3030
}

pattern-matching/src/test/scala/scalaexamples/patternmatching/TypeMatchingTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TypeMatchingTest extends EmptyTest {
1414
for (element <- elements) {
1515
element match {
1616
// Make test run, and assert on types, e.g. " => assertEquals(23, integer)" or " => assertEquals("Hello", s)"
17+
// Insert your matching code here
1718
case other => error("Should match other on type")
1819
}
1920
}

0 commit comments

Comments
 (0)