> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mangrovesystems.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Module 5 Exercise: End-to-End Integration Testing

> Create a comprehensive January 2024 test dataset, run the full pipeline, validate every output against expected values, and document any issues.

<Panel>
  <Card title="Accounting Academy" className="accounting-academy-card">
    <div className="accounting-academy-content">
      <Steps className="my-0">
        <Step title="MODULE 1: Fundamentals" icon="bookmark" iconType="solid" stepNumber={1} titleSize="p">
          * [1.1: Core Concepts & the Data Lifecycle](/accounting-academy/module-1/1-1-core-concepts-data-lifecycle)
          * [1.2: Translating Methodologies to Mangrove](/accounting-academy/module-1/1-2-translating-methodologies-to-mangrove)
          * [1.3: Events and Datapoints](/accounting-academy/module-1/1-3-events-and-datapoints)
          * [Exercise: Design and Build](/accounting-academy/module-1/1-exercise-design-and-build)
        </Step>

        <Step title="MODULE 2: Calculations" icon="bookmark" iconType="solid" stepNumber={2} titleSize="p">
          * [2.1: Calculation Architecture](/accounting-academy/module-2/2-1-calculation-architecture)
          * [2.2: Expanding Your Data Model](/accounting-academy/module-2/2-2-expanding-your-data-model)
          * [Exercise: Multi-Step Calculations](/accounting-academy/module-2/2-exercise-multi-step-calculations)
        </Step>

        <Step title="MODULE 3: Batch Partitioning & LCA" icon="bookmark" iconType="solid" stepNumber={3} titleSize="p">
          * [3.1: What Is a Batch?](/accounting-academy/module-3/3-1-what-is-a-batch)
          * [3.2: Batch Partitioning Strategies](/accounting-academy/module-3/3-2-batch-partitioning)
          * [3.3: Life Cycle Assessment & Emissions](/accounting-academy/module-3/3-3-lca-and-emissions)
          * [3.4: Allocating Emissions to Batches](/accounting-academy/module-3/3-4-allocating-emissions-to-batches)
          * [Exercise: Batch Partitioning & LCA](/accounting-academy/module-3/3-exercise-batch-partitioning-and-lca)
        </Step>

        <Step title="MODULE 4: Mass Balance with Ledgers" icon="bookmark" iconType="solid" stepNumber={4} titleSize="p">
          * [4.1: Introduction to Mass Balance](/accounting-academy/module-4/4-1-intro-to-mass-balance)
          * [4.2: Designing the Ledger Structure](/accounting-academy/module-4/4-2-designing-the-ledger-structure)
          * [4.3: Multiple Batch Types for Different Stages](/accounting-academy/module-4/4-3-multiple-batch-types)
          * [Exercise: Design & Build Mass Balance](/accounting-academy/module-4/4-exercise-design-and-build-mass-balance)
        </Step>

        <Step title="MODULE 5: Integration Testing" icon="bookmark" iconType="solid" stepNumber={5} titleSize="p">
          * [5.1: The Complete Model Assembly](/accounting-academy/module-5/5-1-the-complete-model-assembly)
          * [5.2: Testing Patterns](/accounting-academy/module-5/5-2-testing-patterns)
          * [5.3: Common Integration Pitfalls](/accounting-academy/module-5/5-3-common-integration-pitfalls)
          * [Exercise: Integration Testing](/accounting-academy/module-5/5-exercise-integration-testing)
        </Step>

        <Step title="MODULE 6: Advanced Patterns & Production" icon="bookmark" iconType="solid" stepNumber={6} titleSize="p">
          * [6.1: Model Design Best Practices](/accounting-academy/module-6/6-1-model-design-best-practices)
          * [6.2: Advanced Techniques](/accounting-academy/module-6/6-2-advanced-techniques)
          * [6.3: Production Readiness](/accounting-academy/module-6/6-3-production-readiness)
          * [Exercise: Production Deployment](/accounting-academy/module-6/6-exercise-production-deployment)
        </Step>
      </Steps>
    </div>
  </Card>
</Panel>

<Check>
  **What you'll build in this exercise:**

  * Create a comprehensive test dataset representing one month of Mangrove Biochar operations
  * Run the full calculation pipeline and validate every batch output
  * Verify all ledger balances reconcile
  * Document and fix any integration issues discovered during testing
</Check>

