Exemplo n.º 1
0
class ArrayTest(unittest.TestCase):
    def setUp(self):
        self.jvm = Machine()
        load_stdlib_classes(self.jvm)
        self.jvm.load_class_file('example/ArrayTest.class')

    def test_insertion_sort(self):
        l = [4, 3, 5, 1]
        r = self.jvm.call_function('jvmtest/ArrayTest/insertionSort', l)
        self.assertEqual(r, None)
        self.assertEqual(l, [1, 3, 4, 5])

    def test_cocktail_sort(self):
        l = [4, 3, 5, 1]
        r = self.jvm.call_function('jvmtest/ArrayTest/cocktailSort', l)
        self.assertEqual(r, None)
        self.assertEqual(l, [1, 3, 4, 5])

    def test_sum(self):
        l = [5, 5, 14, 3]
        r = self.jvm.call_function('jvmtest/ArrayTest/sum', l)
        self.assertEqual(r, sum(l))

    def test_loop_multiple(self):
        r = self.jvm.call_function('jvmtest/ArrayTest/loopMultipleArray')
        self.assertEqual(r, 'aA1\nbB2\ncC3\n')
Exemplo n.º 2
0
class StringTest(unittest.TestCase):
    def setUp(self):
        self.jvm = Machine()
        load_stdlib_classes(self.jvm)
        self.jvm.load_class_file('example/StringTest.class')

    def test_rot13_hello_world(self):
        self.assertEqual(
            self.jvm.call_function('jvmtest/StringTest/rot13', 'Hello World!'),
            'Uryyb Jbeyq!')

    def test_reverse_string(self):
        r = self.jvm.call_function('jvmtest/StringTest/reverseString',
                                   'Test message!')
        self.assertEqual(r, '!egassem tseT')
Exemplo n.º 3
0
class JVMTest(unittest.TestCase):
    def setUp(self):
        self.jvm = Machine()
        load_stdlib_classes(self.jvm)
        self.jvm.load_class_file('example/IntegerTest.class')

    def test_return_0(self):
        self.assertEqual(self.jvm.call_function('jvmtest/IntegerTest/return0'),
                         0)

    def test_return_1(self):
        self.assertEqual(self.jvm.call_function('jvmtest/IntegerTest/return1'),
                         1)

    def test_return_5000(self):
        self.assertEqual(
            self.jvm.call_function('jvmtest/IntegerTest/return5000'), 5000)

    def test_passthrough(self):
        for i in range(500):
            self.assertEqual(
                self.jvm.call_function('jvmtest/IntegerTest/passthrough', i),
                i)

    def test_passthrough_loop(self):
        for i in range(500, 550):
            self.assertEqual(
                self.jvm.call_function('jvmtest/IntegerTest/passthrough_loop',
                                       i), i)

    def test_double(self):
        for i in range(500):
            self.assertEqual(
                self.jvm.call_function('jvmtest/IntegerTest/doubleNum', i),
                i * 2)

    def test_power(self):
        for i in range(500):
            self.assertEqual(
                self.jvm.call_function('jvmtest/IntegerTest/power', i), i * i)

    def test_iterative_fibonacci(self):
        self.assertEqual(
            self.jvm.call_function('jvmtest/IntegerTest/iterativeFibonacci',
                                   20), 6765)

    def test_recursive_fibonacci(self):
        self.assertEqual(
            self.jvm.call_function('jvmtest/IntegerTest/recursiveFibonacci',
                                   7), 13)
Exemplo n.º 4
0
class InstanceTest(unittest.TestCase):
    def setUp(self):
        self.jvm = Machine()
        load_stdlib_classes(self.jvm)
        self.jvm.load_class_file('example/InstanceTest.class')

    def test_single_instance(self):
        self.assertEqual(
            self.jvm.call_function('jvmtest/InstanceTest/test_single'), 12345)

    def test_multiple_instance_1(self):
        self.assertEqual(
            self.jvm.call_function('jvmtest/InstanceTest/test_multiple_1'),
            12345)

    def test_multiple_instance_2(self):
        self.assertEqual(
            self.jvm.call_function('jvmtest/InstanceTest/test_multiple_2'),
            54321)
Exemplo n.º 5
0
#!/usr/bin/env python3
from pyjvm.Machine import Machine
from pyjvm.jstdlib.StdlibLoader import load_stdlib_classes

m = Machine()

# Load stdlib
load_stdlib_classes(m)

# Load local classes
m.load_class_file('example/Hello.class')
#m.load_class_file('example/TestImport.class')
#m.load_class_file('example/IntegerTest.class')
#m.load_class_file('example/Rot13.class')
#m.load_class_file('example/InstanceTest.class')

# Dump machine state
#m.dump()

print(m.call_function('com/gkbrk/JVMTest/Hello/monteCarloPi', 5000))
Exemplo n.º 6
0
    frames_chunk = frames[i:i + 14]

    page = Layout(
        HSplit([
            VSplit([HSplit([Frame(VSplit(frame)) for frame in frames_chunk])]),
            Window(),
            Label('LEFT/RIGHT: change page. v: toggle view. q: quit.')
        ]))

    CONST_POOL_PAGES += [page]

# start the JVM and record the Layout at each step
log.info(f'Recording the execution of {method}...')
ERROR = False
try:
    stdout = jvm.call_function(method, arguments)
except Exception as e:
    log.exception('Something went wrong during the execution')
    ERROR = True

if not LAYOUT_STACK:
    log.error('There\'s nothing to replay. Aborting now...')
    exit(1)

# overwrite the first textbox of each Layout object to show the number of steps
for i, l in enumerate(LAYOUT_STACK):
    if ERROR:
        text = f'Step {i+1}/{len(LAYOUT_STACK)} [WARNING: PARTIAL EXECUTION]'
        style = 'class:text-area fg:red'
    else:
        text = f'Step {i+1}/{len(LAYOUT_STACK)}'