1 /**
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <stdlib.h>
17 #include "functionalext.h"
18
19 /**
20 * @tc.name : srand48_0100
21 * @tc.desc : Verify that the random number can be obtained by calling the srand48 function.
22 * @tc.level : Level 0
23 */
srand48_0100(void)24 void srand48_0100(void)
25 {
26 struct srand48_data {
27 long seed;
28 double value[5];
29 };
30 struct srand48_data test_data[2] = {
31 {1,
32 {0.0416303447718782138,
33 0.454492444728629152,
34 0.834817218166914898,
35 0.335986030145200232,
36 0.565489403566136417}},
37 {2,
38 {0.912432653437466712,
39 0.15908290897229449,
40 0.573262780710262376,
41 0.801506833263324836,
42 0.553675300337165055}},
43 };
44 int i, j;
45 for (i = 0; i < 2; i++) {
46 srand48(test_data[i].seed);
47 for (j = 0; j < 5; j++) {
48 EXPECT_TRUE("srand48_0100", fabs(drand48() - test_data[i].value[j]) < 0.00000000001);
49 }
50 }
51 }
52
main(int argc,char * argv[])53 int main(int argc, char *argv[])
54 {
55 srand48_0100();
56
57 return t_status;
58 }