Skip to content

Commit

Permalink
fixed unit tests and added missing feature
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-w committed Jan 18, 2024
1 parent 7d654a3 commit 6834ce0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 8 additions & 0 deletions src/scripting/V3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ V3f & V3f::operator =(const V3f &v)
return *this;
}

QString V3f::toHex() const
{
return QString("#%1%2%3")
.arg(qMin(255, int(m_x * 255)), 2, 16, QChar('0'))
.arg(qMin(255, int(m_y * 255)), 2, 16, QChar('0'))
.arg(qMin(255, int(m_z * 255)), 2, 16, QChar('0'));
}

///////////////////////
#ifdef ENABLE_SCRIPT_QML

Expand Down
2 changes: 2 additions & 0 deletions src/scripting/V3d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public slots:
//! Formats a comma-separated string in angle brackets
//! @todo currently this seems to to nothing. JS print output shows "V3f(address)". Use toVec3f() to show the values formatted by Vec3f's method.
Q_INVOKABLE QString toString() const {return QString("[%1, %2, %3]").arg(m_x).arg(m_y).arg(m_z);}
//! Formats a hex string
Q_INVOKABLE QString toHex() const;
private:
float m_x, m_y, m_z;
};
Expand Down
20 changes: 10 additions & 10 deletions src/tests/testJavaScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void TestJavaScripting::testVec3fConstructor()
"f9.toHex()\n"
<< "#ffffff";

while (data.count() >= 4)
while (data.count() >= 2)
{
QString script = data.takeFirst().toString();
QString expect = data.takeFirst().toString();
Expand All @@ -118,7 +118,7 @@ void TestJavaScripting::testVec3fConstructorFail()
"f10.toString()\n"
<< "error";

while (data.count() >= 4)
while (data.count() >= 2)
{
QString script = data.takeFirst().toString();
QString expect = data.takeFirst().toString();
Expand Down Expand Up @@ -152,7 +152,7 @@ void TestJavaScripting::testVec3dConstructor()
<< "[?, ?, ?]";
***/

while (data.count() >= 4)
while (data.count() >= 2)
{
QString script = data.takeFirst().toString();
QString expect = data.takeFirst().toString();
Expand All @@ -177,11 +177,11 @@ void TestJavaScripting::testV3d()
#else
<< "[0, 0, 0]"
#endif
<< "var f9 = new V3d(f1);\n" // still the same QScriptEngine
"f9.toHex()\n"
<< "var fa = new V3d(1.0, 1.0, 1.0);\n"
"fa.toHex()\n"
<< "#ffffff";

while (data.count() >= 4)
while (data.count() >= 2)
{
QString script = data.takeFirst().toString();
QString expect = data.takeFirst().toString();
Expand All @@ -204,11 +204,11 @@ void TestJavaScripting::testV3f()
#else
<< "[r:0, g:0, b:0]" // difference is just the r/g/b labels
#endif
<< "var f9 = new V3f(f1);\n" // still the same Engine
"f9.toHex()\n"
<< "var fa = new V3f(1.0, 1.0, 1.0);\n"
"fa.toHex()\n"
<< "#ffffff";

while (data.count() >= 4)
while (data.count() >= 2)
{
QString script = data.takeFirst().toString();
QString expect = data.takeFirst().toString();
Expand Down Expand Up @@ -246,7 +246,7 @@ void TestJavaScripting::testColor()
"f9.toHex()\n"
<< "#ffffff";

while (data.count() >= 4)
while (data.count() >= 2)
{
QString script = data.takeFirst().toString();
QString expect = data.takeFirst().toString();
Expand Down

0 comments on commit 6834ce0

Please sign in to comment.