Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
Simple test for inherited super class
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolkabra committed May 16, 2019
1 parent 00af981 commit 94a27ee
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
26 changes: 26 additions & 0 deletions xth/tests/pa7/coloredpoint.xi
Original file line number Diff line number Diff line change
@@ -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)
}
14 changes: 14 additions & 0 deletions xth/tests/pa7/point.ixi
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions xth/tests/pa7/point.xi
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 94a27ee

Please sign in to comment.