def summarize(name, test=False, space_creator=space_optimized):
    print("---------------------")
    print(f"{name}> summarizing")
    files = list(glob.glob(f"output/{name}/*_results.txt"))
    print(f"{name}> {len(files)} files found")

    failed = 0
    timed_out = 0
    memory_error = 0

    results = []
    for file in files:
        log_file = file.replace("_results.txt", "_log.txt")
        with open(log_file) as f:
            lines = "\n".join(f.readlines())
            if "out of memory" in lines:
                failed += 1
                memory_error += 1
                print(f"{name}> {log_file} out of memory")
                continue

        with open(file) as f:
            lines = f.readlines()
            time_taken = int(lines[3]) / 1000 / 60  # minutes
            if lines[5].startswith("False"):
                print(f"{name}> {file} timed out")
                failed += 1
                timed_out += 1
                continue
            results.append(time_taken)

        if test:
            check(log_file, stop_on_error=True, space_creator=space_creator)

    success_count = len(results)

    print(f"{name}> {success_count} successes")
    if success_count != 0:
        d = DescrStatsW(results)
        print(f"{name}> mean={d.mean}, std_mean={d.std_mean}")
        print(f"{name}> confidence interval", d.tconfint_mean())
    print(
        f"{name}> {failed} failed, {failed / (success_count + failed) * 100}%")
    print(f"{name}> {timed_out} timed out")
    print(f"{name}> {memory_error} memory error")
    print(
        f"{name}> binomial success ci={proportion_confint(success_count, success_count + failed, method='wilson')}"
    )

    frame = frame_of(results, name)
    plt.figure()
    sns.boxplot(data=frame, y="time")
    plt.savefig(f"output/fig{name}.png")

    plt.figure()
    sns.displot(frame["time"])
    plt.ylim(0, 350)
    plt.savefig(f"output/fig{name}-dist.png")

    return results
示例#2
0
        (1, 1, 0),
        (2, 2, 2),
        (3, 2, 1),
        (4, 2, 0),
        (5, 3, 4),
        (20, 5, 5),
        (120, 11, 1),
        (121, 11, 0),
        (122, 12, 22),
        (1234**2, 1234, 0),
        (1234**2 + 1, 1235, 2468),
    ]),

    ('Test na velikih številih (težje)', [
        (123456789**2, 123456789, 0),
        (123456789**2 + 1, 123456790, 246913578),
        (123456789987654321**2, 123456789987654321, 0),
        (123456789987654321**2 + 1, 123456789987654322, 246913579975308642),
    ]),
]

for msg, inputs in tests:
    print(msg + '\n' + '-' * len(msg))
    in_out = []
    for n, m, o in inputs:
        in_out.append(((n,), 
            'Vpiši število kock: Potrebujemo škatlo širine {} v kateri je '
            'prostora še za {} kock\n'.format(m, o)))
    tester.check('kocke_z_luknjo.py', in_out)
    print()
示例#3
0
import tester

in_out = [((), '1 2 3 4 5 6 BUM 8 9 10 11 12 13 BUM 15 16 BUM 18 19 20 BUM 22 23 24 25 26 BUM BUM 29 30 31 32 33 34 BUM 36 BUM 38 39 40 41 BUM 43 44 45 46 BUM 48 BUM 50 51 52 53 54 55 BUM BUM 58 59 60 61 62 BUM 64 65 66 BUM 68 69 BUM BUM BUM BUM BUM BUM BUM BUM BUM BUM 80 81 82 83 BUM 85 86 BUM 88 89 90 BUM 92 93 94 95 96 BUM BUM 99 100')]

tester.check('postevanka_stevila_7.py', in_out)
示例#4
0
import tester

tests = [
    ('Test na manjših številih', [
        (1, 1),
        (2, 3),
        (7, 28),
        (100, 5050),
        (1000, 500500),
        (45367, 1029105028),
    ]),
    ('Test na velikih številih (težje)', [
        (123456, 7620753696),
        (123456789, 7620789436823655),
        (123456789987654321, 7620789497027892162094192888812681),
        (134958734958279867346923409818,
         9106930070769616173978874265286493359236600279547451101471),
    ]),
]

for msg, inputs in tests:
    print(msg + '\n' + '-' * len(msg))
    in_out = []
    for n, m in inputs:
        in_out.append(((n, ), 'Vpiši število: {}\n'.format(m)))
    tester.check('vsote.py', in_out)
    print()
示例#5
0
import tester

in_out = [("beseda", False), ("vsedel", True), ("parmezan", True), ("uspelo", False)]

in_out = [
    (i, "Vnesi besedo: %s\n" % ((i + " najbrž ni pravilna slovenska beseda")*f))
    for i, f in in_out]

