aboutsummaryrefslogtreecommitdiff
path: root/EASTL/test/source/TestNumericLimits.cpp
blob: 440715b07fb7c607bf12c50d3e9e05f69750e858 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Electronic Arts Inc. All rights reserved.
/////////////////////////////////////////////////////////////////////////////


#include "EASTLTest.h"
#include <EASTL/numeric_limits.h>


struct NonNumericType
{
	NonNumericType(int value) : mValue(value){}
	bool operator==(int value) const { return mValue == value; }
	int mValue; // This exists for the purpose of allowing the type to act like a number and allow the test logic below to work.
};


///////////////////////////////////////////////////////////////////////////////
// TestNumericLimits
//
int TestNumericLimits()
{
	int nErrorCount = 0;

	// To consider: Some day when we get more time, make a big table-driven set of 
	// expected results to all member variables and function calls.

	// Test a type that is not numeric,.
	EATEST_VERIFY(!eastl::numeric_limits<NonNumericType>::is_bounded);
	EATEST_VERIFY( eastl::numeric_limits<NonNumericType>::max() == 0);

	EATEST_VERIFY(!eastl::numeric_limits<const NonNumericType>::is_bounded);
	EATEST_VERIFY( eastl::numeric_limits<const NonNumericType>::max() == 0);

	EATEST_VERIFY(!eastl::numeric_limits<volatile NonNumericType>::is_bounded);
	EATEST_VERIFY( eastl::numeric_limits<volatile NonNumericType>::max() == 0);

	EATEST_VERIFY(!eastl::numeric_limits<const volatile NonNumericType>::is_bounded);
	EATEST_VERIFY( eastl::numeric_limits<const volatile NonNumericType>::max() == 0);

	// Test bool in all const-volatile variants.
	EATEST_VERIFY(eastl::numeric_limits<bool>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<bool>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<const bool>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<const bool>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<volatile bool>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<volatile bool>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<const volatile bool>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<const volatile bool>::max() != 0);

	// Do basic tests of the remaining types.
	EATEST_VERIFY(eastl::numeric_limits<char>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<char>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<unsigned char>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<unsigned char>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<signed char>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<signed char>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<wchar_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<wchar_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<char16_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<char16_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<char32_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<char32_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<unsigned short>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<unsigned short>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<signed short>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<signed short>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<unsigned int>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<unsigned int>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<signed int>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<signed int>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<unsigned long>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<unsigned long>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<signed long>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<signed long>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<unsigned long long>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<unsigned long long>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<signed long long>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<signed long long>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<float>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<float>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<double>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<double>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<long double>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<long double>::max() != 0);

	// We don't yet have a generic global way to identify what the name of the supported 128 bit type is. 
	// We just happen to know that for gcc/clang it is __int128.
	#if (EA_COMPILER_INTMAX_SIZE >= 16) && (defined(EA_COMPILER_GNUC) || defined(EA_COMPILER_CLANG)) // If __int128_t/__uint128_t is supported...
		EATEST_VERIFY(eastl::numeric_limits<__uint128_t>::is_bounded);
		EATEST_VERIFY(eastl::numeric_limits<__uint128_t>::max() != 0);

		EATEST_VERIFY(eastl::numeric_limits<__int128_t>::is_bounded);
		EATEST_VERIFY(eastl::numeric_limits<__int128_t>::max() != 0);
	#endif

	// Test sized types.
	EATEST_VERIFY(eastl::numeric_limits<uint8_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<uint8_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<int8_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<int8_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<uint16_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<uint16_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<int16_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<int16_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<uint32_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<uint32_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<int32_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<int32_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<uint64_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<uint64_t>::max() != 0);

	EATEST_VERIFY(eastl::numeric_limits<int64_t>::is_bounded);
	EATEST_VERIFY(eastl::numeric_limits<int64_t>::max() != 0);

	return nErrorCount;
}