PC03-L04 · guided challenge

All orders under a limit

Transform orders into decisions and then verify all results.

Practical CEL4 test casesDocumented
What will I practise?

You can read a map().all() chain and handle an empty list deliberately.

How is it checked?

Your one expression must produce the expected result for all four JSON inputs.

When am I done?

When all tests pass and you can explain every condition in your expression.

Word problem

There must be at least one order, and every order total must be less than or equal to the configured limit.

Exact requirements

  1. An empty list is explicitly rejected.
  2. Map each order to a boolean limit decision.
  3. Require every mapped boolean to be true.

Required result

Write one CEL expression. It must return the expected value and type for all four prepared JSON inputs. Do not change the inputs to make an incomplete expression pass.

Recommended procedure

  1. Translate each numbered requirement into one small boolean condition.
  2. Run the starter expression and inspect which cases fail.
  3. Add one condition at a time and run the complete suite again.
  4. Mark the challenge complete only when you can explain every operator and every boundary.

Solve the challenge · browser test suite

Write one expression that passes every case

Edit the CEL expression, then run it against all prepared JSON inputs. A solution is complete only when every case passes.

4 test cases

Hint: map() creates a bool list; all() then requires every bool to be true.

Tip: press Ctrl/⌘ + Enter to run all tests.
All under limitNot run yet
Expected: true · bool
Show JSON input
{
  "orders": [
    {
      "total": 80
    },
    {
      "total": 100
    }
  ],
  "limit": 100
}
One over limitNot run yet
Expected: false · bool
Show JSON input
{
  "orders": [
    {
      "total": 80
    },
    {
      "total": 101
    }
  ],
  "limit": 100
}
Exactly at limitNot run yet
Expected: true · bool
Show JSON input
{
  "orders": [
    {
      "total": 100
    }
  ],
  "limit": 100
}
No ordersNot run yet
Expected: false · bool
Show JSON input
{
  "orders": [],
  "limit": 100
}
Test result

Not run yet

The same expression runs against every case. Test data is fixed so that boundary and failure scenarios cannot be skipped.

Explained solution

Show the complete expression
orders.size() > 0 && orders.map(order, order.total <= limit).all(eligible, eligible)

Why the solution works

  1. size() > 0 defines the required empty-list behavior.
  2. map() preserves order but replaces each order with order.total <= limit.
  3. The mapped list contains only bool values.
  4. all(eligible, eligible) requires every one of those values to be true.

What the test cases prove

  • All under limit: expected true (bool).
  • One over limit: expected false (bool).
  • Exactly at limit: expected true (bool).
  • No orders: expected false (bool).

The cases are intentionally different. A solution that passes only the first case has not yet implemented the complete rule.

Common mistake

Do not optimise the expression for the first successful input. A requirement is implemented only when its positive case, negative case, and boundary case all produce the stated result.

Knowledge check

Can you point to the exact part of the solution that makes each false test case fail? If two different failures depend on the same condition, explain why.

Key takeaway

You can read a map().all() chain and handle an empty list deliberately.

Sources

  • CEL-DEV — official CEL overview.
  • CEL-LANG — official CEL language definition for operators, types, macros, presence, strings, and time values used in this challenge.