123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- #include <QtTest/QtTest>
- #include "vector3d.h"
-
- class TestVector3D : public QObject
- {
- Q_OBJECT
-
- private slots:
- void gettersSetters1();
- void gettersSetters2();
- void gettersSetters3();
-
- void isNull1();
- void isNull1Op();
- void isNull2();
- void isNull2Op();
-
- void equal1();
- void equal2();
- void equal3();
- void equal4();
- void equal5();
- void equal6();
-
- void add1();
- void add1Op();
- void add2();
- void add2Op();
- void add3Op();
-
- void sub1();
- void sub1Op();
- void sub2();
- void sub2Op();
- void sub3Op();
-
- void mult();
- void multOp();
-
- void div();
- void divOp();
-
- void dotProduct1();
- void dotProduct1Op();
- void dotProduct2();
- void dotProduct2Op();
-
- void norm1();
- void norm2();
- };
-
- void TestVector3D::gettersSetters1()
- {
- Vector3D v;
- QCOMPARE(v.getX(), 0.0);
- QCOMPARE(v.getY(), 0.0);
- QCOMPARE(v.getZ(), 0.0);
- }
-
- void TestVector3D::gettersSetters2()
- {
- double x = 1.42, y = 2.0, z = 3.0;
- Vector3D v(x, y, z);
- QCOMPARE(v.getX(), x);
- QCOMPARE(v.getY(), y);
- QCOMPARE(v.getZ(), z);
- }
-
- void TestVector3D::gettersSetters3()
- {
- double x = 1.42, y = 2.0, z = 3.0;
- Vector3D v;
- v.setX(x).setY(y).setZ(z);
- QCOMPARE(v.getX(), x);
- QCOMPARE(v.getY(), y);
- QCOMPARE(v.getZ(), z);
- }
-
- void TestVector3D::isNull1()
- {
- double x = 1.42, y = 2.0, z = 3.0;
- Vector3D v(x, y, z);
- QCOMPARE(v.isNull(), false);
- }
-
- void TestVector3D::isNull1Op()
- {
- double x = 1.42, y = 2.0, z = 3.0;
- Vector3D v(x, y, z);
- QCOMPARE((bool)v, true);
- }
-
- void TestVector3D::isNull2()
- {
- Vector3D v;
- QCOMPARE(v.isNull(), true);
- }
-
- void TestVector3D::isNull2Op()
- {
- Vector3D v;
- QCOMPARE(!v, true);
- }
-
- void TestVector3D::equal1()
- {
- Vector3D v1(1.42, 2.0, 3.0);
- Vector3D v2(1.42, 2.0, 3.0);
- QCOMPARE(v1.equal(v2), true);
- }
-
- void TestVector3D::equal2()
- {
- Vector3D v1(1.42, 2.0, 3.0);
- Vector3D v2(1.40, 2.0, 3.0);
- QCOMPARE(v1.equal(v2), false);
- }
-
- void TestVector3D::equal3()
- {
- Vector3D v1(1.42, 2.0, 3.0);
- Vector3D v2(1.42, 2.1, 3.0);
- QCOMPARE(v1.equal(v2), false);
- }
-
- void TestVector3D::equal4()
- {
- Vector3D v1(1.42, 2.0, 3.0);
- Vector3D v2(1.42, 2.0, 3.1);
- QCOMPARE(v1.equal(v2), false);
- }
-
- void TestVector3D::equal5()
- {
- Vector3D v1(1.42, 2.0, 3.0);
- Vector3D v2(1.42, 2.0, 3.1);
- QCOMPARE(v1 == v2, false);
- }
-
- void TestVector3D::equal6()
- {
- Vector3D v1(1.42, 2.0, 3.0);
- Vector3D v2(1.42, 2.0, 3.0);
- QCOMPARE(v1 == v2, true);
- }
-
- void TestVector3D::add1()
- {
- double x = 1.42, y = 2.0, z = 3.0, x2 = 0.24, y2 = 24.0, z2 = 42.0;
- Vector3D v(x, y, z);
- v.add(x2, y2, z2);
- QCOMPARE(v.getX(), x + x2);
- QCOMPARE(v.getY(), y + y2);
- QCOMPARE(v.getZ(), z + z2);
- }
-
- void TestVector3D::add1Op()
- {
- double x = 1.42, y = 2.0, z = 3.0, x2 = 0.24, y2 = 24.0, z2 = 42.0;
- Vector3D v1(x, y, z);
- Vector3D v2(x2, y2, z2);
- Vector3D v = v1 + v2;
-
- QCOMPARE(v.getX(), x + x2);
- QCOMPARE(v.getY(), y + y2);
- QCOMPARE(v.getZ(), z + z2);
-
- QCOMPARE(v1.getX(), x);
- QCOMPARE(v1.getY(), y);
- QCOMPARE(v1.getZ(), z);
-
- QCOMPARE(v2.getX(), x2);
- QCOMPARE(v2.getY(), y2);
- QCOMPARE(v2.getZ(), z2);
- }
-
- void TestVector3D::add2()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 0.24;
- Vector3D v(x, y, z);
- v.add(m);
- QCOMPARE(v.getX(), x + m);
- QCOMPARE(v.getY(), y + m);
- QCOMPARE(v.getZ(), z + m);
- }
-
- void TestVector3D::add2Op()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 0.24;
- Vector3D v1(x, y, z);
- Vector3D v = v1 + m;
-
- QCOMPARE(v.getX(), x + m);
- QCOMPARE(v.getY(), y + m);
- QCOMPARE(v.getZ(), z + m);
-
- QCOMPARE(v1.getX(), x);
- QCOMPARE(v1.getY(), y);
- QCOMPARE(v1.getZ(), z);
- }
-
- void TestVector3D::add3Op()
- {
- double x = 1.42, y = 2.0, z = 3.0;
- Vector3D v1(x, y, z);
- Vector3D v = +v1;
-
- QCOMPARE(v.getX(), x);
- QCOMPARE(v.getY(), y);
- QCOMPARE(v.getZ(), z);
-
- QCOMPARE(v1.getX(), x);
- QCOMPARE(v1.getY(), y);
- QCOMPARE(v1.getZ(), z);
- }
-
- void TestVector3D::sub1()
- {
- double x = 1.42, y = 2.0, z = 3.0, x2 = 0.24, y2 = 24.0, z2 = 42.0;
- Vector3D v(x, y, z);
- v.sub(x2, y2, z2);
- QCOMPARE(v.getX(), x - x2);
- QCOMPARE(v.getY(), y - y2);
- QCOMPARE(v.getZ(), z - z2);
- }
-
- void TestVector3D::sub1Op()
- {
- double x = 1.42, y = 2.0, z = 3.0, x2 = 0.24, y2 = 24.0, z2 = 42.0;
- Vector3D v1(x, y, z);
- Vector3D v2(x2, y2, z2);
- Vector3D v = v1 - v2;
-
- QCOMPARE(v.getX(), x - x2);
- QCOMPARE(v.getY(), y - y2);
- QCOMPARE(v.getZ(), z - z2);
-
- QCOMPARE(v1.getX(), x);
- QCOMPARE(v1.getY(), y);
- QCOMPARE(v1.getZ(), z);
-
- QCOMPARE(v2.getX(), x2);
- QCOMPARE(v2.getY(), y2);
- QCOMPARE(v2.getZ(), z2);
- }
-
- void TestVector3D::sub2()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 0.24;
- Vector3D v(x, y, z);
- v.sub(m);
- QCOMPARE(v.getX(), x - m);
- QCOMPARE(v.getY(), y - m);
- QCOMPARE(v.getZ(), z - m);
- }
-
- void TestVector3D::sub2Op()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 0.24;
- Vector3D v1(x, y, z);
- Vector3D v = v1 - m;
-
- QCOMPARE(v.getX(), x - m);
- QCOMPARE(v.getY(), y - m);
- QCOMPARE(v.getZ(), z - m);
-
- QCOMPARE(v1.getX(), x);
- QCOMPARE(v1.getY(), y);
- QCOMPARE(v1.getZ(), z);
- }
-
- void TestVector3D::sub3Op()
- {
- double x = 1.42, y = 2.0, z = 3.0;
- Vector3D v1(x, y, z);
- Vector3D v = -v1;
-
- QCOMPARE(v.getX(), -x);
- QCOMPARE(v.getY(), -y);
- QCOMPARE(v.getZ(), -z);
-
- QCOMPARE(v1.getX(), x);
- QCOMPARE(v1.getY(), y);
- QCOMPARE(v1.getZ(), z);
- }
-
- void TestVector3D::mult()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
- Vector3D v(x, y, z);
- v.mult(m);
- QCOMPARE(v.getX(), x * m);
- QCOMPARE(v.getY(), y * m);
- QCOMPARE(v.getZ(), z * m);
- }
-
- void TestVector3D::multOp()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
- Vector3D v1(x, y, z);
- Vector3D v = v1 * m;
- QCOMPARE(v.getX(), x * m);
- QCOMPARE(v.getY(), y * m);
- QCOMPARE(v.getZ(), z * m);
- }
-
- void TestVector3D::div()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
- Vector3D v(x, y, z);
- v.div(m);
- QCOMPARE(v.getX(), x / m);
- QCOMPARE(v.getY(), y / m);
- QCOMPARE(v.getZ(), z / m);
- }
-
- void TestVector3D::divOp()
- {
- double x = 1.42, y = 2.0, z = 3.0, m = 2.0;
- Vector3D v1(x, y, z);
- Vector3D v = v1 / m;
- QCOMPARE(v.getX(), x / m);
- QCOMPARE(v.getY(), y / m);
- QCOMPARE(v.getZ(), z / m);
- }
-
- void TestVector3D::dotProduct1()
- {
- Vector3D v1(1.5, 2.0, 3.0);
- Vector3D v2(42.0, 5.0, 7.0);
- QCOMPARE(v1.dotProduct(v2), 94.0);
- }
-
- void TestVector3D::dotProduct1Op()
- {
- Vector3D v1(1.5, 2.0, 3.0);
- Vector3D v2(42.0, 5.0, 7.0);
- QCOMPARE(v1 * v2, 94.0);
- }
-
- void TestVector3D::dotProduct2()
- {
- Vector3D v1(20, 42, 10);
- Vector3D v2(42.0, 5.0, 7.0);
- QCOMPARE(v1.dotProduct(v2), 1120.0);
- }
-
- void TestVector3D::dotProduct2Op()
- {
- Vector3D v1(20, 42, 10);
- Vector3D v2(42.0, 5.0, 7.0);
- QCOMPARE(v1 * v2, 1120.0);
- }
-
- void TestVector3D::norm1()
- {
- Vector3D v(3, 4, 0);;
- QCOMPARE(v.norm(), 5.0);
- }
-
- void TestVector3D::norm2()
- {
- Vector3D v(0, 30, 40);;
- QCOMPARE(v.norm(), 50.0);
- }
-
- QTEST_MAIN(TestVector3D)
- #include "testvector3d.moc"
|