PeaBox Lab › PeaLang › Learn › Chapter 3 › Lesson 5

Part I — Foundations · Chapter 3 · Lesson 5 of 5 · 8 min read

Chapter 3 Checkpoint: Validation and Scoring Engine

Checkpoint level: Foundation

Purpose: Integrate boolean decisions, while and for loops, ranges, collection iteration, break, continue, nesting, invariants, and defensive termination in one bounded rules program.

Checkpoint outcomes

By completing this checkpoint, you will demonstrate that you can:

Project scenario

A service team needs a command-line engine that validates support-case records, assigns each valid case a numeric score, converts the score into a priority, and stops early if it encounters a critical security case. The foundation version uses a source-defined list of string-keyed maps.

3C.1 Required record fields

FieldMeaningValid values
idReadable case identifierNonempty string
impactService-impact scoreInteger from 0 through 10
affected_usersNumber of affected usersNonnegative integer
customer_tierService tierstandard, gold, or platinum
security_relevantSecurity significanceBoolean

3C.2 Validation rules

3C.3 Scoring policy

Start each valid record at zero and add:

Keep the components named while calculating so a reader can explain the final score.

3C.4 Priority classification

A valid security-relevant record with score at or above 120 is a critical security case. Record its identifier and stop processing after its result has been counted and reported.

3C.5 Defensive limits

3C.6 Required program state

Declare and maintain these summary values:

3C.7 Required control-flow design

3C.8 Loop invariants

State and verify these invariants:

3C.9 Completion codes

CodeMeaning
COMPLETEAll available records were processed within the limit.
CRITICAL_FOUNDA critical security case was counted and caused early exit.
LIMIT_EXHAUSTEDThe record budget stopped processing before collection exhaustion.

3C.10 Reference implementation outline

Attempt the checkpoint independently before using this outline.

const max_records = 10
const user_threshold = 100
const critical_threshold = 120
const high_threshold = 80
const medium_threshold = 40
let inspected_count = 0
let valid_count = 0
let invalid_count = 0
let total_score = 0
let low_count = 0
let medium_count = 0
let high_count = 0
let critical_count = 0
let critical_case_id = null
let limit_exhausted = false
let completion_code = "COMPLETE"
for case in cases {
    if inspected_count >= max_records {
        limit_exhausted = true
        completion_code = "LIMIT_EXHAUSTED"
        break
    }
    inspected_count += 1
    let valid = true
    if case.id == "" { valid = false }
    if case.impact < 0 or case.impact > 10 { valid = false }
    if case.affected_users < 0 { valid = false }
    let approved_tier = case.customer_tier == "standard" or case.customer_tier == "gold" or case.customer_tier == "platinum"
    if not approved_tier { valid = false }
    if not valid {
        invalid_count += 1
        print "Case {case.id}: INVALID_RECORD"
        continue
    }
    let impact_points = case.impact * 10
    let user_points = 0
    if case.affected_users >= user_threshold { user_points = 20 }
    let tier_points = 0
    if case.customer_tier == "gold" { tier_points = 10 } else if case.customer_tier == "platinum" { tier_points = 20 }
    let security_points = 0
    if case.security_relevant { security_points = 50 }
    let score = impact_points + user_points + tier_points + security_points
    let priority = "low"
    if score >= critical_threshold {
        priority = "critical"
        critical_count += 1
    } else if score >= high_threshold {
        priority = "high"
        high_count += 1
    } else if score >= medium_threshold {
        priority = "medium"
        medium_count += 1
    } else {
        priority = "low"
        low_count += 1
    }
    valid_count += 1
    total_score += score
    print "Case {case.id}: score {score}, priority {priority}"
    if priority == "critical" and case.security_relevant {
        critical_case_id = case.id
        completion_code = "CRITICAL_FOUND"
        break
    }
}
print "Completion: {completion_code}"
print "Inspected: {inspected_count}"
print "Valid: {valid_count}"
print "Invalid: {invalid_count}"
print "Total score: {total_score}"
print "Priorities: low={low_count}, medium={medium_count}, high={high_count}, critical={critical_count}"
print "Critical case: {critical_case_id}"

The outline assumes every record has the required keys so field access is safe. For malformed maps with missing keys, validate presence using the supported map operations available in your environment before accessing those fields.

3C.11 Required test matrix

CasePurposeExpected behavior
AOrdinary mixed valid recordsCOMPLETE; all valid records classified
BImpact -1INVALID_RECORD; continue
CImpact 11INVALID_RECORD; continue
DAffected users -1INVALID_RECORD; continue
EUnsupported tierINVALID_RECORD; continue
FScore exactly 40medium
GScore exactly 80high
HScore exactly 120 without securitycritical; processing continues
ICritical security caseCRITICAL_FOUND; counted, then break
JMore records than max_recordsLIMIT_EXHAUSTED
KEmpty collectionCOMPLETE with zero counts

3C.12 Boundary and overlap tests

3C.13 Validation workflow

3C.14 Deliberate defects

Create temporary variants that demonstrate:

For each defect, state the broken invariant, observed output, root cause, correction, and regression test.

3C.15 Acceptance criteria

3C.16 Submission package

3C.17 Assessment rubric

AreaEvidence of mastery
ValidationMalformed and out-of-range records are rejected consistently.
ScoringEvery component, score, and threshold result is correct.
Loop controlContinue and break preserve required state and target the intended loop.
InvariantsAccounting, priority totals, scores, and bounds remain consistent.
TerminationFinite input, record bounds, and completion evidence are explicit.
TestingNormal, invalid, boundary, early-exit, empty, and limit cases are covered.
OutputResults are labeled, deterministic, traceable, and safe.
WorkflowFormatting, checking, execution, diagnosis, and retesting are recorded separately.

Completion standard: Every required test passes, all invariants hold, and the learner can explain each exit mode without guessing.

3C.18 Reflection questions

Chapter 3 summary

You can now design ordered decisions, reason about truthiness and thresholds, build controlled while loops, iterate through ranges and collections, and use break and continue without losing state or termination guarantees. Reliable control flow combines explicit policies, loop invariants, progress measures, boundary tests, completion codes, bounded work, and safe output.

Transition to Chapter 4

Chapter 4 turns repeated logic into structured, reusable programs. The next lesson covers declaring and calling functions, including function syntax, argument evaluation, local scope, return behavior, and small reusable contracts.

Checkpoint status: Approved.

← Previous Next →