From c99886d94389babc78e92bbfa5084fdd785915af Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 7 Dec 2012 15:20:12 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system improved unit tests for LLUnit renamed LLUnit to LLUnitImplicit with LLUnit being reserved for explicit units --- indra/llcommon/tests/llunits_test.cpp | 208 ++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 indra/llcommon/tests/llunits_test.cpp (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp new file mode 100644 index 0000000000..2a941e8229 --- /dev/null +++ b/indra/llcommon/tests/llunits_test.cpp @@ -0,0 +1,208 @@ +/** + * @file llsingleton_test.cpp + * @date 2011-08-11 + * @brief Unit test for the LLSingleton class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" + +#include "llunit.h" +#include "../test/lltut.h" + +namespace LLUnits +{ + // using powers of 2 to allow strict floating point equality + struct Quatloos { typedef Quatloos base_unit_t; }; + LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum); + LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari); +} + +namespace tut +{ + using namespace LLUnits; + struct units + { + }; + + typedef test_group units_t; + typedef units_t::object units_object_t; + tut::units_t tut_singleton("LLUnit"); + + // storage type conversions + template<> template<> + void units_object_t::test<1>() + { + LLUnit float_quatloos; + ensure(float_quatloos.value() == 0.f); + + LLUnit int_quatloos; + ensure(int_quatloos.value() == 0); + + int_quatloos = 42; + ensure(int_quatloos.value() == 42); + float_quatloos = int_quatloos; + ensure(float_quatloos.value() == 42.f); + + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + + float_quatloos = 42.1f; + ensure(float_quatloos.value() == 42.1f); + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + LLUnit unsigned_int_quatloos(float_quatloos); + ensure(unsigned_int_quatloos.value() == 42); + } + + // conversions to/from base unit + template<> template<> + void units_object_t::test<2>() + { + LLUnit quatloos(1.f); + ensure(quatloos.value() == 1.f); + LLUnit latinum_bars(quatloos); + ensure(latinum_bars.value() == 1.f / 4.f); + + latinum_bars = 256; + quatloos = latinum_bars; + ensure(quatloos.value() == 1024); + + LLUnit solari(quatloos); + ensure(solari.value() == 4096); + } + + // conversions across non-base units + template<> template<> + void units_object_t::test<3>() + { + LLUnit solari = 4.f; + LLUnit latinum_bars = solari; + ensure(latinum_bars.value() == 0.25f); + } + + // math operations + template<> template<> + void units_object_t::test<4>() + { + LLUnit quatloos = 1.f; + quatloos *= 4.f; + ensure(quatloos.value() == 4); + quatloos = quatloos * 2; + ensure(quatloos.value() == 8); + quatloos = 2.f * quatloos; + ensure(quatloos.value() == 16); + + quatloos += 4.f; + ensure(quatloos.value() == 20); + quatloos += 4; + ensure(quatloos.value() == 24); + quatloos = quatloos + 4; + ensure(quatloos.value() == 28); + quatloos = 4 + quatloos; + ensure(quatloos.value() == 32); + quatloos += quatloos * 3; + ensure(quatloos.value() == 128); + + quatloos -= quatloos / 4 * 3; + ensure(quatloos.value() == 32); + quatloos = quatloos - 8; + ensure(quatloos.value() == 24); + quatloos -= 4; + ensure(quatloos.value() == 20); + quatloos -= 4.f; + ensure(quatloos.value() == 16); + + quatloos *= 2.f; + ensure(quatloos.value() == 32); + quatloos = quatloos * 2.f; + ensure(quatloos.value() == 64); + quatloos = 0.5f * quatloos; + ensure(quatloos.value() == 32); + + quatloos /= 2.f; + ensure(quatloos.value() == 16); + quatloos = quatloos / 4; + ensure(quatloos.value() == 4); + + F32 ratio = quatloos / LLUnit(4.f); + ensure(ratio == 1); + + quatloos += LLUnit(4.f); + ensure(quatloos.value() == 5); + quatloos -= LLUnit(1.f); + ensure(quatloos.value() == 1); + } + + // implicit units + template<> template<> + void units_object_t::test<5>() + { + // 0-initialized + LLUnit quatloos(0); + // initialize implicit unit from explicit + LLUnitImplicit quatloos_implicit = quatloos + 1; + ensure(quatloos_implicit.value() == 1); + + // assign implicit to explicit, or perform math operations + quatloos = quatloos_implicit; + ensure(quatloos.value() == 1); + quatloos += quatloos_implicit; + ensure(quatloos.value() == 2); + + // math operations on implicits + quatloos_implicit = 1; + ensure(quatloos_implicit == 1); + + quatloos_implicit += 2; + ensure(quatloos_implicit == 3); + + quatloos_implicit *= 2; + ensure(quatloos_implicit == 6); + + quatloos_implicit -= 1; + ensure(quatloos_implicit == 5); + + quatloos_implicit /= 5; + ensure(quatloos_implicit == 1); + + quatloos_implicit = quatloos_implicit + 3 + quatloos_implicit; + ensure(quatloos_implicit == 5); + + quatloos_implicit = 10 - quatloos_implicit - 1; + ensure(quatloos_implicit == 4); + + quatloos_implicit = 2 * quatloos_implicit * 2; + ensure(quatloos_implicit == 16); + + F32 one_half = quatloos_implicit / (quatloos_implicit * 2); + ensure(one_half == 0.5f); + + // implicit conversion to POD + F32 float_val = quatloos_implicit; + ensure(float_val == 16); + + S32 int_val = quatloos_implicit; + ensure(int_val == 16); + } +} -- cgit v1.2.3 From 60b625588faec2472597dae50331b2ce95ce40a2 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 5 Jun 2013 19:57:07 -0700 Subject: BUILDFIX: build fixes for mac --- indra/llcommon/tests/llunits_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 2a941e8229..33e30f9688 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -33,9 +33,9 @@ namespace LLUnits { // using powers of 2 to allow strict floating point equality - struct Quatloos { typedef Quatloos base_unit_t; }; - LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum); - LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari); + LL_DECLARE_BASE_UNIT(Quatloos, "Quat"); + LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum, "Lat"); + LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari, "Sol"); } namespace tut -- cgit v1.2.3 From 9fd3af3c389ed491b515cbb5136b344b069913e4 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 13 Jun 2013 15:29:15 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics changed Units macros and argument order to make it more clear optimized units for integer types fixed merging of periodicrecordings...should eliminate duplicate entries in sceneloadmonitor history --- indra/llcommon/tests/llunits_test.cpp | 104 +++++++++++++++++----------------- 1 file changed, 53 insertions(+), 51 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 33e30f9688..747e8d1827 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -34,8 +34,8 @@ namespace LLUnits { // using powers of 2 to allow strict floating point equality LL_DECLARE_BASE_UNIT(Quatloos, "Quat"); - LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum, "Lat"); - LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari, "Sol"); + LL_DECLARE_DERIVED_UNIT(Latinum, "Lat", Quatloos, * 4); + LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Quatloos, / 4); } namespace tut @@ -53,105 +53,107 @@ namespace tut template<> template<> void units_object_t::test<1>() { - LLUnit float_quatloos; - ensure(float_quatloos.value() == 0.f); + LLUnit float_quatloos; + ensure(float_quatloos == 0.f); - LLUnit int_quatloos; - ensure(int_quatloos.value() == 0); + LLUnit int_quatloos; + ensure(int_quatloos == 0); int_quatloos = 42; - ensure(int_quatloos.value() == 42); + ensure(int_quatloos == 42); float_quatloos = int_quatloos; - ensure(float_quatloos.value() == 42.f); + ensure(float_quatloos == 42.f); int_quatloos = float_quatloos; - ensure(int_quatloos.value() == 42); + ensure(int_quatloos == 42); float_quatloos = 42.1f; - ensure(float_quatloos.value() == 42.1f); + ensure(float_quatloos == 42.1f); int_quatloos = float_quatloos; - ensure(int_quatloos.value() == 42); - LLUnit unsigned_int_quatloos(float_quatloos); - ensure(unsigned_int_quatloos.value() == 42); + ensure(int_quatloos == 42); + LLUnit unsigned_int_quatloos(float_quatloos); + ensure(unsigned_int_quatloos == 42); } // conversions to/from base unit template<> template<> void units_object_t::test<2>() { - LLUnit quatloos(1.f); - ensure(quatloos.value() == 1.f); - LLUnit latinum_bars(quatloos); - ensure(latinum_bars.value() == 1.f / 4.f); + LLUnit quatloos(1.f); + ensure(quatloos == 1.f); + LLUnit latinum_bars(quatloos); + ensure(latinum_bars == 1.f / 4.f); latinum_bars = 256; quatloos = latinum_bars; - ensure(quatloos.value() == 1024); + ensure(quatloos == 1024); - LLUnit solari(quatloos); - ensure(solari.value() == 4096); + LLUnit solari(quatloos); + ensure(solari == 4096); } // conversions across non-base units template<> template<> void units_object_t::test<3>() { - LLUnit solari = 4.f; - LLUnit latinum_bars = solari; - ensure(latinum_bars.value() == 0.25f); + LLUnit solari = 4.f; + LLUnit latinum_bars = solari; + ensure(latinum_bars == 0.25f); } // math operations template<> template<> void units_object_t::test<4>() { - LLUnit quatloos = 1.f; + LLUnit quatloos = 1.f; quatloos *= 4.f; - ensure(quatloos.value() == 4); + ensure(quatloos == 4); quatloos = quatloos * 2; - ensure(quatloos.value() == 8); + ensure(quatloos == 8); quatloos = 2.f * quatloos; - ensure(quatloos.value() == 16); + ensure(quatloos == 16); quatloos += 4.f; - ensure(quatloos.value() == 20); + ensure(quatloos == 20); quatloos += 4; - ensure(quatloos.value() == 24); + ensure(quatloos == 24); quatloos = quatloos + 4; - ensure(quatloos.value() == 28); + ensure(quatloos == 28); quatloos = 4 + quatloos; - ensure(quatloos.value() == 32); + ensure(quatloos == 32); quatloos += quatloos * 3; - ensure(quatloos.value() == 128); + ensure(quatloos == 128); quatloos -= quatloos / 4 * 3; - ensure(quatloos.value() == 32); + ensure(quatloos == 32); quatloos = quatloos - 8; - ensure(quatloos.value() == 24); + ensure(quatloos == 24); quatloos -= 4; - ensure(quatloos.value() == 20); + ensure(quatloos == 20); quatloos -= 4.f; - ensure(quatloos.value() == 16); + ensure(quatloos == 16); quatloos *= 2.f; - ensure(quatloos.value() == 32); + ensure(quatloos == 32); quatloos = quatloos * 2.f; - ensure(quatloos.value() == 64); + ensure(quatloos == 64); quatloos = 0.5f * quatloos; - ensure(quatloos.value() == 32); + ensure(quatloos == 32); quatloos /= 2.f; - ensure(quatloos.value() == 16); + ensure(quatloos == 16); quatloos = quatloos / 4; - ensure(quatloos.value() == 4); + ensure(quatloos == 4); - F32 ratio = quatloos / LLUnit(4.f); + F32 ratio = quatloos / LLUnit(4.f); + ensure(ratio == 1); + ratio = quatloos / LLUnit(16.f); ensure(ratio == 1); - quatloos += LLUnit(4.f); - ensure(quatloos.value() == 5); - quatloos -= LLUnit(1.f); - ensure(quatloos.value() == 1); + quatloos += LLUnit(4.f); + ensure(quatloos == 5); + quatloos -= LLUnit(1.f); + ensure(quatloos == 1); } // implicit units @@ -159,16 +161,16 @@ namespace tut void units_object_t::test<5>() { // 0-initialized - LLUnit quatloos(0); + LLUnit quatloos(0); // initialize implicit unit from explicit - LLUnitImplicit quatloos_implicit = quatloos + 1; - ensure(quatloos_implicit.value() == 1); + LLUnitImplicit quatloos_implicit = quatloos + 1; + ensure(quatloos_implicit == 1); // assign implicit to explicit, or perform math operations quatloos = quatloos_implicit; - ensure(quatloos.value() == 1); + ensure(quatloos == 1); quatloos += quatloos_implicit; - ensure(quatloos.value() == 2); + ensure(quatloos == 2); // math operations on implicits quatloos_implicit = 1; -- cgit v1.2.3 From 3f2de87340b1c831ea59e4a3ca960d49f343c9fd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 17 Jun 2013 01:18:21 -0700 Subject: SH-3931 WIP Interesting: Add graphs to visualize scene load metrics added getAs and setAs to LLUnit to make it clearer how you specify units removed accidental 0-based indexing of periodicRecording history... should now be consistently 1-based, with 0 accessing current active recording removed per frame timer updates of all historical timer bars in fast timer display added missing assignment operator to recordings --- indra/llcommon/tests/llunits_test.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 747e8d1827..04764f6c2f 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -35,7 +35,7 @@ namespace LLUnits // using powers of 2 to allow strict floating point equality LL_DECLARE_BASE_UNIT(Quatloos, "Quat"); LL_DECLARE_DERIVED_UNIT(Latinum, "Lat", Quatloos, * 4); - LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Quatloos, / 4); + LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Latinum, / 16); } namespace tut @@ -206,5 +206,11 @@ namespace tut S32 int_val = quatloos_implicit; ensure(int_val == 16); + + // conversion of implicits + LLUnitImplicit latinum_implicit(2); + ensure(latinum_implicit == 2); + + ensure(latinum_implicit * 2 == quatloos_implicit); } } -- cgit v1.2.3 From d136c4c29686c565b5a46503aa67a9c958b4145d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 18 Jun 2013 23:41:53 -0700 Subject: SH-4246 FIX interesting: fast timers significantly decreases framerate removed implicit flushes on reads from recorders for better performance made sure stack timers were updated on recorder deactivate faster rendering and better ui for fast timer view --- indra/llcommon/tests/llunits_test.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 04764f6c2f..a5df51f6de 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -56,6 +56,9 @@ namespace tut LLUnit float_quatloos; ensure(float_quatloos == 0.f); + LLUnit float_initialize_quatloos(1); + ensure(float_initialize_quatloos == 1.f); + LLUnit int_quatloos; ensure(int_quatloos == 0); -- cgit v1.2.3 From 4ff19b8f63f3814e98049064254323716f0fd422 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sat, 20 Jul 2013 09:41:55 -0700 Subject: removed debug spam fast timer data now resets on login --- indra/llcommon/tests/llunits_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index a5df51f6de..2074a4f4d9 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -164,7 +164,7 @@ namespace tut void units_object_t::test<5>() { // 0-initialized - LLUnit quatloos(0); + LLUnit quatloos; // initialize implicit unit from explicit LLUnitImplicit quatloos_implicit = quatloos + 1; ensure(quatloos_implicit == 1); -- cgit v1.2.3 From 7e7b9ddc32c1eac5f7269cce69f9321d3d17f577 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 24 Jul 2013 11:24:41 -0700 Subject: BUILDFIX fixed llunits unit test to use new unit declaration syntax --- indra/llcommon/tests/llunits_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 2074a4f4d9..e631f18ad4 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -34,8 +34,8 @@ namespace LLUnits { // using powers of 2 to allow strict floating point equality LL_DECLARE_BASE_UNIT(Quatloos, "Quat"); - LL_DECLARE_DERIVED_UNIT(Latinum, "Lat", Quatloos, * 4); - LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Latinum, / 16); + LL_DECLARE_DERIVED_UNIT(Quatloos, * 4, Latinum, "Lat"); + LL_DECLARE_DERIVED_UNIT(Latinum, / 16, Solari, "Sol"); } namespace tut -- cgit v1.2.3 From cc31b4ae7934010762b8aaaa7e190c74a1cd7820 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 12 Aug 2013 20:05:16 -0700 Subject: SH-4399 FIX: Interesting: Texture console MB Bound 0/384 and texture queue bounces once per second SH-4346 FIX: Interesting: some integer Statistics are displayed as floating point after crossing region boundary made llerrs/infos/etc properly variadic wrt tags LL_INFOS("A", "B", "C") works, for example fixed unit tests remove llsimplestat --- indra/llcommon/tests/llunits_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index e631f18ad4..ff981ca2ff 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -53,6 +53,7 @@ namespace tut template<> template<> void units_object_t::test<1>() { + LL_INFOS("test") << "Test" << LL_ENDL; LLUnit float_quatloos; ensure(float_quatloos == 0.f); @@ -93,6 +94,11 @@ namespace tut LLUnit solari(quatloos); ensure(solari == 4096); + + // division of integral unit + LLUnit single_quatloo(1); + LLUnit quarter_latinum = single_quatloo; + ensure(quarter_latinum == 0.25f); } // conversions across non-base units -- cgit v1.2.3 From 9faaa28f4445425e8c5b7b002faffbe0365b905d Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 13 Aug 2013 18:33:07 -0700 Subject: SH-4346 FIX Interesting: some integer Statistics are displayed as floating point after crossing region boundary fine-tuned heuristics for switching between mean and current values in stat bar display added comments to LLUnits unit test --- indra/llcommon/tests/llunits_test.cpp | 76 ++++++++++++++--------------------- 1 file changed, 31 insertions(+), 45 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index ff981ca2ff..b0309585aa 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -53,30 +53,29 @@ namespace tut template<> template<> void units_object_t::test<1>() { - LL_INFOS("test") << "Test" << LL_ENDL; LLUnit float_quatloos; - ensure(float_quatloos == 0.f); + ensure("default float unit is zero", float_quatloos == 0.f); LLUnit float_initialize_quatloos(1); - ensure(float_initialize_quatloos == 1.f); + ensure("non-zero initialized unit", float_initialize_quatloos == 1.f); LLUnit int_quatloos; - ensure(int_quatloos == 0); + ensure("default int unit is zero", int_quatloos == 0); int_quatloos = 42; - ensure(int_quatloos == 42); + ensure("int assignment is preserved", int_quatloos == 42); float_quatloos = int_quatloos; - ensure(float_quatloos == 42.f); + ensure("float assignment from int preserves value", float_quatloos == 42.f); int_quatloos = float_quatloos; - ensure(int_quatloos == 42); + ensure("int assignment from float preserves value", int_quatloos == 42); float_quatloos = 42.1f; - ensure(float_quatloos == 42.1f); int_quatloos = float_quatloos; - ensure(int_quatloos == 42); + ensure("int units truncate float units on assignment", int_quatloos == 42); + LLUnit unsigned_int_quatloos(float_quatloos); - ensure(unsigned_int_quatloos == 42); + ensure("unsigned int can be initialized from signed int", unsigned_int_quatloos == 42); } // conversions to/from base unit @@ -84,36 +83,35 @@ namespace tut void units_object_t::test<2>() { LLUnit quatloos(1.f); - ensure(quatloos == 1.f); LLUnit latinum_bars(quatloos); - ensure(latinum_bars == 1.f / 4.f); + ensure("conversion between units is automatic via initialization", latinum_bars == 1.f / 4.f); latinum_bars = 256; quatloos = latinum_bars; - ensure(quatloos == 1024); - - LLUnit solari(quatloos); - ensure(solari == 4096); + ensure("conversion between units is automatic via assignment, and bidirectional", quatloos == 1024); - // division of integral unit LLUnit single_quatloo(1); LLUnit quarter_latinum = single_quatloo; - ensure(quarter_latinum == 0.25f); + ensure("division of integer unit preserves fractional values when converted to float unit", quarter_latinum == 0.25f); } // conversions across non-base units template<> template<> void units_object_t::test<3>() { - LLUnit solari = 4.f; + LLUnit quatloos(1024); + LLUnit solari(quatloos); + ensure("conversions can work between indirectly related units: Quatloos -> Latinum -> Solari", solari == 4096); + LLUnit latinum_bars = solari; - ensure(latinum_bars == 0.25f); + ensure("Non base units can be converted between each other", latinum_bars == 256); } // math operations template<> template<> void units_object_t::test<4>() { + // exercise math operations LLUnit quatloos = 1.f; quatloos *= 4.f; ensure(quatloos == 4); @@ -142,44 +140,34 @@ namespace tut quatloos -= 4.f; ensure(quatloos == 16); - quatloos *= 2.f; - ensure(quatloos == 32); - quatloos = quatloos * 2.f; - ensure(quatloos == 64); - quatloos = 0.5f * quatloos; - ensure(quatloos == 32); - quatloos /= 2.f; - ensure(quatloos == 16); + ensure(quatloos == 8); quatloos = quatloos / 4; - ensure(quatloos == 4); + ensure(quatloos == 2); - F32 ratio = quatloos / LLUnit(4.f); + F32 ratio = quatloos / LLUnit(2.f); ensure(ratio == 1); - ratio = quatloos / LLUnit(16.f); + ratio = quatloos / LLUnit(8.f); ensure(ratio == 1); - quatloos += LLUnit(4.f); - ensure(quatloos == 5); + quatloos += LLUnit(8.f); + ensure(quatloos == 4); quatloos -= LLUnit(1.f); - ensure(quatloos == 1); + ensure(quatloos == 0); } // implicit units template<> template<> void units_object_t::test<5>() { - // 0-initialized LLUnit quatloos; - // initialize implicit unit from explicit LLUnitImplicit quatloos_implicit = quatloos + 1; - ensure(quatloos_implicit == 1); + ensure("can initialize implicit unit from explicit", quatloos_implicit == 1); - // assign implicit to explicit, or perform math operations quatloos = quatloos_implicit; - ensure(quatloos == 1); + ensure("can assign implicit unit to explicit unit", quatloos == 1); quatloos += quatloos_implicit; - ensure(quatloos == 2); + ensure("can perform math operation using mixture of implicit and explicit units", quatloos == 2); // math operations on implicits quatloos_implicit = 1; @@ -211,15 +199,13 @@ namespace tut // implicit conversion to POD F32 float_val = quatloos_implicit; - ensure(float_val == 16); + ensure("implicit units convert implicitly to regular values", float_val == 16); S32 int_val = quatloos_implicit; - ensure(int_val == 16); + ensure("implicit units convert implicitly to regular values", int_val == 16); // conversion of implicits LLUnitImplicit latinum_implicit(2); - ensure(latinum_implicit == 2); - - ensure(latinum_implicit * 2 == quatloos_implicit); + ensure("implicit units of different types are comparable", latinum_implicit * 2 == quatloos_implicit); } } -- cgit v1.2.3 From 26581404e426b00cd0a07c38b5cb858d5d5faa28 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 14 Aug 2013 11:51:49 -0700 Subject: BUILDFIX: added header for numeric_limits support on gcc added convenience types for units F32Seconds, etc. --- indra/llcommon/tests/llunits_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index b0309585aa..8546bcbc54 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -112,7 +112,7 @@ namespace tut void units_object_t::test<4>() { // exercise math operations - LLUnit quatloos = 1.f; + LLUnit quatloos(1.f); quatloos *= 4.f; ensure(quatloos == 4); quatloos = quatloos * 2; -- cgit v1.2.3 From 612892b45a3413b16e40c49d3bfde77a4ca927fd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 18 Aug 2013 22:30:27 -0700 Subject: SH-4433 WIP: Interesting: Statistics > Ping Sim is always 0 ms continued conversion to units system made units perform type promotion correctly and preserve type in arithmetic e.g. can now do LLVector3 in units added typedefs for remaining common unit types, including implicits --- indra/llcommon/tests/llunits_test.cpp | 126 ++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 44 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 8546bcbc54..a8e9be86ca 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -38,6 +38,13 @@ namespace LLUnits LL_DECLARE_DERIVED_UNIT(Latinum, / 16, Solari, "Sol"); } +typedef LLUnit F32Quatloos; +typedef LLUnit S32Quatloos; +typedef LLUnit F32Latinum; +typedef LLUnit S32Latinum; +typedef LLUnit F32Solari; +typedef LLUnit S32Solari; + namespace tut { using namespace LLUnits; @@ -54,28 +61,28 @@ namespace tut void units_object_t::test<1>() { LLUnit float_quatloos; - ensure("default float unit is zero", float_quatloos == 0.f); + ensure("default float unit is zero", float_quatloos == F32Quatloos(0.f)); LLUnit float_initialize_quatloos(1); - ensure("non-zero initialized unit", float_initialize_quatloos == 1.f); + ensure("non-zero initialized unit", float_initialize_quatloos == F32Quatloos(1.f)); LLUnit int_quatloos; - ensure("default int unit is zero", int_quatloos == 0); + ensure("default int unit is zero", int_quatloos == S32Quatloos(0)); - int_quatloos = 42; - ensure("int assignment is preserved", int_quatloos == 42); + int_quatloos = S32Quatloos(42); + ensure("int assignment is preserved", int_quatloos == S32Quatloos(42)); float_quatloos = int_quatloos; - ensure("float assignment from int preserves value", float_quatloos == 42.f); + ensure("float assignment from int preserves value", float_quatloos == F32Quatloos(42.f)); int_quatloos = float_quatloos; - ensure("int assignment from float preserves value", int_quatloos == 42); + ensure("int assignment from float preserves value", int_quatloos == S32Quatloos(42)); - float_quatloos = 42.1f; + float_quatloos = F32Quatloos(42.1f); int_quatloos = float_quatloos; - ensure("int units truncate float units on assignment", int_quatloos == 42); + ensure("int units truncate float units on assignment", int_quatloos == S32Quatloos(42)); LLUnit unsigned_int_quatloos(float_quatloos); - ensure("unsigned int can be initialized from signed int", unsigned_int_quatloos == 42); + ensure("unsigned int can be initialized from signed int", unsigned_int_quatloos == S32Quatloos(42)); } // conversions to/from base unit @@ -84,15 +91,15 @@ namespace tut { LLUnit quatloos(1.f); LLUnit latinum_bars(quatloos); - ensure("conversion between units is automatic via initialization", latinum_bars == 1.f / 4.f); + ensure("conversion between units is automatic via initialization", latinum_bars == F32Latinum(1.f / 4.f)); - latinum_bars = 256; + latinum_bars = S32Latinum(256); quatloos = latinum_bars; - ensure("conversion between units is automatic via assignment, and bidirectional", quatloos == 1024); + ensure("conversion between units is automatic via assignment, and bidirectional", quatloos == S32Quatloos(1024)); LLUnit single_quatloo(1); LLUnit quarter_latinum = single_quatloo; - ensure("division of integer unit preserves fractional values when converted to float unit", quarter_latinum == 0.25f); + ensure("division of integer unit preserves fractional values when converted to float unit", quarter_latinum == F32Latinum(0.25f)); } // conversions across non-base units @@ -101,10 +108,10 @@ namespace tut { LLUnit quatloos(1024); LLUnit solari(quatloos); - ensure("conversions can work between indirectly related units: Quatloos -> Latinum -> Solari", solari == 4096); + ensure("conversions can work between indirectly related units: Quatloos -> Latinum -> Solari", solari == S32Solari(4096)); LLUnit latinum_bars = solari; - ensure("Non base units can be converted between each other", latinum_bars == 256); + ensure("Non base units can be converted between each other", latinum_bars == S32Latinum(256)); } // math operations @@ -114,36 +121,36 @@ namespace tut // exercise math operations LLUnit quatloos(1.f); quatloos *= 4.f; - ensure(quatloos == 4); + ensure(quatloos == S32Quatloos(4)); quatloos = quatloos * 2; - ensure(quatloos == 8); + ensure(quatloos == S32Quatloos(8)); quatloos = 2.f * quatloos; - ensure(quatloos == 16); - - quatloos += 4.f; - ensure(quatloos == 20); - quatloos += 4; - ensure(quatloos == 24); - quatloos = quatloos + 4; - ensure(quatloos == 28); - quatloos = 4 + quatloos; - ensure(quatloos == 32); + ensure(quatloos == S32Quatloos(16)); + + quatloos += F32Quatloos(4.f); + ensure(quatloos == S32Quatloos(20)); + quatloos += S32Quatloos(4); + ensure(quatloos == S32Quatloos(24)); + quatloos = quatloos + S32Quatloos(4); + ensure(quatloos == S32Quatloos(28)); + quatloos = S32Quatloos(4) + quatloos; + ensure(quatloos == S32Quatloos(32)); quatloos += quatloos * 3; - ensure(quatloos == 128); + ensure(quatloos == S32Quatloos(128)); quatloos -= quatloos / 4 * 3; - ensure(quatloos == 32); - quatloos = quatloos - 8; - ensure(quatloos == 24); - quatloos -= 4; - ensure(quatloos == 20); - quatloos -= 4.f; - ensure(quatloos == 16); + ensure(quatloos == S32Quatloos(32)); + quatloos = quatloos - S32Quatloos(8); + ensure(quatloos == S32Quatloos(24)); + quatloos -= S32Quatloos(4); + ensure(quatloos == S32Quatloos(20)); + quatloos -= F32Quatloos(4.f); + ensure(quatloos == S32Quatloos(16)); quatloos /= 2.f; - ensure(quatloos == 8); + ensure(quatloos == S32Quatloos(8)); quatloos = quatloos / 4; - ensure(quatloos == 2); + ensure(quatloos == S32Quatloos(2)); F32 ratio = quatloos / LLUnit(2.f); ensure(ratio == 1); @@ -151,23 +158,54 @@ namespace tut ensure(ratio == 1); quatloos += LLUnit(8.f); - ensure(quatloos == 4); + ensure(quatloos == S32Quatloos(4)); quatloos -= LLUnit(1.f); - ensure(quatloos == 0); + ensure(quatloos == S32Quatloos(0)); } - // implicit units + // comparison operators template<> template<> void units_object_t::test<5>() + { + LLUnit quatloos(1); + ensure("can perform less than comparison against same type", quatloos < S32Quatloos(2)); + ensure("can perform less than comparison against different storage type", quatloos < F32Quatloos(2.f)); + ensure("can perform less than comparison against different units", quatloos < S32Latinum(5)); + ensure("can perform less than comparison against different storage type and units", quatloos < F32Latinum(5.f)); + + ensure("can perform greater than comparison against same type", quatloos > S32Quatloos(0)); + ensure("can perform greater than comparison against different storage type", quatloos > F32Quatloos(0.f)); + ensure("can perform greater than comparison against different units", quatloos > S32Latinum(0)); + ensure("can perform greater than comparison against different storage type and units", quatloos > F32Latinum(0.f)); + + } + + bool accept_explicit_quatloos(S32Quatloos q) + { + return true; + } + + // signature compatibility + template<> template<> + void units_object_t::test<6>() + { + S32Quatloos quatloos(1); + ensure("can pass unit values as argument", accept_explicit_quatloos(S32Quatloos(1))); + ensure("can pass unit values as argument", accept_explicit_quatloos(quatloos)); + } + + // implicit units + template<> template<> + void units_object_t::test<7>() { LLUnit quatloos; - LLUnitImplicit quatloos_implicit = quatloos + 1; + LLUnitImplicit quatloos_implicit = quatloos + S32Quatloos(1); ensure("can initialize implicit unit from explicit", quatloos_implicit == 1); quatloos = quatloos_implicit; - ensure("can assign implicit unit to explicit unit", quatloos == 1); + ensure("can assign implicit unit to explicit unit", quatloos == S32Quatloos(1)); quatloos += quatloos_implicit; - ensure("can perform math operation using mixture of implicit and explicit units", quatloos == 2); + ensure("can perform math operation using mixture of implicit and explicit units", quatloos == S32Quatloos(2)); // math operations on implicits quatloos_implicit = 1; -- cgit v1.2.3 From 2c6bc5afa59a88136fd6de4ebf0cb99ea7cdef3f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Wed, 21 Aug 2013 14:06:57 -0700 Subject: SH-4433 WIP Interesting: Statistics > Ping Sim is always 0 ms made getPrimaryAccumulator return a reference since it was an always non-null pointer changed unit conversion to perform lazy division in order to avoid truncation of timer values --- indra/llcommon/tests/llunits_test.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index a8e9be86ca..b8aef9d15e 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -38,12 +38,9 @@ namespace LLUnits LL_DECLARE_DERIVED_UNIT(Latinum, / 16, Solari, "Sol"); } -typedef LLUnit F32Quatloos; -typedef LLUnit S32Quatloos; -typedef LLUnit F32Latinum; -typedef LLUnit S32Latinum; -typedef LLUnit F32Solari; -typedef LLUnit S32Solari; +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Quatloos); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Latinum); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Solari); namespace tut { @@ -83,6 +80,15 @@ namespace tut LLUnit unsigned_int_quatloos(float_quatloos); ensure("unsigned int can be initialized from signed int", unsigned_int_quatloos == S32Quatloos(42)); + + S32Solari int_solari(1); + + float_quatloos = int_solari; + ensure("fractional units are preserved in conversion from integer to float type", float_quatloos == F32Quatloos(0.25f)); + + int_quatloos = S32Quatloos(1); + F32Solari float_solari = int_quatloos; + ensure("can convert with fractional intermediates from integer to float type", float_solari == F32Solari(4.f)); } // conversions to/from base unit @@ -185,6 +191,11 @@ namespace tut return true; } + bool accept_implicit_quatloos(S32Quatloos q) + { + return true; + } + // signature compatibility template<> template<> void units_object_t::test<6>() -- cgit v1.2.3 From cf014375b8b408d58bd35deb4e58e4369fb3bf62 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 22 Aug 2013 14:21:16 -0700 Subject: SH-4433 FIX: Interesting: Statistics > Ping Sim is always 0 ms removed bad assert fixed precision issues during int->unsigned int conversions and vice versa --- indra/llcommon/tests/llunits_test.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index b8aef9d15e..292c6122af 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -257,4 +257,20 @@ namespace tut LLUnitImplicit latinum_implicit(2); ensure("implicit units of different types are comparable", latinum_implicit * 2 == quatloos_implicit); } + + // precision tests + template<> template<> + void units_object_t::test<8>() + { + U32Bytes max_bytes(U32_MAX); + S32Megabytes mega_bytes = max_bytes; + ensure("max available precision is used when converting units", mega_bytes == (S32Megabytes)4095); + + mega_bytes = (S32Megabytes)-5 + (U32Megabytes)1; + ensure("can mix signed and unsigned in units addition", mega_bytes == (S32Megabytes)-4); + + mega_bytes = (U32Megabytes)5 + (S32Megabytes)-1; + ensure("can mix unsigned and signed in units addition", mega_bytes == (S32Megabytes)4); + + } } -- cgit v1.2.3 From 8535b87544cc2e71896716a4cd1c3c2445ff4af0 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 26 Aug 2013 18:00:24 -0700 Subject: removed some unecessary template parameters from LLUnit member functions forced unit conversion code to inline unit conversion now no longer converts all the way to base and back, but tries to find equivalent units as early as possible fixed another llinfos instance scene monitor now outputs n/a for invalid samples --- indra/llcommon/tests/llunits_test.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 292c6122af..31d4f86159 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -271,6 +271,5 @@ namespace tut mega_bytes = (U32Megabytes)5 + (S32Megabytes)-1; ensure("can mix unsigned and signed in units addition", mega_bytes == (S32Megabytes)4); - } } -- cgit v1.2.3 From a7aed07a5b620977fb74e4070e432eef01d11d3c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 27 Aug 2013 13:41:19 -0700 Subject: broke out llunit.h into llunittype.h and llunits.h for unit declarations changed unit declarations macros to make a lot more sense --- indra/llcommon/tests/llunits_test.cpp | 73 +++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 31d4f86159..5a18603e4e 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -27,15 +27,15 @@ #include "linden_common.h" -#include "llunit.h" +#include "llunits.h" #include "../test/lltut.h" namespace LLUnits { // using powers of 2 to allow strict floating point equality LL_DECLARE_BASE_UNIT(Quatloos, "Quat"); - LL_DECLARE_DERIVED_UNIT(Quatloos, * 4, Latinum, "Lat"); - LL_DECLARE_DERIVED_UNIT(Latinum, / 16, Solari, "Sol"); + LL_DECLARE_DERIVED_UNIT(Latinum, "Lat", Quatloos, / 4); + LL_DECLARE_DERIVED_UNIT(Solari, "Sol", Latinum, * 16); } LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Quatloos); @@ -256,6 +256,12 @@ namespace tut // conversion of implicits LLUnitImplicit latinum_implicit(2); ensure("implicit units of different types are comparable", latinum_implicit * 2 == quatloos_implicit); + + quatloos_implicit += F32Quatloos(10); + ensure("can add-assign explicit units", quatloos_implicit == 26); + + quatloos_implicit -= F32Quatloos(10); + ensure("can subtract-assign explicit units", quatloos_implicit == 16); } // precision tests @@ -272,4 +278,65 @@ namespace tut mega_bytes = (U32Megabytes)5 + (S32Megabytes)-1; ensure("can mix unsigned and signed in units addition", mega_bytes == (S32Megabytes)4); } + + // default units + template<> template<> + void units_object_t::test<9>() + { + U32Gigabytes GB(1); + U32Megabytes MB(GB); + U32Kilobytes KB(GB); + U32Bytes B(GB); + + ensure("GB -> MB conversion", MB.value() == 1024); + ensure("GB -> KB conversion", KB.value() == 1024 * 1024); + ensure("GB -> B conversion", B.value() == 1024 * 1024 * 1024); + + KB = U32Kilobytes(1); + U32Kilobits Kb(KB); + U32Bits b(KB); + ensure("KB -> Kb conversion", Kb.value() == 8); + ensure("KB -> b conversion", b.value() == 8 * 1024); + + U32Days days(1); + U32Hours hours(days); + U32Minutes minutes(days); + U32Seconds seconds(days); + U32Milliseconds ms(days); + + ensure("days -> hours conversion", hours.value() == 24); + ensure("days -> minutes conversion", minutes.value() == 24 * 60); + ensure("days -> seconds conversion", seconds.value() == 24 * 60 * 60); + ensure("days -> ms conversion", ms.value() == 24 * 60 * 60 * 1000); + + U32Kilometers km(1); + U32Meters m(km); + U32Centimeters cm(km); + U32Millimeters mm(km); + + ensure("km -> m conversion", m.value() == 1000); + ensure("km -> cm conversion", cm.value() == 1000 * 100); + ensure("km -> mm conversion", mm.value() == 1000 * 1000); + + U32Gigahertz GHz(1); + U32Megahertz MHz(GHz); + U32Kilohertz KHz(GHz); + U32Hertz Hz(GHz); + + ensure("GHz -> MHz conversion", MHz.value() == 1000); + ensure("GHz -> KHz conversion", KHz.value() == 1000 * 1000); + ensure("GHz -> Hz conversion", Hz.value() == 1000 * 1000 * 1000); + + F32Radians rad(6.2831853071795f); + F32Degrees deg(rad); + ensure("radians -> degrees conversion", deg.value() > 359 && deg.value() < 361); + + F32Percent percent(50); + F32Ratio ratio(percent); + ensure("percent -> ratio conversion", ratio.value() == 0.5f); + + U32Kilotriangles ktris(1); + U32Triangles tris(ktris); + ensure("kilotriangles -> triangles conversion", tris.value() == 1000); + } } -- cgit v1.2.3 From 00bd492b30f0dcb49d354be74e6e9a312a84863f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 27 Aug 2013 16:36:36 -0700 Subject: got linear unit conversions (like fahrenheit <-> celsius) working correctly further optimizations for codegen --- indra/llcommon/tests/llunits_test.cpp | 40 +++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 5a18603e4e..59876ce3b4 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -42,6 +42,18 @@ LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Quatloos); LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Latinum); LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Solari); +namespace LLUnits +{ + LL_DECLARE_BASE_UNIT(Celcius, "c"); + LL_DECLARE_DERIVED_UNIT(Fahrenheit, "f", Celcius, * 9 / 5 + 32); + LL_DECLARE_DERIVED_UNIT(Kelvin, "k", Celcius, + 273.15f); +} + +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Celcius); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Fahrenheit); +LL_DECLARE_UNIT_TYPEDEFS(LLUnits, Kelvin); + + namespace tut { using namespace LLUnits; @@ -328,8 +340,8 @@ namespace tut ensure("GHz -> Hz conversion", Hz.value() == 1000 * 1000 * 1000); F32Radians rad(6.2831853071795f); - F32Degrees deg(rad); - ensure("radians -> degrees conversion", deg.value() > 359 && deg.value() < 361); + S32Degrees deg(rad); + ensure("radians -> degrees conversion", deg.value() == 360); F32Percent percent(50); F32Ratio ratio(percent); @@ -339,4 +351,28 @@ namespace tut U32Triangles tris(ktris); ensure("kilotriangles -> triangles conversion", tris.value() == 1000); } + + bool value_near(F32 value, F32 target, F32 threshold) + { + return fabsf(value - target) < threshold; + } + + // linear transforms + template<> template<> + void units_object_t::test<10>() + { + F32Celcius float_celcius(100); + F32Fahrenheit float_fahrenheit(float_celcius); + ensure("floating point celcius -> fahrenheit conversion using linear transform", value_near(float_fahrenheit.value(), 212, 0.1f) ); + + float_celcius = float_fahrenheit; + ensure("floating point fahrenheit -> celcius conversion using linear transform (round trip)", value_near(float_celcius.value(), 100.f, 0.1f) ); + + S32Celcius int_celcius(100); + S32Fahrenheit int_fahrenheit(int_celcius); + ensure("integer celcius -> fahrenheit conversion using linear transform", int_fahrenheit.value() == 212); + + int_celcius = int_fahrenheit; + ensure("integer fahrenheit -> celcius conversion using linear transform (round trip)", int_celcius.value() == 100); + } } -- cgit v1.2.3 From 25e2fbe419655b2f8ce22dbafa1de6bc655b1567 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 27 Aug 2013 18:08:32 -0700 Subject: got comparisons between implicit and explicit units working right --- indra/llcommon/tests/llunits_test.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index 59876ce3b4..d5b7c08672 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -274,6 +274,16 @@ namespace tut quatloos_implicit -= F32Quatloos(10); ensure("can subtract-assign explicit units", quatloos_implicit == 16); + + // comparisons + ensure("can compare greater than implicit unit", quatloos_implicit > F32QuatloosImplicit(0.f)); + ensure("can compare greater than non-implicit unit", quatloos_implicit > F32Quatloos(0.f)); + ensure("can compare greater than or equal to implicit unit", quatloos_implicit >= F32QuatloosImplicit(0.f)); + ensure("can compare greater than or equal to non-implicit unit", quatloos_implicit >= F32Quatloos(0.f)); + ensure("can compare less than implicit unit", quatloos_implicit < F32QuatloosImplicit(0.f)); + ensure("can compare less than non-implicit unit", quatloos_implicit < F32Quatloos(0.f)); + ensure("can compare less than or equal to implicit unit", quatloos_implicit <= F32QuatloosImplicit(0.f)); + ensure("can compare less than or equal to non-implicit unit", quatloos_implicit <= F32Quatloos(0.f)); } // precision tests -- cgit v1.2.3 From 5ddd5694b54150b50a77627112ea98a4a94d0e46 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Tue, 27 Aug 2013 18:59:32 -0700 Subject: fixed bad logic in unit test --- indra/llcommon/tests/llunits_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llcommon/tests/llunits_test.cpp') diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp index d5b7c08672..57cf9810af 100644 --- a/indra/llcommon/tests/llunits_test.cpp +++ b/indra/llcommon/tests/llunits_test.cpp @@ -280,10 +280,10 @@ namespace tut ensure("can compare greater than non-implicit unit", quatloos_implicit > F32Quatloos(0.f)); ensure("can compare greater than or equal to implicit unit", quatloos_implicit >= F32QuatloosImplicit(0.f)); ensure("can compare greater than or equal to non-implicit unit", quatloos_implicit >= F32Quatloos(0.f)); - ensure("can compare less than implicit unit", quatloos_implicit < F32QuatloosImplicit(0.f)); - ensure("can compare less than non-implicit unit", quatloos_implicit < F32Quatloos(0.f)); - ensure("can compare less than or equal to implicit unit", quatloos_implicit <= F32QuatloosImplicit(0.f)); - ensure("can compare less than or equal to non-implicit unit", quatloos_implicit <= F32Quatloos(0.f)); + ensure("can compare less than implicit unit", quatloos_implicit < F32QuatloosImplicit(20.f)); + ensure("can compare less than non-implicit unit", quatloos_implicit < F32Quatloos(20.f)); + ensure("can compare less than or equal to implicit unit", quatloos_implicit <= F32QuatloosImplicit(20.f)); + ensure("can compare less than or equal to non-implicit unit", quatloos_implicit <= F32Quatloos(20.f)); } // precision tests -- cgit v1.2.3