PC01-L01 · guided challenge

Order ready for approval

Translate four order requirements into one boolean expression.

Practical CEL4 test casesDocumented
What will I practise?

You can separate activity, a non-empty list, and two item-level requirements.

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

An order may enter approval only when it is active, contains at least one item, every item has a positive price, and at least one item costs 100 or more.

Exact requirements

  1. The order is active.
  2. The item list is not empty.
  3. Every price is greater than 0.
  4. At least one price is 100 or greater.

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: You need size(), all(), and exists(). Every part must return bool.

Tip: press Ctrl/⌘ + Enter to run all tests.
Valid orderNot run yet
Expected: true · bool
Show JSON input
{
  "order": {
    "active": true,
    "items": [
      {
        "price": 25
      },
      {
        "price": 120
      }
    ]
  }
}
Inactive orderNot run yet
Expected: false · bool
Show JSON input
{
  "order": {
    "active": false,
    "items": [
      {
        "price": 120
      }
    ]
  }
}
Empty listNot run yet
Expected: false · bool
Show JSON input
{
  "order": {
    "active": true,
    "items": []
  }
}
Invalid priceNot run yet
Expected: false · bool
Show JSON input
{
  "order": {
    "active": true,
    "items": [
      {
        "price": 0
      },
      {
        "price": 120
      }
    ]
  }
}
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
order.active && order.items.size() > 0 && order.items.all(item, item.price > 0.0) && order.items.exists(item, item.price >= 100.0)

Why the solution works

  1. order.active checks the order-level state.
  2. size() > 0 gives the empty list an explicit false result.
  3. all() rejects the complete order when any price is zero or negative.
  4. exists() proves that at least one item reaches the high-value threshold.

What the test cases prove

  • Valid order: expected true (bool).
  • Inactive order: expected false (bool).
  • Empty list: expected false (bool).
  • Invalid price: 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 separate activity, a non-empty list, and two item-level requirements.

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.