rslc compiler.
A scenario is an RSL file that gives a rater one set of inputs, the values to print, and the values you expect.
rslc eval rates the inputs and compares each expected value with the computed one.
The example is the worked example of Write your first rater.
A $250,000 dwelling in protection class 5, with scheduled items worth $1,200 and $800, has a $1,028 premium.
Save the two files of that rater, or run rslc examples get dwelling.
dwelling/rater.rsl
dwelling/rater.rsl
dwelling/rater.rsl
dwelling/tables/BaseRate.csv
dwelling/tables/BaseRate.csv
dwelling/tables/BaseRate.csv
Write the scenario
Save this file asdwelling/worked-example.rsl, in the same folder as rater.rsl:
dwelling/worked-example.rsl
Scenario section with three parts.
instances gives the inputs, evaluate lists the values to print, and assert states the expected values.
Run the scenario
- The first line gives the result of the whole scenario.
- The
targetsline gives each listed value, sorted by name.exactis the exact decimal, andvalueis the same number as a float. - Each assertion gets one line, in the order of the file. The name after
@is the instance that the assertion starts with.
Name the inputs
Each entry ofinstances creates one record of the rater and gives it a name:
- The entry starts with the record, then a name of your choice:
Dwelling home. input = valuesets one input of that record. Write a number,trueorfalse, a date such as2026-01-01, or an enum member such as@Peril.fire.parent: policyplaces the record inside the instance namedpolicy. Sohomebecomes thedwellingof the policy.- Each
Itemwithparent: policyjoins theitemslist of the policy, in the order of the file. - A record that holds only other records, such as
Policyhere, still needs its entry.
List the values to print
targets names each value as instance.name:
- A target is a calculation or an input of the record.
- A calculation with a key, such as
peril_premium, takes one member in brackets. evaluateis optional. A scenario withinstancesandevaluatealone prints the values, which helps while you build the example.
State the expected values
Each line ofassert is a comparison that must hold:
=compares exact values. So 1028 equals 1028.00, and 1027.5 differs from 1028.- An assertion reads any value of an instance, listed in
targetsor left out of it. - Other comparisons work too, such as
policy.premium > 1000andpolicy.premium in [1000, 1100]. assertis optional.
Read a wrong expectation
This copy of the scenario expects a premium of 1,030:= assertion prints the computed value and the expected value.
A failed comparison of another kind prints FAIL assertion: and the instance name alone.
Count the lines to find the assertion: the third line belongs to the third assertion.
Read an incomplete scenario
This copy leaves outprotection_class:
dwelling/incomplete.rsl
dwelling/incomplete.rsl
dwelling/incomplete.rsl
PROTECTION-CLASS and the message of the rule.
Compute the values that the inputs reach
Add--partial to compute what the given inputs allow:
targetsholds the values that the inputs reach. Here the item charge needs only the items.blockedlists the missing input and each value that waits for it.- An assertion over a blocked value fails.
- With every input present,
--partialprints the same lines as the plain command.
Read the exit code
Add
--json to print one JSON value for a program. Its status is passed, failed or incomplete.
Its targets holds the computed values, and each entry of assertions holds passed, the computed value as left and the expected value as right.
Rules for a scenario file
- Keep the scenario in the folder of the rater it imports. The rater reads its tables from that folder.
- Write one
Scenariosection in a file.rslc evalruns the first one. - Check each input name against the rater.
rslc evalskips a name that the record lacks. - A target or an assertion that names an unknown value stops the run with
E-UNRESOLVEDand the line. rslc checkandrslc fmttake a scenario file.rslc fmtwrites the layout this page shows.rslc exportleaves the scenario out of the bundle.
Related
- Test a rater checks many requests against independent premiums in Python.
- Sample and validate requests generates requests that a rater accepts.
- The command reference lists every option of
rslc eval.