Skip to content

Commit 7461054

Browse files
Merge pull request #127 from jeremylaier/(FIX)EvalExercises
Updated Eval Exercise to take input, spec was off as well
2 parents fd11e26 + 2d5fb5b commit 7461054

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/main/scala/catslib/EvalSection.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
5959
* eager.value
6060
* // res0: Int = 7
6161
*/
62-
def nowEval(resultList: List[Int]) = {
62+
def nowEval(res0: List[Int]) = {
6363
//given
6464
val eagerEval = Eval.now {
6565
println("This is eagerly evaluated")
6666
1 :: 2 :: 3 :: Nil
6767
}
6868

6969
//when/then
70-
eagerEval.value shouldBe (resultList: List[Int])
70+
eagerEval.value shouldBe (res0)
7171
}
7272

7373
/**
@@ -97,7 +97,7 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
9797
* First, it allows the runtime to perform garbage collection of the thunk after evaluation, leading to more memory being freed earlier.
9898
* Secondly, when lazy vals are evaluated, in order to preserve thread-safety, the Scala compiler will lock the whole surrounding class, whereas Eval will only lock itself.
9999
*/
100-
def laterEval(resultList: List[Int], counterResult: Int) = {
100+
def laterEval(res0: List[Int], res1: Int) = {
101101
//given
102102
val n = 2
103103
var counter = 0
@@ -109,8 +109,8 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
109109

110110
//when/then
111111
List.fill(n)("").foreach(_ => lazyEval.value)
112-
lazyEval.value shouldBe (resultList: List[Int])
113-
counter shouldBe counterResult
112+
lazyEval.value shouldBe res0
113+
counter shouldBe res1
114114
}
115115

116116
/**
@@ -128,7 +128,7 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
128128
* alwaysEval.eval
129129
* }}}
130130
*/
131-
def alwaysEval(resultList: List[Int], counterAfterListEval: Int, latestCounter: Int) = {
131+
def alwaysEval(res0: Int, res1: List[Int], res2: Int) = {
132132
//given
133133
val n = 4
134134
var counter = 0
@@ -140,9 +140,9 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
140140

141141
//when/then
142142
List.fill(n)("").foreach(_ => alwaysEval.value)
143-
counter shouldBe counterAfterListEval
144-
alwaysEval.value shouldBe (resultList: List[Int])
145-
counter shouldBe latestCounter
143+
counter shouldBe res0
144+
alwaysEval.value shouldBe res1
145+
counter shouldBe res2
146146
}
147147

148148
/**
@@ -152,15 +152,15 @@ object EvalSection extends AnyFlatSpec with Matchers with org.scalaexercises.def
152152
* This is useful when you want to delay execution of an expression which produces an Eval[A] value. Like .flatMap, it is stack-safe.
153153
* Because Eval guarantees stack-safety, we can chain a lot of computations together using flatMap without fear of blowing up the stack.
154154
*/
155-
def deferEval(resultList: List[Int]) = {
155+
def deferEval(res0: List[Int]) = {
156156
//given
157157
val list = List.fill(3)(0)
158158

159159
//when
160160
val deferedEval: Eval[List[Int]] = Eval.now(list).flatMap(e => Eval.defer(Eval.later(e)))
161161

162162
//then
163-
Eval.defer(deferedEval).value shouldBe (resultList: List[Int])
163+
Eval.defer(deferedEval).value shouldBe res0
164164
}
165165

166166
}

src/test/scala/catslib/EvalSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class EvalSpec extends RefSpec with Checkers {
4646
check(
4747
Test.testSuccess(
4848
EvalSection.alwaysEval _,
49-
List(1, 2, 3, 4) :: 4 :: 5 :: HNil
49+
4 :: List(1, 2, 3, 4) :: 5 :: HNil
5050
)
5151
)
5252
}

0 commit comments

Comments
 (0)