Skip to content

Commit 92ad3f4

Browse files
committed
Fix learn page exercise and add unit tests (93)
- Fix Validate Data exercise solution: add parentheses around pipe expression to resolve operator precedence issue - Add unit tests for all 7 exercise solutions to prevent future regressions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 36b3632 commit 92ad3f4

3 files changed

Lines changed: 64 additions & 1 deletion

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Problem to solve
2+
3+
At least the solution of the last exercice does not parse.
4+
5+
```elo
6+
let Product = { name: String, price: Int } in
7+
assert({ name: 'Widget', price: '99' } |> Product == { name: 'Widget', price: 99 })
8+
```
9+
10+
## Idea
11+
12+
* Check the unit test we have that was supposed to check all examples/exercices on
13+
the website is up to date.
14+
* Complete it if needed
15+
* Fix examples that don't work (or fix parser/compilation to make them pass)

test/unit/learn-examples.unit.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,51 @@ describe('Learn Page Examples - Lesson 15: Parsing Data', () => {
168168
assert.throws(() => compile("Int('not a number')", { runtime }), /expected Int/);
169169
});
170170
});
171+
172+
/**
173+
* Exercise Solutions
174+
* These tests verify that all exercise solutions on the Learn page
175+
* are valid Elo code that compiles and evaluates successfully.
176+
*/
177+
178+
describe('Learn Page Exercises - Build a Greeting', () => {
179+
it('should pass the greeting assertion', () => {
180+
assert.strictEqual(compile("assert('Hello, ' + 'World!' == 'Hello, World!')", { runtime }), true);
181+
});
182+
});
183+
184+
describe('Learn Page Exercises - Product Total', () => {
185+
it('should pass the product total assertion', () => {
186+
assert.strictEqual(compile("assert({ price: 25, quantity: 4 }.price * { price: 25, quantity: 4 }.quantity == 100)", { runtime }), true);
187+
});
188+
});
189+
190+
describe('Learn Page Exercises - Text Transform', () => {
191+
it('should pass the text transform assertion', () => {
192+
assert.strictEqual(compile("assert(upper(trim(' hello ')) == 'HELLO')", { runtime }), true);
193+
});
194+
});
195+
196+
describe('Learn Page Exercises - Rectangle Area', () => {
197+
it('should pass the rectangle area assertion', () => {
198+
assert.strictEqual(compile("let width = 8, height = 5 in assert(width * height == 40)", { runtime }), true);
199+
});
200+
});
201+
202+
describe('Learn Page Exercises - Filter and Double', () => {
203+
it('should pass the filter and double assertion', () => {
204+
assert.strictEqual(compile("assert(([5, 12, 8, 20, 3, 15] |> filter(x ~> x > 10) |> map(x ~> x * 2)) == [24, 40, 30])", { runtime }), true);
205+
});
206+
});
207+
208+
describe('Learn Page Exercises - Order Total', () => {
209+
it('should pass the order total assertion', () => {
210+
assert.strictEqual(compile("let order = { price: 50, quantity: 3 } in assert(order.price * order.quantity == 150)", { runtime }), true);
211+
});
212+
});
213+
214+
describe('Learn Page Exercises - Validate Data', () => {
215+
it('should pass the validate data assertion', () => {
216+
assert.strictEqual(compile("let Product = { name: String, price: Int } in assert(({ name: 'Widget', price: '99' } |> Product) == { name: 'Widget', price: 99 })", { runtime }), true);
217+
});
218+
});

web/src/pages/learn.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ in
732732
<h4>Solution</h4>
733733
<div class="lesson-example" data-action="click->doc#tryExample">
734734
<pre class="example-code">let Product = &#123; name: String, price: Int &#125; in
735-
assert(&#123; name: 'Widget', price: '99' &#125; |> Product == &#123; name: 'Widget', price: 99 &#125;)</pre>
735+
assert((&#123; name: 'Widget', price: '99' &#125; |> Product) == &#123; name: 'Widget', price: 99 &#125;)</pre>
736736
</div>
737737
</div>
738738
</section>

0 commit comments

Comments
 (0)