This is the most comprehensive exercise in the course. You'll load a full month of realistic test data, run the complete pipeline, and systematically validate every output. Think of this as a **dress rehearsal for production**.

```mermaid theme={null}
flowchart LR
    DATA["January 2024<br/>Test Dataset<br/>(17 events)"] --> PIPELINE["Full<br/>Pipeline"]
    PIPELINE --> VALIDATE["Validate<br/>Outputs"]
    VALIDATE --> RECONCILE["Reconcile<br/>Ledgers"]
    RECONCILE --> DOCUMENT["Document<br/>Results"]

    style DATA fill:#42a5f5,stroke:#1976d2,stroke-width:2px,color:#000
    style PIPELINE fill:#66bb6a,stroke:#388e3c,stroke-width:2px,color:#000
    style VALIDATE fill:#ffa726,stroke:#f57c00,stroke-width:2px,color:#000
    style RECONCILE fill:#ab47bc,stroke:#7b1fa2,stroke-width:2px,color:#000
    style DOCUMENT fill:#78909c,stroke:#455a64,stroke-width:2px,color:#000
```

**Prerequisites:** Complete [Lesson 5.1](/accounting-academy/module-5/5-1-the-complete-model-assembly), [Lesson 5.2](/accounting-academy/module-5/5-2-testing-patterns), and [Lesson 5.3](/accounting-academy/module-5/5-3-common-integration-pitfalls). Your project should have all event types, models, batch partitioning, and LCA calculations from Modules 1-4.

***

## Part 1: Design (30 min)

### 1. Define test scenarios

Plan your test dataset to cover all three scenario types:

<CardGroup cols={3}>
  <Card icon="circle-check" title="Happy Path">
    Normal operations:

    * 4 typical deliveries (2-6 t)
    * 5 feedstock receipts
    * 3 lab analyses
    * Standard moisture (10-20%)
    * Typical H:C ratio (0.2-0.5)
  </Card>

  <Card icon="triangle-exclamation" title="Edge Cases">
    Boundary values:

    * 1 high-moisture receipt (50%)
    * 1 high H:C ratio analysis (0.75)
    * 1 very small delivery (0.5 t)
    * 1 zero-distance transport
  </Card>

  <Card icon="circle-xmark" title="Error Cases">
    Invalid data:

    * Missing a required datapoint
    * Event outside accounting period
    * Duplicate tracking IDs
  </Card>
</CardGroup>

### 2. Calculate expected outputs

Before running the pipeline, calculate the expected output for every batch in a spreadsheet. Include:

* Gross carbon for each delivery
* Proportional emission allocation (by mass)
* Direct transport emissions per delivery
* Net carbon per batch
* Ledger totals and balances

### 3. Identify potential failure points

List what might go wrong:

* Slug mismatches between new event types and model nodes
* Date range issues with edge case events
* Allocation denominators including edge case batches
* Missing aggregation for energy consumption events

***

## Part 2: Build in Mangrove (1.5 hrs)

### Step 1: Create the January 2024 test dataset

Create the following events using <a href="/data-collection/add-data" target="_blank" rel="noopener noreferrer">Add Data</a>

or <a href="/data-collection/bulk-import" target="_blank" rel="noopener noreferrer">Bulk Import</a>

:

**5 Feedstock Receipt events:**

| Receipt | Date   | Wet Mass (t) | Moisture % | Feedstock Type                   |
| ------- | ------ | ------------ | ---------- | -------------------------------- |
| FR-001  | Jan 2  | 12           | 15         | Agricultural waste               |
| FR-002  | Jan 8  | 10           | 12         | Forestry residue                 |
| FR-003  | Jan 14 | 15           | 18         | Agricultural waste               |
| FR-004  | Jan 20 | 8            | **50**     | Agricultural waste *(edge case)* |
| FR-005  | Jan 27 | 11           | 14         | Forestry residue                 |

**3 Lab Analysis events:**

| Analysis | Date   | Carbon % | H:C Ratio | Ash %                     |
| -------- | ------ | -------- | --------- | ------------------------- |
| LA-001   | Jan 5  | 80       | 0.35      | 8                         |
| LA-002   | Jan 15 | 78       | 0.42      | 10                        |
| LA-003   | Jan 25 | 82       | **0.75**  | 6 *(edge case: high H:C)* |

**4 Biochar Delivery events:**

