Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds more unit tests for Vector2D

  • Loading branch information...
commit 36b66b6f5dc0c25089dba7d09071bf60cb616788 1 parent 302eb0e
@dtillner authored
Showing with 476 additions and 9 deletions.
  1. +476 −9 Vector2DTest.dart
View
485 Vector2DTest.dart
@@ -1,6 +1,3 @@
-#import('unittest/unittest.dart');
-#source('Vector2D.dart');
-
vector2DTests() {
group('Constructor', () {
@@ -184,11 +181,59 @@ vector2DTests() {
});
});
- group('Addition', () {
+ group('Scalar Addition', () {
+ test('Test 1', () {
+ Vector2D v = new Vector2D(0,0);
+ v = v + 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 2', () {
+ Vector2D v = new Vector2D(-4,1);
+ v = v + 3;
+ Expect.equals(-1, v.x);
+ Expect.equals(4, v.y);
+ });
+
+ test('Test 3', () {
+ Vector2D v = new Vector2D(-1,4);
+ v = v + -3;
+ Expect.equals(-4, v.x);
+ Expect.equals(1, v.y);
+ });
+
+ test('Test 4', () {
+ Vector2D v = new Vector2D(0,0);
+ v += 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 5', () {
+ Vector2D v = new Vector2D(-4,1);
+ v += 3;
+ Expect.equals(-1, v.x);
+ Expect.equals(4, v.y);
+ });
+
+ test('Test 6', () {
+ Vector2D v = new Vector2D(-1,4);
+ v += -3;
+ Expect.equals(-4, v.x);
+ Expect.equals(1, v.y);
+ });
+ });
+
+ group('Vector Addition', () {
test('Test 1', () {
Vector2D v1 = new Vector2D(0,0);
Vector2D v2 = new Vector2D(0,0);
Vector2D v3 = v1 + v2;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(0, v2.x);
+ Expect.equals(0, v2.y);
Expect.equals(0, v3.x);
Expect.equals(0, v3.y);
});
@@ -197,6 +242,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(1,2);
Vector2D v2 = new Vector2D(3,4);
Vector2D v3 = v1 + v2;
+ Expect.equals(1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(3, v2.x);
+ Expect.equals(4, v2.y);
Expect.equals(4, v3.x);
Expect.equals(6, v3.y);
});
@@ -205,6 +254,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(-1,2);
Vector2D v2 = new Vector2D(3,-4);
Vector2D v3 = v1 + v2;
+ Expect.equals(-1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(3, v2.x);
+ Expect.equals(-4, v2.y);
Expect.equals(2, v3.x);
Expect.equals(-2, v3.y);
});
@@ -213,6 +266,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(0,0);
Vector2D v2 = new Vector2D(-3,4);
Vector2D v3 = v1 + v2;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(-3, v2.x);
+ Expect.equals(4, v2.y);
Expect.equals(-3, v3.x);
Expect.equals(4, v3.y);
});
@@ -221,6 +278,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(1,2);
Vector2D v2 = new Vector2D(0,0);
Vector2D v3 = v1 + v2;
+ Expect.equals(1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(0, v2.x);
+ Expect.equals(0, v2.y);
Expect.equals(1, v3.x);
Expect.equals(2, v3.y);
});
@@ -245,12 +306,60 @@ vector2DTests() {
Expect.equals(-4, v2.y);
});
});
+
+ group('Scalar Subtraction', () {
+ test('Test 1', () {
+ Vector2D v = new Vector2D(0,0);
+ v = v - 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 2', () {
+ Vector2D v = new Vector2D(2,4);
+ v = v - 3;
+ Expect.equals(-1, v.x);
+ Expect.equals(1, v.y);
+ });
+
+ test('Test 3', () {
+ Vector2D v = new Vector2D(-4,1);
+ v = v - -3;
+ Expect.equals(-1, v.x);
+ Expect.equals(4, v.y);
+ });
+
+ test('Test 4', () {
+ Vector2D v = new Vector2D(0,0);
+ v -= 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 5', () {
+ Vector2D v = new Vector2D(2,4);
+ v -= 3;
+ Expect.equals(-1, v.x);
+ Expect.equals(1, v.y);
+ });
+
+ test('Test 6', () {
+ Vector2D v = new Vector2D(-4,1);
+ v -= -3;
+ Expect.equals(-1, v.x);
+ Expect.equals(4, v.y);
+ });
+ });
- group('Subtraction', () {
+ group('Vector Subtraction', () {
test('Test 1', () {
Vector2D v1 = new Vector2D(0,0);
Vector2D v2 = new Vector2D(0,0);
Vector2D v3 = v1 - v2;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(0, v2.x);
+ Expect.equals(0, v2.y);
Expect.equals(0, v3.x);
Expect.equals(0, v3.y);
});
@@ -259,6 +368,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(1,2);
Vector2D v2 = new Vector2D(3,4);
Vector2D v3 = v1 - v2;
+ Expect.equals(1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(3, v2.x);
+ Expect.equals(4, v2.y);
Expect.equals(-2, v3.x);
Expect.equals(-2, v3.y);
});
@@ -267,6 +380,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(-1,2);
Vector2D v2 = new Vector2D(3,-4);
Vector2D v3 = v1 - v2;
+ Expect.equals(-1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(3, v2.x);
+ Expect.equals(-4, v2.y);
Expect.equals(-4, v3.x);
Expect.equals(6, v3.y);
});
@@ -275,6 +392,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(0,0);
Vector2D v2 = new Vector2D(-3,4);
Vector2D v3 = v1 - v2;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(-3, v2.x);
+ Expect.equals(4, v2.y);
Expect.equals(3, v3.x);
Expect.equals(-4, v3.y);
});
@@ -283,6 +404,10 @@ vector2DTests() {
Vector2D v1 = new Vector2D(1,2);
Vector2D v2 = new Vector2D(0,0);
Vector2D v3 = v1 - v2;
+ Expect.equals(1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(0, v2.x);
+ Expect.equals(0, v2.y);
Expect.equals(1, v3.x);
Expect.equals(2, v3.y);
});
@@ -307,8 +432,350 @@ vector2DTests() {
Expect.equals(-4, v2.y);
});
});
-}
-
-void main() {
- vector2DTests();
+
+ group('Scalar Multiplication', () {
+ test('Test 1', () {
+ Vector2D v = new Vector2D(0,0);
+ v = v * 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 2', () {
+ Vector2D v = new Vector2D(-2,2);
+ v = v * 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 3', () {
+ Vector2D v = new Vector2D(-2,2);
+ v = v * 3;
+ Expect.equals(-6, v.x);
+ Expect.equals(6, v.y);
+ });
+
+ test('Test 4', () {
+ Vector2D v = new Vector2D(-2,2);
+ v = v * -3;
+ Expect.equals(6, v.x);
+ Expect.equals(-6, v.y);
+ });
+
+ test('Test 5', () {
+ Vector2D v = new Vector2D(0,0);
+ v *= 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 6', () {
+ Vector2D v = new Vector2D(-2,2);
+ v *= 0;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 7', () {
+ Vector2D v = new Vector2D(-2,2);
+ v *= 3;
+ Expect.equals(-6, v.x);
+ Expect.equals(6, v.y);
+ });
+
+ test('Test 8', () {
+ Vector2D v = new Vector2D(-2,2);
+ v *= -3;
+ Expect.equals(6, v.x);
+ Expect.equals(-6, v.y);
+ });
+ });
+
+ group('Vector Multiplication', () {
+ test('Test 1', () {
+ Vector2D v1 = new Vector2D(0,0);
+ Vector2D v2 = new Vector2D(0,0);
+ Vector2D v3 = v1 * v2;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(0, v2.x);
+ Expect.equals(0, v2.y);
+ Expect.equals(0, v3.x);
+ Expect.equals(0, v3.y);
+ });
+
+ test('Test 2', () {
+ Vector2D v1 = new Vector2D(1,2);
+ Vector2D v2 = new Vector2D(3,4);
+ Vector2D v3 = v1 * v2;
+ Expect.equals(1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(3, v2.x);
+ Expect.equals(4, v2.y);
+ Expect.equals(3, v3.x);
+ Expect.equals(8, v3.y);
+ });
+
+ test('Test 3', () {
+ Vector2D v1 = new Vector2D(-1,0);
+ Vector2D v2 = new Vector2D(1,2);
+ Vector2D v3 = v1 * v2;
+ Expect.equals(-1, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(1, v2.x);
+ Expect.equals(2, v2.y);
+ Expect.equals(-1, v3.x);
+ Expect.equals(0, v3.y);
+ });
+
+ test('Test 4', () {
+ Vector2D v1 = new Vector2D(0,0);
+ Vector2D v2 = new Vector2D(0,0);
+ v2 *= v1;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(0, v2.x);
+ Expect.equals(0, v2.y);
+ });
+
+ test('Test 5', () {
+ Vector2D v1 = new Vector2D(1,2);
+ Vector2D v2 = new Vector2D(3,4);
+ v2 *= v1;
+ Expect.equals(1, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(3, v2.x);
+ Expect.equals(8, v2.y);
+ });
+
+ test('Test 6', () {
+ Vector2D v1 = new Vector2D(-1,0);
+ Vector2D v2 = new Vector2D(1,2);
+ v2 *= v1;
+ Expect.equals(-1, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(-1, v2.x);
+ Expect.equals(0, v2.y);
+ });
+ });
+
+ group('Scalar Division', () {
+ test('Test 1', () {
+ Vector2D v = new Vector2D(0,0);
+ v = v / 1;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 2', () {
+ Vector2D v = new Vector2D(-2,2);
+ v = v / 1;
+ Expect.equals(-2, v.x);
+ Expect.equals(2, v.y);
+ });
+
+ test('Test 3', () {
+ Vector2D v = new Vector2D(-4,4);
+ v = v / 2;
+ Expect.equals(-2, v.x);
+ Expect.equals(2, v.y);
+ });
+
+ test('Test 4', () {
+ Vector2D v = new Vector2D(-4,4);
+ v = v / -2;
+ Expect.equals(2, v.x);
+ Expect.equals(-2, v.y);
+ });
+
+ test('Test 5', () {
+ Vector2D v = new Vector2D(-3,3);
+ v = v / 2;
+ Expect.equals(-1.5, v.x);
+ Expect.equals(1.5, v.y);
+ });
+
+ test('Test 6', () {
+ Vector2D v = new Vector2D(-3,3);
+ v = v / -2;
+ Expect.equals(1.5, v.x);
+ Expect.equals(-1.5, v.y);
+ });
+
+ test('Test 7', () {
+ Vector2D v = new Vector2D(0,0);
+ v /= 1;
+ Expect.equals(0, v.x);
+ Expect.equals(0, v.y);
+ });
+
+ test('Test 8', () {
+ Vector2D v = new Vector2D(-2,2);
+ v /= 1;
+ Expect.equals(-2, v.x);
+ Expect.equals(2, v.y);
+ });
+
+ test('Test 9', () {
+ Vector2D v = new Vector2D(-4,4);
+ v /= 2;
+ Expect.equals(-2, v.x);
+ Expect.equals(2, v.y);
+ });
+
+ test('Test 10', () {
+ Vector2D v = new Vector2D(-4,4);
+ v /= -2;
+ Expect.equals(2, v.x);
+ Expect.equals(-2, v.y);
+ });
+
+ test('Test 11', () {
+ Vector2D v = new Vector2D(-3,3);
+ v /= 2;
+ Expect.equals(-1.5, v.x);
+ Expect.equals(1.5, v.y);
+ });
+
+ test('Test 12', () {
+ Vector2D v = new Vector2D(-3,3);
+ v /= -2;
+ Expect.equals(1.5, v.x);
+ Expect.equals(-1.5, v.y);
+ });
+ });
+
+ group('Scalar Division', () {
+ test('Test 1', () {
+ Vector2D v1 = new Vector2D(0,0);
+ Vector2D v2 = new Vector2D(1,2);
+ Vector2D v3 = v1 / v2;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(1, v2.x);
+ Expect.equals(2, v2.y);
+ Expect.equals(0, v3.x);
+ Expect.equals(0, v3.y);
+ });
+
+ test('Test 2', () {
+ Vector2D v1 = new Vector2D(-2,2);
+ Vector2D v2 = new Vector2D(1,1);
+ Vector2D v3 = v1 / v2;
+ Expect.equals(-2, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(1, v2.x);
+ Expect.equals(1, v2.y);
+ Expect.equals(-2, v3.x);
+ Expect.equals(2, v3.y);
+ });
+
+ test('Test 3', () {
+ Vector2D v1 = new Vector2D(-4,4);
+ Vector2D v2 = new Vector2D(2,2);
+ Vector2D v3 = v1 / v2;
+ Expect.equals(-4, v1.x);
+ Expect.equals(4, v1.y);
+ Expect.equals(2, v2.x);
+ Expect.equals(2, v2.y);
+ Expect.equals(-2, v3.x);
+ Expect.equals(2, v3.y);
+ });
+
+ test('Test 4', () {
+ Vector2D v1 = new Vector2D(-4,4);
+ Vector2D v2 = new Vector2D(-2,-2);
+ Vector2D v3 = v1 / v2;
+ Expect.equals(-4, v1.x);
+ Expect.equals(4, v1.y);
+ Expect.equals(-2, v2.x);
+ Expect.equals(-2, v2.y);
+ Expect.equals(2, v3.x);
+ Expect.equals(-2, v3.y);
+ });
+
+ test('Test 5', () {
+ Vector2D v1 = new Vector2D(-3,3);
+ Vector2D v2 = new Vector2D(2,2);
+ Vector2D v3 = v1 / v2;
+ Expect.equals(-3, v1.x);
+ Expect.equals(3, v1.y);
+ Expect.equals(2, v2.x);
+ Expect.equals(2, v2.y);
+ Expect.equals(-1.5, v3.x);
+ Expect.equals(1.5, v3.y);
+ });
+
+ test('Test 6', () {
+ Vector2D v1 = new Vector2D(-3,3);
+ Vector2D v2 = new Vector2D(-2,-2);
+ Vector2D v3 = v1 / v2;
+ Expect.equals(-3, v1.x);
+ Expect.equals(3, v1.y);
+ Expect.equals(-2, v2.x);
+ Expect.equals(-2, v2.y);
+ Expect.equals(1.5, v3.x);
+ Expect.equals(-1.5, v3.y);
+ });
+
+ test('Test 7', () {
+ Vector2D v1 = new Vector2D(0,0);
+ Vector2D v2 = new Vector2D(1,2);
+ v1 /= v2;
+ Expect.equals(0, v1.x);
+ Expect.equals(0, v1.y);
+ Expect.equals(1, v2.x);
+ Expect.equals(2, v2.y);
+ });
+
+ test('Test 8', () {
+ Vector2D v1 = new Vector2D(-2,2);
+ Vector2D v2 = new Vector2D(1,1);
+ v1 /= v2;
+ Expect.equals(-2, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(1, v2.x);
+ Expect.equals(1, v2.y);
+ });
+
+ test('Test 9', () {
+ Vector2D v1 = new Vector2D(-4,4);
+ Vector2D v2 = new Vector2D(2,2);
+ v1 /= v2;
+ Expect.equals(-2, v1.x);
+ Expect.equals(2, v1.y);
+ Expect.equals(2, v2.x);
+ Expect.equals(2, v2.y);
+ });
+
+ test('Test 10', () {
+ Vector2D v1 = new Vector2D(-4,4);
+ Vector2D v2 = new Vector2D(-2,-2);
+ v1 /= v2;
+ Expect.equals(2, v1.x);
+ Expect.equals(-2, v1.y);
+ Expect.equals(-2, v2.x);
+ Expect.equals(-2, v2.y);
+ });
+
+ test('Test 11', () {
+ Vector2D v1 = new Vector2D(-3,3);
+ Vector2D v2 = new Vector2D(2,2);
+ v1 /= v2;
+ Expect.equals(-1.5, v1.x);
+ Expect.equals(1.5, v1.y);
+ Expect.equals(2, v2.x);
+ Expect.equals(2, v2.y);
+ });
+
+ test('Test 12', () {
+ Vector2D v1 = new Vector2D(-3,3);
+ Vector2D v2 = new Vector2D(-2,-2);
+ v1 /= v2;
+ Expect.equals(1.5, v1.x);
+ Expect.equals(-1.5, v1.y);
+ Expect.equals(-2, v2.x);
+ Expect.equals(-2, v2.y);
+ });
+ });
}
Please sign in to comment.
Something went wrong with that request. Please try again.