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
|
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
|
-
+
+
+
+
-
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
-
+
+
|
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#import "TestsAppDelegate.h"
#import "ObjFW.h"
#import "ObjFWTest.h"
@interface OFNumberTests: OTTestCase
@end
static OFString *const module = @"OFNumber";
extern unsigned long OFHashSeed;
@implementation TestsAppDelegate (OFNumberTests)
- (void)numberTests
@implementation OFNumberTests
- (void)testIsEqual
{
void *pool = objc_autoreleasePoolPush();
OFNumber *number;
TEST(@"+[numberWithLongLong:]",
(number = [OFNumber numberWithLongLong: 123456789]))
OFNumber *number = [OFNumber numberWithLongLong: 123456789];
OTAssertEqualObjects(number, [OFNumber numberWithLong: 123456789]);
}
- (void)testHash
{
unsigned long long hashSeed = OFHashSeed;
OFHashSeed = 0;
@try {
OFNumber *number = [OFNumber numberWithLongLong: 123456789];
OTAssertEqual(number.hash, 0x82D8BC42);
} @finally {
OFHashSeed = hashSeed;
};
}
TEST(@"-[isEqual:]",
[number isEqual: [OFNumber numberWithLong: 123456789]])
- (void)testCharValue
{
OFNumber *number = [OFNumber numberWithLongLong: 123456789];
TEST(@"-[hash]", number.hash == 0x82D8BC42)
TEST(@"-[charValue]", number.charValue == 21)
TEST(@"-[doubleValue]", number.doubleValue == 123456789.L)
TEST(@"signed char minimum & maximum unmodified",
(number = [OFNumber numberWithChar: SCHAR_MIN]) &&
number.charValue == SCHAR_MIN &&
(number = [OFNumber numberWithChar: SCHAR_MAX]) &&
number.charValue == SCHAR_MAX)
TEST(@"short minimum & maximum unmodified",
(number = [OFNumber numberWithShort: SHRT_MIN]) &&
number.shortValue == SHRT_MIN &&
(number = [OFNumber numberWithShort: SHRT_MAX]) &&
number.shortValue == SHRT_MAX)
TEST(@"int minimum & maximum unmodified",
(number = [OFNumber numberWithInt: INT_MIN]) &&
OTAssertEqual(number.charValue, 21);
}
- (void)testDoubleValue
{
OFNumber *number = [OFNumber numberWithLongLong: 123456789];
OTAssertEqual(number.doubleValue, 123456789.L);
}
- (void)testSignedCharMinAndMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithChar: SCHAR_MIN] charValue],
SCHAR_MIN);
OTAssertEqual([[OFNumber numberWithChar: SCHAR_MAX] charValue],
SCHAR_MAX);
}
- (void)testShortMinAndMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithShort: SHRT_MIN] shortValue],
SHRT_MIN);
OTAssertEqual([[OFNumber numberWithShort: SHRT_MAX] shortValue],
SHRT_MAX);
}
- (void)testIntMinAndMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithInt: INT_MIN] intValue], INT_MIN);
number.intValue == INT_MIN &&
(number = [OFNumber numberWithInt: INT_MAX]) &&
OTAssertEqual([[OFNumber numberWithInt: INT_MAX] intValue], INT_MAX);
number.intValue == INT_MAX)
TEST(@"long minimum & maximum unmodified",
(number = [OFNumber numberWithLong: LONG_MIN]) &&
number.longValue == LONG_MIN &&
(number = [OFNumber numberWithLong: LONG_MAX]) &&
number.longValue == LONG_MAX)
TEST(@"long long minimum & maximum unmodified",
(number = [OFNumber numberWithLongLong: LLONG_MIN]) &&
number.longLongValue == LLONG_MIN &&
(number = [OFNumber numberWithLongLong: LLONG_MAX]) &&
number.longLongValue == LLONG_MAX)
}
- (void)testLongMinAndMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithLong: LONG_MIN] longValue],
LONG_MIN);
OTAssertEqual([[OFNumber numberWithLong: LONG_MAX] longValue],
LONG_MAX);;
}
- (void)testLongLongMinAndMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithLongLong: LLONG_MIN] longLongValue],
LLONG_MIN);
OTAssertEqual([[OFNumber numberWithLongLong: LLONG_MAX] longLongValue],
LLONG_MAX);
}
- (void)testUnsignedCharMaxUnmodified
{
TEST(@"unsigned char maximum unmodified",
(number = [OFNumber numberWithUnsignedChar: UCHAR_MAX]) &&
number.unsignedCharValue == UCHAR_MAX)
TEST(@"unsigned short maximum unmodified",
(number = [OFNumber numberWithUnsignedShort: USHRT_MAX]) &&
number.unsignedShortValue == USHRT_MAX)
TEST(@"unsigned int maximum unmodified",
(number = [OFNumber numberWithUnsignedInt: UINT_MAX]) &&
number.unsignedIntValue == UINT_MAX)
TEST(@"unsigned long maximum unmodified",
(number = [OFNumber numberWithUnsignedLong: ULONG_MAX]) &&
number.unsignedLongValue == ULONG_MAX)
TEST(@"unsigned long long maximum unmodified",
OTAssertEqual([[OFNumber numberWithUnsignedChar: UCHAR_MAX]
unsignedCharValue], UCHAR_MAX);
}
- (void)testUnsignedShortMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithUnsignedShort: USHRT_MAX]
unsignedShortValue], USHRT_MAX);
}
- (void)testUnsignedIntMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithUnsignedInt: UINT_MAX]
unsignedIntValue], UINT_MAX);
}
- (void)testUnsignedLongMaxUnmodified
{
OTAssertEqual([[OFNumber numberWithUnsignedLong: ULONG_MAX]
unsignedLongValue], ULONG_MAX);
}
(number = [OFNumber numberWithUnsignedLongLong: ULLONG_MAX]) &&
number.unsignedLongLongValue == ULLONG_MAX)
- (void)testUnsignedLongLongMaxUnmodified
{
objc_autoreleasePoolPop(pool);
OTAssertEqual([[OFNumber numberWithUnsignedLongLong: ULLONG_MAX]
unsignedLongLongValue], ULLONG_MAX);
}
@end
|