PageRenderTime 25ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llmath/tests/llmodularmath_test.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 76 lines | 39 code | 7 blank | 30 comment | 0 complexity | 8d182c6e09e50a391fcc65d1cc0ea16b MD5 | raw file
 1/**
 2 * @file modularmath_test.cpp
 3 * @author babbage
 4 * @date 2008-09
 5 * @brief llmodularmath tests
 6 *
 7 * $LicenseInfo:firstyear=2007&license=viewerlgpl$
 8 * Second Life Viewer Source Code
 9 * Copyright (C) 2010, Linden Research, Inc.
10 * 
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation;
14 * version 2.1 of the License only.
15 * 
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 * Lesser General Public License for more details.
20 * 
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 * 
25 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
26 * $/LicenseInfo$
27 */
28 
29#include "linden_common.h"
30
31#include "../llmodularmath.h"
32
33#include "../test/lltut.h"
34
35namespace tut
36{
37	struct modularmath_data
38	{
39	};
40	typedef test_group<modularmath_data> modularmath_test;
41	typedef modularmath_test::object modularmath_object;
42	tut::modularmath_test modularmath_testcase("LLModularMath");
43
44	template<> template<>
45	void modularmath_object::test<1>()
46	{
47		// lhs < rhs
48		const U32 lhs = 0x000001;
49		const U32 rhs = 0xFFFFFF;
50		const U32 width = 24;
51		U32 result = LLModularMath::subtract<width>(lhs, rhs); 
52		ensure_equals("diff(0x000001, 0xFFFFFF, 24)", result, 2);
53	}
54
55	template<> template<>
56	void modularmath_object::test<2>()
57	{
58		// lhs > rhs
59		const U32 lhs = 0x000002;
60		const U32 rhs = 0x000001;
61		const U32 width = 24;
62		U32 result = LLModularMath::subtract<width>(lhs, rhs); 
63		ensure_equals("diff(0x000002, 0x000001, 24)", result, 1);
64	}
65
66	template<> template<>
67	void modularmath_object::test<3>()
68	{
69		// lhs == rhs
70		const U32 lhs = 0xABCDEF;
71		const U32 rhs = 0xABCDEF;
72		const U32 width = 24;
73		U32 result = LLModularMath::subtract<width>(lhs, rhs); 
74		ensure_equals("diff(0xABCDEF, 0xABCDEF, 24)", result, 0);
75	}	
76}