#competitive-programming #testing #programming-language #test-cases #testing-tools #analysis #coding

bin+lib cpast

Run custom testcase with powerful clex lang powered generated tool. Ideal for competitive coders. Can test two file and pass & match randomly generated outputs

11 releases

0.4.0 Jan 30, 2024
0.3.4 Jan 24, 2024
0.2.9 Nov 11, 2023

#391 in Development tools

Download history 24/week @ 2024-02-25 2/week @ 2024-03-10 121/week @ 2024-03-31

180 downloads per month

GPL-3.0-or-later

86KB
1.5K SLoC

Contains (ELF exe/lib, 33KB) examples/artifacts/my_approach, (ELF exe/lib, 17KB) examples/artifacts/correct_approach

cpast - Code Testing and Analysis Tool

Crates.io Crates.io GitHub repo size Crates.io docs.rs GitHub Workflow Status (with event)

cpast is a versatile code testing and analysis tool that allows you to test correct and incorrect code files against a custom language generator called clex. It supports a variety of programming languages, including Python, C++, C, Rust, Ruby, JavaScript, and Java. You can specify the number of iterations and test your code against random input values, comparing the output against expected results.

Introduction

cpast - Code Testing and Analysis Tool is your solution to a crucial problem faced by competitive programmers (CP) and coding enthusiasts. It empowers you to streamline your coding journey and overcome common challenges in competitive programming and coding practice. Checkout the blog post here

Addressing a Crucial Problem in Competitive Programming (C.P.)

Competitive programming, often referred to as C.P., involves solving algorithmic and coding challenges within strict time limits. Participants in coding contests, such as ACM ICPC, Codeforces, and LeetCode, often face challenges like:

  • Verifying code correctness against various test cases.
  • Efficiently testing code under time constraints.
  • Debugging errors quickly to improve code performance.

cpast has been designed to tackle these challenges head-on and make the competitive programming experience more efficient and enjoyable.

How cpast Solves the Problem

1. Testing Correctness

cpast enables you to test your code with both correct and incorrect code files, ensuring that your solutions work as expected while also helping you identify and fix issues in your code.

2. Rapid Testing

In competitive programming, time is of the essence. cpast allows you to define custom test cases and automate testing, saving valuable time that would otherwise be spent manually verifying code correctness.

3. Debugging Support

With cpast, you can quickly identify and debug issues in your code by comparing actual output with expected results. This helps you fine-tune your code for optimal performance.

By addressing these crucial problems, cpast enhances your competitive programming experience, making it more efficient and effective, ultimately improving your coding skills and competition performance. Say goodbye to manual testing and debugging, and let cpast handle the heavy lifting for you.

Table of Contents

Usecases

  1. Debugging your CP/DSA questions.
  2. Live hacking in during/post Codeforces contests.
  3. Generate testcases for your problem setters.

Features

  • Test correct and incorrect code files.
  • Set the number of iterations to run your tests.
  • Support for multiple programming languages.
  • What's new?

Getting Started

https://github.com/rootCircle/cpast/assets/35325046/1229ce29-f142-4e7a-9008-10b280fb57b6

Installation

To get started with cpast, you need to install it. You can do this by running the following command:

cargo install cpast
Note for Windows users
On windows, to install cargo, run these commands in terminal (for faster and lighter setup)
winget install rustup
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
Note for Linux users
On Linux, you'll need to have xorg-dev and libxcb-composite0-dev to compile. On Debian and Ubuntu you can install them with
sudo apt install xorg-dev libxcb-composite0-dev

Required for clipboard support,

Chances are that clipboard support might be broken for some WMs like bspwm, but other features will work just fine!

Note for users not running windows, linux or macos; basically android users etc

Default compilations won't be supported due to lack of clipboard API support in those systems, and hence you need to compile it with --no-default-features feature

cargo install cpast --no-default-features

Usage

Here's a simple example of how to use cpast:

test

cpast test -c correct.cpp -t incorrect.cpp -g "(N) (?:N){\1}" --iterations 100
  • correct.cpp should contain the correct code.
  • incorrect.cpp should contain the incorrect code.
  • (N) (?:N){\1} is the language generator.
  • 100 is the number of test iterations.

generate

cpast generate "S[10,'U']"
  • Generates string of length 10, of uppercase characters only

Language Specification

The clex language generator is based on a custom grammar specification. It allows you to define input patterns for testing. For more information on the clex language and its usage, please refer to the Grammar Rules for Clex Generator.

Roadmap

  • Support for Capturing Group inside Non-capturing group
  • Support strong strings checks like all lowercase, uppercase, alphabets, numbers, alphanumeric
  • Allow only one time compilations in future
  • Support for lazy evaluations of group values.
  • Add docs about clex usage. For now try inferring from CLEX_LANGUAGE.md file.
  • Floating Limit support in Range Bounds for Numeral Data Type for Float
  • Support Back-references in Range Bounds as well.

Now you are ready to use cpast for testing your code against various programming languages and input patterns defined by the clex language. Happy testing!

Alternatives

Dependencies

~7–20MB
~275K SLoC