tester.check("naloga_a.py", in_out)
import math

inputs = [
    [(1, 2, 2), []],
    [(1, 2, 1), [-1.0]],
    [(1, 2, 0), [0.0, -2.0]],
    [(1, -42, 0), [42.0, 0.0]],
    [(1, 2 * -42, 42**2), [42.0]],
    [(5, 11, 4), [-0.45968757625671514, -1.7403124237432848]],
    [(5, 11, 4), [-0.45968757625671514, -1.7403124237432848]],
]

in_out = []
for input, sol in inputs:
    output = 'Vpiši a: Vpiši b: Vpiši c: '
    if len(sol) == 0:
        output += 'Enačba nima realnih rešitev.'
    elif len(sol) == 1:
        output += 'Enačba ima eno realno rešitev: {}'.format(sol[0])
    else:
        output += 'Enačba ima dve realni rešitvi: {} in {}'.format(
            sol[0], sol[1])
    output += '\n'
    in_out.append((input, output))

print('''OPOZORILO
Test predpostavlja, da je pri kvadratnih enačbah z dvema rešitvama
vrstni red rešitev enak kot v navodilu naloge.\n''')

tester.check('kvadratna_enacba.py', in_out)
import tester

in_out = [
    [(1, ), '*\n'],
    [(2, ), '*\n**\n'],
    [(3, ), '*\n**\n***\n'],
    [(4, ), '*\n**\n***\n****\n'],
    [(6, ), '*\n**\n***\n****\n*****\n******\n'],
]

for xs in in_out:
    xs[1] = 'Vpiši višino: ' + xs[1]
tester.check('trikotnik_iz_zvezdic.py', in_out)
import tester

in_out = [
    [(1,), '1\n'],
    [(3,), '1\n3\n'],
    [(18,), '1\n2\n3\n6\n9\n18\n'],
    [(42,), '1\n2\n3\n6\n7\n14\n21\n42\n'],
    [(120,), '1\n2\n3\n4\n5\n6\n8\n10\n12\n15\n20\n24\n30\n40\n60\n120\n'],
    [(121,), '1\n11\n121\n'],
    [(122,), '1\n2\n61\n122\n'],
    [(12345,), '1\n3\n5\n15\n823\n2469\n4115\n12345\n'],
]

for xs in in_out:
    xs[1] = 'Vpiši število: ' + xs[1]
tester.check('delitelji.py', in_out)
示例#9
0
tests = [
    ('Test na manjših številih', [
        (1, True),
        (2, False),
        (7, False),
        (25, True),
        (27, False),
        (1234, False),
        (9876, False),
        (123**2, True),
        (123**2 + 1, False),
    ]),
    ('Test na velikih številih (težje)', [
        (123456789**2, True),
        (123456789**2 + 1, False),
        (123456789**2 - 1, False),
        (5613524678954351234687**2, True),
        (5613524678954351234687**2 + 1, False),
        (5613524678954351234687**2 - 1, False),
    ]),
]

for msg, inputs in tests:
    print(msg + '\n' + '-' * len(msg))
    in_out = []
    for n, isprime in inputs:
        in_out.append(((n, ), 'Vpiši število: Število {} kvadrat\n'.format(
            'je' if isprime else 'ni')))
    tester.check('kvadrati.py', in_out)
    print()
示例#10
0
import tester

in_out = [
    [(1, ), '*\n'],
    [(2, ), ' *\n***\n'],
    [(3, ), '  *\n ***\n*****\n'],
    [(4, ), '   *\n  ***\n *****\n*******\n'],
    [(6, ), '     *\n    ***\n   *****\n  *******\n *********\n***********\n'],
]

for xs in in_out:
    xs[1] = 'Vpiši višino: ' + xs[1]
tester.check('smrekica.py', in_out)
示例#11
0
        (0, 0),
        (1, 1),
        (2, 2),
        (3, 2),
        (4, 2),
        (5, 3),
        (20, 5),
        (120, 11),
        (121, 11),
        (122, 12),
        (1234**2, 1234),
        (1234**2 + 1, 1235),
    ]),
    ('Test na velikih številih (težje)', [
        (123456789**2, 123456789),
        (123456789**2 + 1, 123456790),
        (123456789987654321**2, 123456789987654321),
        (123456789987654321**2 + 1, 123456789987654322),
    ]),
]

for msg, inputs in tests:
    print(msg + '\n' + '-' * len(msg))
    in_out = []
    for n, m in inputs:
        in_out.append(
            ((n, ),
             'Vpiši število kock: Potrebujemo škatlo širine {}\n'.format(m)))
    tester.check('kocke.py', in_out)
    print()