diff --git a/xth/tests/pa7/coloredpoint.xi b/xth/tests/pa7/coloredpoint.xi new file mode 100644 index 0000000..d62f85f --- /dev/null +++ b/xth/tests/pa7/coloredpoint.xi @@ -0,0 +1,26 @@ +use io +use conv +use point + +class Color { + r, g, b: int +} + +class ColoredPoint extends Point { + col: Color + color(): Color { return col } + + initColoredPoint(x0: int, y0: int, c: Color): ColoredPoint { + col = c + _ = initPoint(x0, y0) + return this + } +} + +main(args:int[][]) { + c:Color = new Color + c.r = 1; c.g = 2; c.b = 3; + + p:Point = new ColoredPoint + _ = p.initPoint(1, 2) +} diff --git a/xth/tests/pa7/point.ixi b/xth/tests/pa7/point.ixi new file mode 100644 index 0000000..282559f --- /dev/null +++ b/xth/tests/pa7/point.ixi @@ -0,0 +1,14 @@ +// A 2D Point with integer coordinates (x,y) +class Point { + move(dx: int, dy: int) + add(p: Point): Point + coords(): int, int + clone(): Point + + // Initialize this to contain (x, y). + // Returns: this + initPoint(x: int, y: int): Point +} + +// Create the point (x, y) +createPoint(x: int, y:int): Point diff --git a/xth/tests/pa7/point.xi b/xth/tests/pa7/point.xi new file mode 100644 index 0000000..e967863 --- /dev/null +++ b/xth/tests/pa7/point.xi @@ -0,0 +1,25 @@ +class Point{ // a mutable point + x, y: int + + move(dx: int, dy: int) { + x = x + dx + y = y + dy + } + coords(): int, int { + return x, y + } + add(p: Point): Point { + return createPoint(x + p.x, y + p.y) + } + initPoint(x0: int, y0: int): Point { + x = x0 + y = y0 + return this + } + clone(): Point { return createPoint(x, y) } +} + +createPoint(x: int, y:int): Point { + return new Point.initPoint(x, y) +} +