mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:16:51 +00:00
b101a7d002
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
102 lines
2.2 KiB
Dart
102 lines
2.2 KiB
Dart
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// @dart = 2.9
|
|
|
|
import 'dart:math';
|
|
import 'package:expect/expect.dart';
|
|
|
|
main() {
|
|
// constructor
|
|
{
|
|
var point = new Point(0, 0);
|
|
Expect.equals(0, point.x);
|
|
Expect.equals(0, point.y);
|
|
Expect.equals('Point(0, 0)', '$point');
|
|
}
|
|
|
|
// constructor X
|
|
{
|
|
var point = new Point<int>(10, 0);
|
|
Expect.equals(10, point.x);
|
|
Expect.equals(0, point.y);
|
|
Expect.equals('Point(10, 0)', '$point');
|
|
}
|
|
|
|
// constructor X Y
|
|
{
|
|
var point = new Point<int>(10, 20);
|
|
Expect.equals(10, point.x);
|
|
Expect.equals(20, point.y);
|
|
Expect.equals('Point(10, 20)', '$point');
|
|
}
|
|
|
|
// constructor X Y double
|
|
{
|
|
var point = new Point<double>(10.5, 20.897);
|
|
Expect.equals(10.5, point.x);
|
|
Expect.equals(20.897, point.y);
|
|
Expect.equals('Point(10.5, 20.897)', '$point');
|
|
}
|
|
|
|
// constructor X Y NaN
|
|
{
|
|
var point = new Point(double.nan, 1000);
|
|
Expect.isTrue(point.x.isNaN);
|
|
Expect.equals(1000, point.y);
|
|
Expect.equals('Point(NaN, 1000)', '$point');
|
|
}
|
|
|
|
// squaredDistanceTo
|
|
{
|
|
var a = new Point(7, 11);
|
|
var b = new Point(3, -1);
|
|
Expect.equals(160, a.squaredDistanceTo(b));
|
|
Expect.equals(160, b.squaredDistanceTo(a));
|
|
}
|
|
|
|
// distanceTo
|
|
{
|
|
var a = new Point(-2, -3);
|
|
var b = new Point(2, 0);
|
|
Expect.equals(5, a.distanceTo(b));
|
|
Expect.equals(5, b.distanceTo(a));
|
|
}
|
|
|
|
// subtract
|
|
{
|
|
var a = new Point(5, 10);
|
|
var b = new Point(2, 50);
|
|
Expect.equals(new Point(3, -40), a - b);
|
|
}
|
|
|
|
// add
|
|
{
|
|
var a = new Point(5, 10);
|
|
var b = new Point(2, 50);
|
|
Expect.equals(new Point(7, 60), a + b);
|
|
}
|
|
|
|
// hashCode
|
|
{
|
|
var a = new Point(0, 1);
|
|
var b = new Point(0, 1);
|
|
Expect.equals(b.hashCode, a.hashCode);
|
|
|
|
var c = new Point(1, 0);
|
|
Expect.isFalse(a.hashCode == c.hashCode);
|
|
}
|
|
|
|
// magnitude
|
|
{
|
|
var a = new Point(5, 10);
|
|
var b = new Point(0, 0);
|
|
Expect.equals(a.distanceTo(b), a.magnitude);
|
|
Expect.equals(0, b.magnitude);
|
|
|
|
var c = new Point(-5, -10);
|
|
Expect.equals(a.distanceTo(b), c.magnitude);
|
|
}
|
|
}
|