Skip to content

Commit b546e96

Browse files
resolve conflict (#775)
* add code for difference between reduce, scan and fold article * add tests when collection is empty * update tests to resolve conflict
1 parent 82f508a commit b546e96

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

scala-core-8/src/test/scala/com/baeldung/scala/highorderfunctions/HighOrderFunctionsUnitTest.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,23 @@ class HighOrderFunctionsUnitTest extends AnyFlatSpec with Matchers {
7474
val actualResult = numbers.scanRight(1)(_ + _)
7575
assert(List(16, 15, 13, 10, 6, 1) == actualResult)
7676
}
77+
78+
"reduceLeft" should "throw an exception" in {
79+
val numbers = List.empty[Int]
80+
assertThrows[UnsupportedOperationException] {
81+
numbers.reduceLeft(_ max _)
82+
}
83+
}
84+
85+
"foldRight" should "return the initial element i.e $" in {
86+
val alphabets = List.empty[String]
87+
val actualResult = alphabets.foldRight("$")(_ + _)
88+
assert("$" == actualResult)
89+
}
90+
91+
"scanRight" should "return the initial element i.e 5" in {
92+
val numbers = List.empty[Int]
93+
val actualResult = numbers.scanRight(5)(_ + _)
94+
assert(List(5) == actualResult)
95+
}
7796
}

0 commit comments

Comments
 (0)