示例#1
0
import unittest
from tdasm import Runtime
from sdl.vector import Vector2, Vector3, Vector4
from sdl.shader import Shader
from sdl.args import IntArg, FloatArg, Vec2Arg, Vec3Arg, Vec4Arg, StructArgPtr
from sdl.args import register_struct


class TestPoint:
    def __init__(self, x, y):
        self.x = x
        self.y = y

register_struct(TestPoint, 'TestPoint', fields=[('x', FloatArg),
               ('y', FloatArg)], factory=lambda: TestPoint(1.0, 2.0))


class FuncCallTests(unittest.TestCase):

    def setUp(self):
        self.runtimes = [Runtime()]

    def test_call(self):
        code = """
tmp = p1 + p2 + p3
p4.x = 55.99
return tmp
        """
        p1 = FloatArg('p1', 2.0)
        p2 = IntArg('p2', 0)
示例#2
0
import unittest
from tdasm import Runtime
from sdl.shader import Shader
from sdl.args import FloatArg, register_struct
from sdl.arr import ObjArray, ArrayArg


class SuperPoint:
    def __init__(self, x, y):
        self.x = x
        self.y = y

register_struct(SuperPoint, 'SuperPoint',
                fields=[('x', FloatArg), ('y', FloatArg)],
                factory=lambda: SuperPoint(1.0, 2.0))


class ArrayTests(unittest.TestCase):
    def test_array(self):

        p = SuperPoint(3.0, 4.0)
        arr = ObjArray(p)
        arr.append(p)
        arr.append(p)
        p = SuperPoint(7.0, 9.0)
        arr.append(p)

        code = """
index = 2
temp = arr[index]
示例#3
0
from sdl.vector import Vector2, Vector3, Vector4
from sdl.shader import Shader
from sdl.args import IntArg, FloatArg, Vec2Arg, Vec3Arg, Vec4Arg
from sdl.args import register_struct


class MyPoint:
    def __init__(self, x, y, k, m, p):
        self.x = x
        self.y = y
        self.k = k
        self.m = m
        self.p = p

register_struct(MyPoint, 'MyPoint', fields=[('x', IntArg),
               ('y', FloatArg), ('k', Vec2Arg), ('m', Vec3Arg),
               ('p', Vec4Arg)], factory=lambda:
               MyPoint(1, 2.0, Vector2(2.2, 3.3), Vector3(3.3, 5.5, 7.7), Vector4(3.3, 6.6, 8.8, 9.9)))


class StructTests(unittest.TestCase):

    def test_struct(self):
        code = """
a1 = MyPoint()
tmp = 66
a1.x = tmp
p1 = a1.x

tmp = 4.4
a1.y = tmp
p2 = a1.y
示例#4
0
import unittest
from tdasm import Runtime
from sdl.shader import Shader
from sdl.args import FloatArg, register_struct
from sdl.arr import ObjArray, ArrayArg


class SuperPoint:
    def __init__(self, x, y):
        self.x = x
        self.y = y


register_struct(SuperPoint,
                'SuperPoint',
                fields=[('x', FloatArg), ('y', FloatArg)],
                factory=lambda: SuperPoint(1.0, 2.0))


class ArrayTests(unittest.TestCase):
    def test_array(self):

        p = SuperPoint(3.0, 4.0)
        arr = ObjArray(p)
        arr.append(p)
        arr.append(p)
        p = SuperPoint(7.0, 9.0)
        arr.append(p)

        code = """
index = 2
示例#5
0
from sdl.args import register_struct


class MyPoint:
    def __init__(self, x, y, k, m, p):
        self.x = x
        self.y = y
        self.k = k
        self.m = m
        self.p = p


register_struct(
    MyPoint,
    'MyPoint',
    fields=[('x', IntArg), ('y', FloatArg), ('k', Vec2Arg), ('m', Vec3Arg),
            ('p', Vec4Arg)],
    factory=lambda: MyPoint(1, 2.0, Vector2(2.2, 3.3), Vector3(3.3, 5.5, 7.7),
                            Vector4(3.3, 6.6, 8.8, 9.9)))


class StructTests(unittest.TestCase):
    def test_struct(self):
        code = """
a1 = MyPoint()
tmp = 66
a1.x = tmp
p1 = a1.x

tmp = 4.4
a1.y = tmp
示例#6
0
import unittest
from tdasm import Runtime
from sdl.vector import Vector2, Vector3, Vector4
from sdl.shader import Shader
from sdl.args import IntArg, FloatArg, Vec2Arg, Vec3Arg, Vec4Arg, StructArgPtr
from sdl.args import register_struct


class TestPoint:
    def __init__(self, x, y):
        self.x = x
        self.y = y


register_struct(TestPoint,
                'TestPoint',
                fields=[('x', FloatArg), ('y', FloatArg)],
                factory=lambda: TestPoint(1.0, 2.0))


class FuncCallTests(unittest.TestCase):
    def setUp(self):
        self.runtimes = [Runtime()]

    def test_call(self):
        code = """
tmp = p1 + p2 + p3
p4.x = 55.99
return tmp
        """
        p1 = FloatArg('p1', 2.0)
        p2 = IntArg('p2', 0)