Skip to content

Add Zipper practice exercise#162

Closed
jojo8356 wants to merge 2 commits intoexercism:mainfrom
jojo8356:add-zipper-exercise
Closed

Add Zipper practice exercise#162
jojo8356 wants to merge 2 commits intoexercism:mainfrom
jojo8356:add-zipper-exercise

Conversation

@jojo8356
Copy link

Closes #157

@jojo8356
Copy link
Author

(TestSuite.empty \"{exercise}\")"

def genTestCase (_exercise : String) (_case : TreeMap.Raw String Json) : String :=
"" -- Zipper tests are handwritten due to complex operation chaining
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests aren’t complex enough to justify hardcoding them. One of the main purposes of a generator is to make it easy to automatically add new test cases in the future, which is impossible with handwritten tests.

/-
You should define:

1. A `BinTree` inductive type representing a binary tree where each node
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is best if we don't mention "inductive" here. A binary tree may be defined in other ways and it is not the focus of this exercise. We should simply say a BinTree type.

1. A `BinTree` inductive type representing a binary tree where each node
has a value (Int), a left subtree, and a right subtree.

2. A `Zipper` structure that allows navigating within a binary tree.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zipper type

return assertEqual none result)
|>.addTest "left, right, and up" (do
let zipper := fromTree initialTree
let result := zipper.left >>= Zipper.up >>= Zipper.right >>= Zipper.up >>= Zipper.left >>= Zipper.right >>= (·.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should serialize long sequences of operations in different lines.

You should define:

1. A `BinTree` inductive type representing a binary tree where each node
has a value (Int), a left subtree, and a right subtree.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering this is a harder exercise, I think we should make the tree polymorphic and add a few extra test cases for other types (maybe String).

Extra cases may be defined in an extra.json inside the .meta folder for the exercise. They are called in the same way as those in canonical data, but they don't need an uuid.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Fixed. Rewrote the generator to properly parse the canonical data JSON (tree serialization, operation chaining, handling all expected types). Thanks for the feedback.

  2. Fixed, changed to "BinTree type".

  3. Fixed, changed to "Zipper type".

  4. Fixed. Operations are now chained on separate lines using >>=.

  5. Done. Made BinTree α and Zipper α polymorphic. Added 3 extra String test cases in .meta/extra.json (data retained, left/right/value, set_value).

@github-actions
Copy link
Contributor

Hello. Thanks for opening a PR on Exercism 🙂

We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in.

You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch.

If you're interested in learning more about this auto-responder, please read this blog post.


Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it.

@github-actions github-actions bot closed this Mar 25, 2026
@oxe-i oxe-i reopened this Mar 25, 2026
@oxe-i oxe-i added x:size/large Large amount of work x:rep/large Large amount of reputation labels Mar 25, 2026
@oxe-i
Copy link
Contributor

oxe-i commented Mar 25, 2026

The initial tree for the tests remains hardcoded, even though the extra cases have their own initial trees (which are simply disregarded).

The extra cases are also in invalid format. They should be in a JSON array. This means the test file was not generated from the generator file using the generator script.

Since this PR does not follow our contribution guidelines, it will be closed. Thank you for your contribution.

@oxe-i oxe-i closed this Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

x:rep/large Large amount of reputation x:size/large Large amount of work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Zipper practice exercise

2 participants