Package: porunga
porungais a tool for algorithms testing.InstallationIn order to installporungasimply run:pip install porungaUsageBasically 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.outHere,foobaris our problemname- it should be same for parent the
directory and coded solution (here we havefoobar.pybut it can be other
language - see supported languages below; i.e. for Java we would createfoobar.javafile)At./foobar/directory we would run:$ porunga test --lang pythonSee help for more options (you can see supported languages there too):$ porunga test -hIf we want to set time constraints for tests we can use--timeoutswitch. In
example, if we need tests to run below 2.5 seconds we can run:$ porunga test --timeout 2.5Please note that very low timeout value is not supported. Moreover,Supported languagesCurrentlyporungasupports following languages:CC++Objective CPythonRubyJavaJavaJava source file should be named same as parent directory and should contain
public class with same name. So if our problem is calledfoobarwe would
createfoobar.javafile withfoobarnamed public class.TutorialLet’s say we have a following problem to solve:ProblemAt input we get two integers:n,m, where1 <= n < m <= 100000.
Your program should write to output allFibonacci numbersbetweennandm(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 55Firstly, let’s make a directory for our solution:$ mkdir fibs
$ cd fibsLet’s also create atestdatadirectory (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.outNote that test inputs and outputs should have.inand.outextensions
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.pyWe 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.outThat’s it. We can now runporungainsidefibsdirectory 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 failedWell, we get 2 tests failed but we haven’t actually coded anything yet. Just put
following code intofibs.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