File: math_util_test.cpp

package info (click to toggle)
megaglest 3.13.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,844 kB
  • ctags: 18,191
  • sloc: cpp: 144,280; ansic: 11,861; sh: 3,233; perl: 1,904; python: 1,751; objc: 142; asm: 42; makefile: 24
file content (68 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// ==============================================================
//	This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
//	Copyright (C) 2013 Mark Vejvoda
//
//	You can redistribute this code 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
// ==============================================================

#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include "math_util.h"

#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

using namespace Shared::Graphics;

//
// Tests for math_util
//
class MathUtilTest : public CppUnit::TestFixture {
	// Register the suite of tests for this fixture
	CPPUNIT_TEST_SUITE( MathUtilTest );

	CPPUNIT_TEST( test_RoundFloat );

	CPPUNIT_TEST_SUITE_END();
	// End of Fixture registration

public:

	void test_RoundFloat() {
		float value1 = truncateDecimal<float>(1.123456f, 6);
		CPPUNIT_ASSERT_EQUAL( 1.123456f, value1 );

		value1 = truncateDecimal<float>(1.123456f, 5);
		CPPUNIT_ASSERT_EQUAL( 1.12345f, value1 );

		value1 = truncateDecimal<float>(1.123456f, 4);
		CPPUNIT_ASSERT_EQUAL( 1.1234f, value1 );

		value1 = truncateDecimal<float>(1.123456f, 3);
		CPPUNIT_ASSERT_EQUAL( 1.123f, value1 );

		value1 = truncateDecimal<float>(1.123456f, 2);
		CPPUNIT_ASSERT_EQUAL( 1.12f, value1 );

		value1 = truncateDecimal<float>(1.123456f, 1);
		CPPUNIT_ASSERT_EQUAL( 1.1f, value1 );

//		int32 value2 = xs_CRoundToInt(1.123456f);
//		CPPUNIT_ASSERT_EQUAL( (int32)1, value2 );
//
//		value2 = xs_CRoundToInt(1.523456f);
//		CPPUNIT_ASSERT_EQUAL( (int32)2, value2 );
	}
};


// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( MathUtilTest );
//