import stdio
import t, c


@t.CVTable
class Animal:
    name: t.CInt

    def __init__(self, n: t.CInt):
        self.name = n

    def GetName(self) -> t.CInt:
        return self.name

    def Speak(self) -> t.CInt:
        return 0


@t.CVTable
class Shape:
    sides: t.CInt

    def SetSides(self, n: t.CInt) -> t.CInt:
        self.sides = n
        return 0

    def GetSides(self) -> t.CInt:
        return self.sides


def vtable_test() -> int:
    stdio.printf("vtable: === Test Start ===\n")

    # 测试 1: Animal 虚方法调用（无参，访问 self 字段）
    a: Animal = Animal(42)
    name: int = a.GetName()
    stdio.printf("vtable: a.GetName()=%d (expected 42)\n", name)
    if name != 42:
        stdio.printf("[FAIL] a.GetName()=%d expected 42\n", name)
        return 1

    speak: int = a.Speak()
    stdio.printf("vtable: a.Speak()=%d (expected 0)\n", speak)
    if speak != 0:
        stdio.printf("[FAIL] a.Speak()=%d expected 0\n", speak)
        return 1

    # 测试 2: Shape 虚方法调用（带参，修改 self 字段）
    s: Shape = Shape()
    r: int = s.SetSides(4)
    stdio.printf("vtable: s.SetSides(4)=%d (expected 0)\n", r)
    if r != 0:
        stdio.printf("[FAIL] s.SetSides(4)=%d expected 0\n", r)
        return 1

    sides: int = s.GetSides()
    stdio.printf("vtable: s.GetSides()=%d (expected 4)\n", sides)
    if sides != 4:
        stdio.printf("[FAIL] s.GetSides()=%d expected 4\n", sides)
        return 1

    stdio.printf("vtable: === All Tests Passed ===\n")
    return 0
