File: testFunction.cpp

package info (click to toggle)
openexr 1.2.2-4.3
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 15,508 kB
  • ctags: 3,410
  • sloc: cpp: 40,009; sh: 8,399; makefile: 345
file content (68 lines) | stat: -rw-r--r-- 1,351 bytes parent folder | download | duplicates (3)
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
#include <testFunction.h>
#include <halfFunction.h>
#include <iostream>
#include <assert.h>


using namespace std;

namespace {


float
divideByTwo (float x)
{
    return x / 2;
}


struct timesN
{
    timesN (float n): n (n) {}
    float operator () (float x) {return x * n;}
    float n;
};


} // namespace


void
testFunction ()
{
    cout << "halfFunction<T>\n";

    halfFunction <float> d2 (divideByTwo);

    assert (d2 (0)  ==  0);
    assert (d2 (2)  ==  1);
    assert (d2 (-2) == -1);
    assert (d2 (HALF_MAX)  ==  HALF_MAX / 2);
    assert (d2 (-HALF_MAX) == -HALF_MAX / 2);
    assert (d2 (half::posInf()) == 0);
    assert (d2 (half::negInf()) == 0);
    assert (d2 (half::qNan())   == 0);

    halfFunction <half> t5 (timesN (5),		// function
			    0, HALF_MAX / 8,	// domain
			    -1,			// default value
			    half::posInf(),	// posInfValue
			    half::negInf(),	// negInfValue
			    half::qNan());	// nanValue

    assert (t5 (0)  ==  0);
    assert (t5 (2)  == 10);
    assert (t5 (-2) == -1);
    assert (t5 (HALF_MAX)  == -1);
    assert (t5 (-HALF_MAX) == -1);

    assert ( t5(half::posInf()).isInfinity());
    assert (!t5(half::posInf()).isNegative());

    assert (t5(half::negInf()).isInfinity());
    assert (t5(half::negInf()).isNegative());

    assert (t5(half::qNan()).isNan());

    cout << "ok\n\n" << flush;
}