| Delivery | Date   | Mass (t) | Carbon %                     |
| -------- | ------ | -------- | ---------------------------- |
| DEL-001  | Jan 7  | 5        | 80                           |
| DEL-002  | Jan 14 | 3        | 78                           |
| DEL-003  | Jan 21 | 4        | 82                           |
| DEL-004  | Jan 28 | **0.5**  | 79 *(edge case: very small)* |

**1 Energy Consumption event (January):**

* Electricity: 12,000 kWh
* Propane: 600 gallons
* Period: Jan 1 – Jan 31

**4 Transportation events:**

| Delivery | Distance (km) | Fuel Type                  |
| -------- | ------------- | -------------------------- |
| DEL-001  | 180           | Diesel                     |
| DEL-002  | 150           | Diesel                     |
| DEL-003  | **0**         | n/a *(edge case: on-site)* |
| DEL-004  | 200           | Diesel                     |

<Tip>
  Use <a href="/data-collection/bulk-import" target="_blank" rel="noopener noreferrer">bulk import</a>

  for faster data entry when creating many events. Prepare a CSV with all required columns matching your event type slugs.
</Tip>

### Step 2: Run the full pipeline

1. Go to **Production Accounting** and <a href="/production-accounting/generate-batches" target="_blank" rel="noopener noreferrer">generate batches</a>

   for January 2024.
2. Resolve any **validation messages** — these indicate missing or problematic data.
3. **Submit** to generate batches.

<Warning>
  If you see validation errors, don't skip them — they're the first sign of integration issues. Check the pitfalls from Lesson 5.3 to diagnose the root cause.
</Warning>

### Step 3: Validate batch outputs

For each of the 4 delivery batches, compare the pipeline output against your expected values:

<Steps>
  <Step title="Check gross carbon">
    Does the gross tCO2e for each batch match your spreadsheet? If not, check the production model nodes (dry mass → carbon → CO2 conversion).
  </Step>

  <Step title="Check emission allocation">
    Are electricity and propane emissions allocated proportionally by mass? Do the allocations across all batches sum to the total period emissions?
  </Step>

  <Step title="Check transport emissions">
    Is DEL-003's transport emission zero (on-site delivery)? Are other deliveries' transport emissions correct?
  </Step>

  <Step title="Check net carbon">
    Does net = gross - (allocated electricity + allocated propane + transport) for each batch?
  </Step>

  <Step title="Check edge case batches">
    DEL-004 (0.5 t): Is the net carbon very small or potentially negative? If negative, flag this — the methodology may require a minimum batch size or different handling.
  </Step>
</Steps>

### Step 4: Verify ledger reconciliation

Check each ledger's balance:

| Ledger              | Credits (In)                | Debits (Out)            | Balance       |
| ------------------- | --------------------------- | ----------------------- | ------------- |
| Feedstock Inventory | Sum of dry feedstock masses | Allocated to production | Should be ≥ 0 |
| Biochar Production  | Sum of biochar produced     | Allocated to delivery   | Should be ≥ 0 |
| Carbon Delivered    | Sum of net tCO2e            | Allocated to reports    | Running total |

<Note>
  If a ledger balance goes negative, it means you're claiming more output than input at that stage — a mass balance violation that must be resolved before reporting.
</Note>

### Step 5: Document and fix issues

For every issue found:

1. **Describe the symptom** — what output was wrong?
2. **Identify the root cause** — which pitfall from Lesson 5.3?
3. **Apply the fix** — update the configuration
4. **Re-run and verify** — confirm the fix resolves the issue

***

## Success criteria

You have completed the Module 5 exercise when:

* **Test dataset created** — 17 events across 5 event types covering happy path and edge cases
* **Pipeline executed** — Generate Batches runs for January 2024 without unresolved validation errors
* **4 batches generated** — one per delivery, with correct gross and net carbon values
* **Batch outputs match** — all values within 1% of your pre-calculated expected outputs
* **Emissions correctly allocated** — proportional allocations sum to period totals, direct allocations are batch-specific
* **Ledger balances reconcile** — no negative balances, inputs ≥ outputs at each stage
* **Edge cases handled** — high moisture, high H:C, small delivery, and zero-distance transport produce correct results
* **Issues documented** — any problems found during testing are documented with root cause and fix

***

## What's next

Your Mangrove Biochar project now passes comprehensive testing. In [Module 6: Advanced Patterns & Production](/accounting-academy/module-6/6-1-model-design-best-practices) you'll learn best practices for model design, advanced techniques, and how to prepare your project for production deployment.
