# avuvos/cp-stress-tester architecture

> Architecture diagram of the GitHub repository avuvos/cp-stress-tester, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/avuvos/cp-stress-tester
- Repository: https://github.com/avuvos/cp-stress-tester

## Overview

##### Project type and purpose
- This is a command-line stress-testing tool for competitive programming solutions.
- Purpose: generate random testcases, run both a brute-force (guaranteed correct but slow) solution and an “optimal” solution under test, and highlight mismatches.

##### File structure
- Top-level files:
- brute_sol.cpp – the brute-force C++ solution source
- optimal_sol.cpp – the “optimal” (possibly incorrect) C++ solution source
- testcase_generator.py – Python script with a function to produce one test case
- mapper.sh – shell script that orchestrates generation, compilation, execution, and comparison over N testcases
- README.md, .gitignore
- No separate frontend/backend folders—this is a single-purpose CLI pipeline.
- Key patterns: generator → compiler → runner → comparator.

##### README for additional insights
- README clarifies the workflow:
a. You fill in the generator to define how testcases are built.
b. You compile and plug in two solutions.
c. You invoke mapper.sh with a parameter (e.g., 20) to run that many tests in sequence.
- No other external services or databases.

##### Main components
a. Testcase Generator (Python)
b. Brute-Force Solution (compiled binary from brute_sol.cpp)
c. Optimal Solution (compiled binary from optimal_sol.cpp)
d. Mapper/Orchestration Script (mapper.sh)
e. Comparator & Logger (internal to mapper.sh or a helper function)
f. CLI/User Interface

##### Relationships and data flow
- CLI invokes mapper.sh with parameter N.
- mapper.sh loops from 1 to N:
1. Calls testcase_generator.py → STDOUT sends one test input
2. Pipes the input to both compiled binaries in parallel or sequentially → captures two outputs
3. Passes the two outputs to a compare routine
4. If they differ, logs the test input, both outputs, and stops or continues
5. Reports summary at the end

##### Architectural patterns and design principles
- Pipeline pattern: a linear sequence of processing stages
- Separation of concerns:
- Generation (Python)
- Execution (binaries)
- Comparison & reporting (shell logic)

##### Relevant technologies
- Python 3 for testcase_generator.py
- Bash for mapper.sh
- C++14 (or C++17) for brute_sol.cpp and optimal_sol.cpp
- Standard I/O and exit codes for communication

## Diagram (Mermaid)

```mermaid
flowchart TD
    CLI["CLI Orchestrator\n(mapper.sh)"]:::script
    Gen["Testcase Generator\n(testcase_generator.py)"]:::script

    subgraph "Solution Executors"
        Brute["Brute-Force Solver\n(brute_sol)"]:::binary
        Optimal["Optimal Solver\n(optimal_sol)"]:::binary
    end

    Comparator["Comparator & Logger"]:::comparator

    CLI -->|"invoke N tests"| Gen
    Gen -->|"stdin"| Brute
    Gen -->|"stdin"| Optimal
    Brute -->|"stdout"| Comparator
    Optimal -->|"stdout"| Comparator
    Comparator -->|"log/mismatch report"| CLI

    click Gen "https://github.com/avuvos/cp-stress-tester/blob/main/testcase_generator.py"
    click Brute "https://github.com/avuvos/cp-stress-tester/blob/main/brute_sol.cpp"
    click Optimal "https://github.com/avuvos/cp-stress-tester/blob/main/optimal_sol.cpp"
    click CLI "https://github.com/avuvos/cp-stress-tester/blob/main/mapper.sh"
    click Comparator "https://github.com/avuvos/cp-stress-tester/blob/main/mapper.sh"

    classDef script fill:#D6EAF8,stroke:#21618C,stroke-width:2px
    classDef binary fill:#D5F5E3,stroke:#196F3D,stroke-width:2px
    classDef comparator fill:#FCF3CF,stroke:#B9770E,stroke-width:2px
```
