https://github.com/himkt/ac-random-test
https://github.com/himkt/ac-random-test
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/himkt/ac-random-test
- Owner: himkt
- License: mit
- Created: 2024-04-29T01:53:24.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-03T03:01:58.000Z (over 1 year ago)
- Last Synced: 2025-01-13T05:09:02.641Z (over 1 year ago)
- Language: Rust
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## AC Random Test
CLI to run a program with randomly generated inputs (a.k.a. stress test), designed for programming contest (like AtCoder).
### Install
Use homebrew.
```
brew tap himkt/tap
brew install himkt/tap/ac-random-test
```
You can also download a binary from [GitHub Release](https://github.com/himkt/ac-random-test/releases).
### Basic usage
#### 1. Generating input randomly
`ac-random-test` assumes `gen.py` (executable) exists on the current directory.
`gen.py` should be executable like following:
##### `file gen.py`
```bash
gen.py: Python script text executable, ASCII text
```
> [!IMPORTANT]
> Make sure `gen.py` is executable.
##### `cat gen.py`
```python
#!/usr/bin/python3
import random
n = random.randint(1, 5)
a = [str(random.randint(0, 10)) for _ in range(n)]
with open("in.txt", "w") as f:
print(n, file=f)
print(" ".join(a), file=f)
```
> [!IMPORTANT]
> Don't forget to provide a shebang.
#### 2. Running a program
`ac-random-test` runs `./a.out` if you provide `a.out` and `./{argv0}` as `--run-cmd`.
`{argv0}` will be replaced with a name you give as a name (in this example, `a.out`).
`ac-random-test` also runs `./a.out_lazy` and check results are the same, in other words,
you need to prepare two programs: one is a submission program and the another is a
slow-but-correct program.
```bash
ac-random-test a.out --run-cmd './{argv0}'
```
If you want to run `ac-random-test` without a lazy program, specify `--without-lazy`.
```bash
ac-random-test a.out \
--run-cmd './{argv0}' \
--without-lazy
```
You may want to run a program written in other languages. No worries, please specify `--run-lazy-cmd`!
```bash
ac-random-test a.out \
--run-cmd './{argv0}' \
--run-lazy-cmd 'python3 slow_ac_code.py'
```
### 3. Setting time limit
In programing contest, your program must finish to run in a given time limit.
To find an input that makes your program slow, you can specify `--max-ms` to limit an execution time.
For example, if you provide `--max-ms 50`, `ac-random-test` fails if your program don't finished within 50ms.
```bash
ac-random-test a.out \
--run-cmd './{argv0}' \
--max-ms 50
```
Of course, `--max-ms` works with `--without-lazy`!
```bash
ac-random-test a.out \
--run-cmd './{argv0}' \
--max-ms 50 \
--without-lazy
```
### 4. Using custom input generating scripts
`ac-random-test` assumes `gen.py` is created in the current directory by default.
You can use a custom script by specifying `--gen-input-cmd`.
```bash
ac-random-test a.out \
--run-cmd './{argv0}' \
--gen-input-cmd "python3 $HOME/Desktop/gen.py"
```