Skip to content

Commit

Permalink
Tests|libdeng2: Added the vectors test
Browse files Browse the repository at this point in the history
Also modified the Vector template classes to remove the automatic
casting to String, as that can easily cause some unexpected
conversions.
  • Loading branch information
skyjake committed Oct 25, 2012
1 parent 470fda9 commit 76fb46b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 10 deletions.
9 changes: 0 additions & 9 deletions doomsday/libdeng2/include/de/vector.h
Expand Up @@ -55,9 +55,6 @@ namespace de
operator Vector2<ddouble> () const {
return Vector2<ddouble>(ddouble(x), ddouble(y));
}
operator String () const {
return asText();
}
Vector2 operator + (const Vector2& other) const {
return Vector2(x + other.x, y + other.y);
}
Expand Down Expand Up @@ -158,9 +155,6 @@ namespace de
operator Vector3<ddouble> () const {
return Vector3<ddouble>(Vector2<Type>::x, Vector2<Type>::y, z);
}
operator String () const {
return asText();
}
Vector3 operator + (const Vector3& other) const {
return Vector3(Vector2<Type>::x + other.x, Vector2<Type>::y + other.y, z + other.z);
}
Expand Down Expand Up @@ -266,9 +260,6 @@ namespace de
operator Vector4<ddouble> () const {
return Vector4<ddouble>(Vector3<Type>::x, Vector3<Type>::y, Vector3<Type>::z, w);
}
operator String () const {
return asText();
}
Vector4 operator + (const Vector4& other) const {
return Vector4(Vector3<Type>::x + other.x, Vector3<Type>::y + other.y,
Vector3<Type>::z + other.z, w + other.w);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/tests/tests.pro
Expand Up @@ -4,6 +4,6 @@ SUBDIRS = \
#basiclink \
#record \
script \
#vectors
vectors

#OTHER_FILES += testapp.de
84 changes: 84 additions & 0 deletions doomsday/tests/vectors/main.cpp
@@ -0,0 +1,84 @@
/*
* The Doomsday Engine Project
*
* Copyright (c) 2009-2012 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <de/Vector>
#include <QDebug>

using namespace de;

int main(int, char**)
{
try
{
Vector2f a(1, 2.5);
Vector3f b(3, 5, 6);

// Note: Using QDebug because no de::App (and therefore no log message
// buffer) is available.

qDebug() << "Sizeof Vector2f:" << sizeof(a);
qDebug() << "Sizeof Vector3f:" << sizeof(b);

qDebug() << "Direct access to members:";
qDebug() << a.x << a.y;
qDebug() << b.x << b.y << b.z;

qDebug() << "First operand defines type of result:";

qDebug() << "Vector2f + Vector3f:" << (a + b).asText();
qDebug() << "Vector3f + Vector2f:" << (b + a).asText();

Vector2i c(6, 5);

// This would downgrade the latter to int; won't do it.
//qDebug() << "Vector2i + Vector2f (converted to int!): " << (c + a).asText();

qDebug() << "Vector2i:" << c.asText();
qDebug() << "Vector2f + Vector2i:" << (a + c).asText();

a += b;
b += a;
qDebug() << "After sum:" ;
qDebug() << "a:" << a.asText() << "b:" << b.asText();

qDebug() << "a > b: " << (a > b);
qDebug() << "b > a: " << (b > a);

Vector2f s(1, 1);
Vector3f t(2, 2, 2);
qDebug() << "s: " << s.asText() << " t:" << t.asText();
qDebug() << "s > t: " << (s > t);
qDebug() << "t > s: " << (t > s);
qDebug() << "s < t: " << (s < t);
qDebug() << "t < s: " << (t < s);
t.z = -100;
qDebug() << "t is now: " << t.asText();
qDebug() << "s > t: " << (s > t);
qDebug() << "t > s: " << (t > s);
qDebug() << "s < t: " << (s < t) << " <- first operand causes conversion to Vector2";
qDebug() << "t < s: " << (t < s);
}
catch(const Error& err)
{
qWarning() << err.asText() << "\n";
}

qDebug() << "Exiting main()...\n";
return 0;
}
15 changes: 15 additions & 0 deletions doomsday/tests/vectors/vectors.pro
@@ -0,0 +1,15 @@
include(../config_test.pri)

TEMPLATE = app
TARGET = test_vectors

SOURCES += main.cpp

macx {
cfg.files = $$DENG_CONFIG_DIR/deng.de
cfg.path = Contents/Resources/config

QMAKE_BUNDLE_DATA += cfg

macDeployTest($$TARGET)
}

0 comments on commit 76fb46b

Please sign in to comment.