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
|
/*
* Copyright (c) 2005 Adrian Page <[email protected]>
*
* This program is free software; you can redistribute it 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.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tdeunittest/runner.h>
#include <tdeunittest/module.h>
#include "kis_integer_maths_tester.h"
#include "kis_integer_maths.h"
using namespace KUnitTest;
TDEUNITTEST_MODULE(tdeunittest_kis_integer_maths_tester, "Integer Maths Tester");
TDEUNITTEST_MODULE_REGISTER_TESTER(KisIntegerMathsTester);
void KisIntegerMathsTester::allTests()
{
UINT8Tests();
UINT16Tests();
conversionTests();
}
void KisIntegerMathsTester::UINT8Tests()
{
CHECK((int)UINT8_MULT(0, 255), 0);
CHECK((int)UINT8_MULT(255, 255), 255);
CHECK((int)UINT8_MULT(128, 255), 128);
CHECK((int)UINT8_MULT(255, 128), 128);
CHECK((int)UINT8_MULT(1, 255), 1);
CHECK((int)UINT8_MULT(1, 127), 0);
CHECK((int)UINT8_MULT(64, 128), 32);
CHECK((int)UINT8_DIVIDE(255, 255), 255);
CHECK((int)UINT8_DIVIDE(64, 128), 128);
CHECK((int)UINT8_DIVIDE(1, 64), 4);
CHECK((int)UINT8_DIVIDE(0, 1), 0);
CHECK((int)UINT8_BLEND(255, 0, 0), 0);
CHECK((int)UINT8_BLEND(255, 0, 128), 128);
CHECK((int)UINT8_BLEND(255, 128, 128), 192);
CHECK((int)UINT8_BLEND(128, 64, 255), 128);
}
void KisIntegerMathsTester::UINT16Tests()
{
CHECK((int)UINT16_MULT(0, 65535), 0);
CHECK((int)UINT16_MULT(65535, 65535), 65535);
CHECK((int)UINT16_MULT(32768, 65535), 32768);
CHECK((int)UINT16_MULT(65535, 32768), 32768);
CHECK((int)UINT16_MULT(1, 65535), 1);
CHECK((int)UINT16_MULT(1, 32767), 0);
CHECK((int)UINT16_MULT(16384, 32768), 8192);
CHECK((int)UINT16_DIVIDE(65535, 65535), 65535);
CHECK((int)UINT16_DIVIDE(16384, 32768), 32768);
CHECK((int)UINT16_DIVIDE(1, 16384), 4);
CHECK((int)UINT16_DIVIDE(0, 1), 0);
CHECK((int)UINT16_BLEND(65535, 0, 0), 0);
CHECK((int)UINT16_BLEND(65535, 0, 32768), 32768);
CHECK((int)UINT16_BLEND(65535, 32768, 32768), 49152);
CHECK((int)UINT16_BLEND(32768, 16384, 65535), 32768);
}
void KisIntegerMathsTester::conversionTests()
{
CHECK((int)UINT8_TO_UINT16(255), 65535);
CHECK((int)UINT8_TO_UINT16(0), 0);
CHECK((int)UINT8_TO_UINT16(128), 128 * 257);
CHECK((int)UINT16_TO_UINT8(65535), 255);
CHECK((int)UINT16_TO_UINT8(0), 0);
CHECK((int)UINT16_TO_UINT8(128 * 257), 128);
}
|