#competitive-programming #generator #framework #cp #test-cases #test-framework #test-data

ezcp

A simple tool to automatically generate test cases for competitive programming problems

7 releases

0.3.0 Mar 11, 2024
0.2.2 Mar 11, 2024
0.2.1 Jan 6, 2024
0.1.2 Jan 1, 2024
0.1.0 Dec 29, 2023

#422 in Development tools

Download history 45/week @ 2023-12-30 3/week @ 2024-01-06 2/week @ 2024-02-17 251/week @ 2024-03-09 39/week @ 2024-03-16 2/week @ 2024-03-23 20/week @ 2024-03-30 7/week @ 2024-04-06

80 downloads per month

Custom license

120KB
3K SLoC

EZCP

A Rust framework to easily create tasks for competitive programming.

Features:

  • Generate test inputs and save them into files.
  • Generate correct outputs.
  • Optionally have a test input checker.
  • [TODO] Make a solution checker if there are multiple valid solutions.
  • Subtask dependencies.
  • Graph generator.
  • Array generator.
  • [TODO] Automatically generate some parts of the statement (time/memory limit, subtasks, samples...) and save it to latex.
  • Add a partial solution and specify which subtasks it should pass.
  • Automatically archive all test files into a zip.

Suggestions and bug reports: jakob@zorz.si You can also open a pull request.

Minimal example: (see examples/ for more complete examples)

use rand::Rng;
use std::path::PathBuf;

fn main() {
    // For the first task you get an array of even integers. 
    // You need to find the sum of all elements in the array minus the half of the maximum element.

    let mut task = ezcp::Task::new("Coupon", &PathBuf::from("coupon"));

    // Constraint: n = 1
    let mut subtask1 = ezcp::Subtask::new(20);
    
    // Add 5 tests, where an array is generated with length 1 and an even value between 0 and 1_000_000_000 (inclusive).
    subtask1.add_test(5, ezcp::array_generator_custom(1, 1, |rng| rng.gen_range(0..=500_000_000) * 2));
    

    // No additional constraints.
    let mut subtask2 = ezcp::Subtask::new(50);

    // Add some random tests.
    subtask2.add_test(5, ezcp::array_generator_custom(1, 200_000, |rng| rng.gen_range(0..=500_000_000) * 2));

    // Add 5 edge cases, where n is maximal.
    subtask2.add_test(5, ezcp::array_generator_custom(200_000, 200_000, |rng| rng.gen_range(0..=500_000_000) * 2));

    // Add subtasks to the task.
    let subtask1 = task.add_subtask(subtask1);
    let subtask2 = task.add_subtask(subtask2);

    // Add dependencies (dependencies are only if constraints of a dependency are a subset of constraints of a subtask).
    task.add_subtask_dependency(subtask2, subtask1);
    
    // Finally, create the tests.
    task.create_tests();
}

And coupon/solution.cpp:

#include<iostream>
using namespace std;

int main(){
    int n;
    cin>>n;
    long long sum=0;
    int big=0;
    while(n--){
        int a;
        cin>>a;
        big=max(big,a);
        sum+=a;
    }
    cout<<sum-big/2<<"\n";
}

Dependencies

~4.5–6.5MB
~128K SLoC