| 1 |
|
| 2 |
import { Point } from "./point.so"; |
| 3 |
|
| 4 |
function assert(b, str) |
| 5 |
{ |
| 6 |
if (b) { |
| 7 |
return; |
| 8 |
} else { |
| 9 |
throw Error("assertion failed: " + str); |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
class ColorPoint extends Point { |
| 14 |
constructor(x, y, color) { |
| 15 |
super(x, y); |
| 16 |
this.color = color; |
| 17 |
} |
| 18 |
get_color() { |
| 19 |
return this.color; |
| 20 |
} |
| 21 |
}; |
| 22 |
|
| 23 |
function main() |
| 24 |
{ |
| 25 |
var pt, pt2; |
| 26 |
|
| 27 |
pt = new Point(2, 3); |
| 28 |
assert(pt.x === 2); |
| 29 |
assert(pt.y === 3); |
| 30 |
pt.x = 4; |
| 31 |
assert(pt.x === 4); |
| 32 |
assert(pt.norm() == 5); |
| 33 |
|
| 34 |
pt2 = new ColorPoint(2, 3, 0xffffff); |
| 35 |
assert(pt2.x === 2); |
| 36 |
assert(pt2.color === 0xffffff); |
| 37 |
assert(pt2.get_color() === 0xffffff); |
| 38 |
} |
| 39 |
|
| 40 |
main(); |