Skip to main content

porunga

https://secure.travis-ci.org/lukaszb/porunga.png?branch=master

porunga is a tool for algorithms testing.

Installation

In order to install porunga simply run:

pip install porunga

Usage

Basically we need specific files structure to test our algorithms:

./foobar/
./foobar/foobar.py
./foobar/testdata/
./foobar/testdata/test01.in
./foobar/testdata/test01.out
./foobar/testdata/test02.in
./foobar/testdata/test02.out
./foobar/testdata/test03.in
./foobar/testdata/test03.out

Here, foobar is our problem name - it should be same for parent the directory and coded solution (here we have foobar.py but it can be other language - see supported languages below; i.e. for Java we would create foobar.java file)

At ./foobar/ directory we would run:

$ porunga test --lang python

See help for more options (you can see supported languages there too):

$ porunga test -h

If we want to set time constraints for tests we can use --timeout switch. In example, if we need tests to run below 2.5 seconds we can run:

$ porunga test --timeout 2.5

Please note that very low timeout value is not supported. Moreover,

Supported languages

Currently porunga supports following languages:

Java

Java source file should be named same as parent directory and should contain public class with same name. So if our problem is called foobar we would create foobar.java file with foobar named public class.

Tutorial

Let’s say we have a following problem to solve:

Problem

At input we get two integers: n, m, where 1 <= n < m <= 100000. Your program should write to output all Fibonacci numbers between n and m (including both). Numbers at output should be space separated.

Examples:

INPUT  1: 3 5
OUTPUT 1: 2 3 5

INPUT  2: 6 10
OUTPUT 2: 8 13 21 34 55

Firstly, let’s make a directory for our solution:

$ mkdir fibs
$ cd fibs

Let’s also create a testdata directory (exact name should be used) and put there some test cases:

$ mkdir testdata
$ echo '3 5' > testdata/test01.in
$ echo '2 3 5' > testdata/test01.out
$ echo '6 10' > testdata/test02.in
$ echo '8 13 21 34 55' > testdata/test02.out

Note that test inputs and outputs should have .in and .out extensions respectively.

Now let’s create our solution - we can pick any of the supported languages but for sake of this tutorial let it be Python module. Create one (empty for now):

$ touch fibs.py

We should have following files created by now:

./fibs/
./fibs/fibs.py
./fibs/testdata/
./fibs/testdata/test01.in
./fibs/testdata/test01.out
./fibs/testdata/test02.in
./fibs/testdata/test02.out

That’s it. We can now run porunga inside fibs directory and see our solution being tested against created test cases:

$ porunga test
Testing ./fibs
==============

=> Binary: python /Users/lukasz/temp/fibs/fibs.py

=> Testing ./fibs/testdata/test01.in ... Fail
=> Testing ./fibs/testdata/test02.in ... Fail

=> Total time: 0.058s
=> 2 out of 2 tests failed

Well, we get 2 tests failed but we haven’t actually coded anything yet. Just put following code into fibs.py:

import fileinput
import re
import sys


def fib(n):
    if n in (1, 2):
        return 1
    a = b = 1
    for x in range(3, n + 1):
        a, b = b, a + b
    return b

def main():
    fin = fileinput.input()
    n, m = map(int, re.findall(r'\d+', fin.readline()))
    fibs = [str(fib(num)) for num in range(n, m + 1)]
    result = ' '.join(fibs)
    sys.stdout.write(result)


if __name__ == '__main__':
    main()

(this is not optimal code as we compute Fibonacci numbers each time but it can be easily upgraded)

Let’s run tests again:

$ porunga test
Testing ./fibs
==============

=> Binary: python ./fibs/fibs.py

=> Testing ./fibs/testdata/test01.in ... OK [0.030]s
=> Testing ./fibs/testdata/test02.in ... OK [0.033]s

=> Total time: 0.063s
=> All 2 tests passed

Metadata

Release files for porunga 0.9.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for porunga 0.9.3
File Size Uploaded Provenance Actions
porunga-0.9.3.tar.gz 13.6 kB Without provenance Details for porunga-0.9.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for porunga 0.9.3
File Interpreter ABI Platform Actions
porunga-0.9.3-py27-none-any.whl Python 2.7 none any Details for porunga-0.9.3-py27-none-any.whl

Total release size: 33.8 kB

Release files / porunga-0.9.3.tar.gz

Download URL porunga-0.9.3.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
669b3b0a289f309b8740877f7d7faec315ac2e4f39dfef99d9bb567fd7e515c6
BLAKE2b-256 checksum
How to use checksums
bf3bc9326823e75afc8952f09df97c85c0975b9de5759498a335adf00a671568
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / porunga-0.9.3-py27-none-any.whl

Download URL porunga-0.9.3-py27-none-any.whl
Size 20.1 kB
Tags Python 2.7
SHA-256 checksum
How to use checksums
cbcea7deae9f1302cf02b94c0a5f609107bf0bfe56ebd5980873bd51b389b6ad
BLAKE2b-256 checksum
How to use checksums
ab8e4228cc310649c2f238ce0ece5d90712b1e3b232ca5b4ba1e62aff11ce850
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for porunga 0.9.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page