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
|
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
/*=============================================================================
**
** Source: test1.c
**
** Purpose: Test to ensure that cos return the correct values
**
** Dependencies: PAL_Initialize
** PAL_Terminate
** Fail
** fabs
**
**
**===========================================================================*/
#include <palsuite.h>
#define DELTA 0.0000001 /* Error acceptance level to the 7th decimal */
/**
* Helper test structure
*/
struct test
{
double value; /* value to test the function with */
double result; /* expected result */
};
/**
* main
*
* executable entry point
*/
INT __cdecl main(INT argc, CHAR **argv)
{
double pi = 3.1415926535;
int i;
struct test tests[] =
{
/* Value test result */
{ 0, 1 },
{ pi/2.0, 0 },
{ pi, -1 },
{ (3.0*pi) / 2.0, 0 },
{ 2.0 * pi, 1 },
{ 5.0*pi/2.0, 0 },
{ 3.0*pi, -1 },
{ (7.0*pi) / 2.0, 0 },
{ 4.0 * pi, 1 },
{ 1.7e-12, 1 },
{ 1.7e+12, 0.1745850 }
};
/* PAL initialization */
if( PAL_Initialize(argc, argv) != 0 )
{
return (FAIL);
}
for( i = 0; i < sizeof(tests) / sizeof(struct test); i++)
{
double result;
double testDelta;
result = cos( tests[i].value );
/* The test is valid when the difference between the */
/* result and the expectation is less than DELTA */
testDelta = fabs( result - tests[i].result );
if( testDelta >= DELTA )
{
Fail( "cos(%g) returned %20.10g"
" when it should have returned %20.10g",
tests[i].value,
result,
tests[i].result );
}
}
PAL_Terminate();
return PASS;
}
|