Skip to content

Commit 65c562c

Browse files
authored
Ch6 - Fix Action Self test and solution (#284)
* Revert "Add concrete test for Multiply Self append (#199)" This reverts commit 217f6c1. * Replacement Multiply Self concrete test * Relax concrete tests These still catch the incorrect instances, but are easier to troubleshoot.
1 parent b000a6b commit 65c562c

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

exercises/chapter6/test/Main.purs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ Note to reader: Delete this line to expand comment block -}
174174
test "Multiply Int append" do
175175
Assert.equal (act m1 (act m2 a))
176176
$ act (m1 <> m2) a
177-
test "Multiply Int append concrete" do
178-
Assert.equal 60
179-
$ act (m1 <> m2) a
177+
test "Multiply Int concrete" do
178+
Assert.equal 15
179+
$ act m1 a
180180
-- Multiply String is the actual exercise question
181181
suite "Multiply String" do
182182
let
@@ -187,9 +187,9 @@ Note to reader: Delete this line to expand comment block -}
187187
test "Multiply String append" do
188188
Assert.equal (act m1 (act m2 a))
189189
$ act (m1 <> m2) a
190-
test "Multiply String append concrete" do
191-
Assert.equal "foofoofoofoofoofoofoofoofoofoofoofoo"
192-
$ act (m1 <> m2) a
190+
test "Multiply String concrete" do
191+
Assert.equal "foofoofoo"
192+
$ act m1 a
193193
suite "Exercise - Action Class - actionArray instance" do
194194
suite "Multiply Array Int" do
195195
let
@@ -200,9 +200,9 @@ Note to reader: Delete this line to expand comment block -}
200200
test "Multiply Array Int append" do
201201
Assert.equal (act m1 (act m2 a))
202202
$ act (m1 <> m2) a
203-
test "Multiply Array Int append concrete" do
204-
Assert.equal [ 12, 24, 36 ]
205-
$ act (m1 <> m2) a
203+
test "Multiply Array Int concrete" do
204+
Assert.equal [ 3, 6, 9 ]
205+
$ act m1 a
206206
suite "Multiply Array String" do
207207
let
208208
a = [ "foo", "bar", "baz" ]
@@ -212,13 +212,13 @@ Note to reader: Delete this line to expand comment block -}
212212
test "Multiply Array String append" do
213213
Assert.equal (act m1 (act m2 a))
214214
$ act (m1 <> m2) a
215-
test "Multiply Array String append concrete" do
215+
test "Multiply Array String concrete" do
216216
Assert.equal
217-
[ "foofoofoofoofoofoofoofoofoofoofoofoo"
218-
, "barbarbarbarbarbarbarbarbarbarbarbar"
219-
, "bazbazbazbazbazbazbazbazbazbazbazbaz"
217+
[ "foofoofoo"
218+
, "barbarbar"
219+
, "bazbazbaz"
220220
]
221-
$ act (m1 <> m2) a
221+
$ act m1 a
222222
suite "Exercise - Action Class - actionSelf instance" do
223223
let
224224
a = Self m1
@@ -228,9 +228,9 @@ Note to reader: Delete this line to expand comment block -}
228228
test "Multiply Self append" do
229229
Assert.equal (act m1 (act m2 a))
230230
$ act (m1 <> m2) a
231-
test "Multiply Self append concrete" do
232-
Assert.equal 72
233-
$ act (act (m1 <> m2) a) 2
231+
test "Multiply Self concrete" do
232+
Assert.equal (Self (Multiply 12))
233+
$ act m2 a
234234
suite "Exercise Group - Hashes" do
235235
suite "Exercise - arrayHasDuplicates" do
236236
test "No dupe" do

exercises/chapter6/test/no-peeking/Solutions.purs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,6 @@ instance actionSelf :: Monoid m => Action m (Self m) where
219219
-- These may also be written manualy
220220
derive newtype instance showSelf :: Show m => Show (Self m)
221221
derive newtype instance eqSelf :: Eq m => Eq (Self m)
222-
derive newtype instance semigroupSelf :: Semigroup m => Semigroup (Self m)
223-
derive newtype instance monoidSelf :: Monoid m => Monoid (Self m)
224-
225-
instance repeatActionMultSelf :: Action (Self Multiply) Int where
226-
act (Self (Multiply m)) s = m * s
227222

228223
arrayHasDuplicates :: forall a. Hashable a => Array a -> Boolean
229224
arrayHasDuplicates arr =

0 commit comments

Comments
 (0)