sku-pg
Version:
Skulpt is a Javascript implementation of Python 2.x. Python that runs in your browser!
70 lines (55 loc) • 1.9 kB
HTML
<html>
<!--
Copyright 2007 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by an Apache 2.0 License.
See the COPYING file for details.
-->
<head>
<title>Closure Unit Tests - goog.math.Bezier</title>
<script src="../base.js"></script>
<script>
goog.require('goog.math.Bezier');
goog.require('goog.testing.jsunit');
</script>
</head>
<body>
<script>
function testEquals() {
var input = new goog.math.Bezier(1, 2, 3, 4, 5, 6, 7, 8);
assert(input.equals(input));
}
function testClone() {
var input = new goog.math.Bezier(1, 2, 3, 4, 5, 6, 7, 8);
assertNotEquals('Clone returns a new object', input, input.clone())
assert('Contents of clone match original', input.equals(input.clone()));
}
function testFlip() {
var input = new goog.math.Bezier(1, 1, 2, 2, 3, 3, 4, 4);
var compare = new goog.math.Bezier(4, 4, 3, 3, 2, 2, 1, 1);
var flipped = input.clone();
flipped.flip();
assert('Flipped behaves as expected', compare.equals(flipped));
flipped.flip();
assert('Flipping twice gives original', input.equals(flipped));
}
function testGetPoint() {
var input = new goog.math.Bezier(0, 1, 1, 2, 2, 3, 3, 4);
assert(goog.math.Coordinate.equals(input.getPoint(0),
new goog.math.Coordinate(0, 1)));
assert(goog.math.Coordinate.equals(input.getPoint(1),
new goog.math.Coordinate(3, 4)));
assert(goog.math.Coordinate.equals(input.getPoint(0.5),
new goog.math.Coordinate(1.5, 2.5)));
}
function testSubdivide() {
var input = new goog.math.Bezier(0, 1, 1, 2, 2, 3, 3, 4);
input.subdivide(1/3, 2/3);
assert(goog.math.nearlyEquals(1, input.x0));
assert(goog.math.nearlyEquals(2, input.y0));
assert(goog.math.nearlyEquals(2, input.x3));
assert(goog.math.nearlyEquals(3, input.y3));
}
</script>
</body>
</html>