MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Macros | Functions | Variables
test_timebinmgr.c File Reference
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include "stub.h"
#include <libgadget/timebinmgr.h>
Include dependency graph for test_timebinmgr.c:

Go to the source code of this file.

Macros

#define TIMEMAX   1.0
 
#define TIMEIC   0.1
 
#define OutputListLength   4
 

Functions

static void test_conversions (void **state)
 
static void test_skip_first (void **state)
 
static void test_dloga (void **state)
 
static int setup (void *p1, void *p2)
 
static int teardown (void *p1, void *p2)
 
int main (void)
 

Variables

double outs [4] = {TIMEIC, 0.2, 0.8, TIMEMAX}
 
double logouts [4]
 

Macro Definition Documentation

◆ OutputListLength

#define OutputListLength   4

Definition at line 93 of file test_timebinmgr.c.

◆ TIMEIC

#define TIMEIC   0.1

Definition at line 15 of file test_timebinmgr.c.

◆ TIMEMAX

#define TIMEMAX   1.0

Definition at line 14 of file test_timebinmgr.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 115 of file test_timebinmgr.c.

115  {
116  const struct CMUnitTest tests[] = {
117  cmocka_unit_test(test_conversions),
118  cmocka_unit_test(test_dloga),
119  cmocka_unit_test(test_skip_first),
120  };
121  return cmocka_run_group_tests_mpi(tests, setup, teardown);
122 }
static void test_conversions(void **state)
static int teardown(void *p1, void *p2)
static void test_skip_first(void **state)
static void test_dloga(void **state)
static int setup(void *p1, void *p2)

References setup(), teardown(), test_conversions(), test_dloga(), and test_skip_first().

Here is the call graph for this function:

◆ setup()

static int setup ( void *  p1,
void *  p2 
)
static

Definition at line 96 of file test_timebinmgr.c.

97 {
98  int i;
99  double OutputListTimes[OutputListLength];
100  for(i = 0; i < OutputListLength; i ++) {
101  OutputListTimes[i] = outs[i];
102  logouts[i] = log(outs[i]);
103  }
104 
105  set_sync_params(OutputListLength, OutputListTimes);
106  return 0;
107 }
double outs[4]
double logouts[4]
#define OutputListLength
void set_sync_params(int OutputListLength, double *OutputListTimes)
Definition: timebinmgr.c:76

References logouts, OutputListLength, outs, and set_sync_params().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ teardown()

static int teardown ( void *  p1,
void *  p2 
)
static

Definition at line 109 of file test_timebinmgr.c.

110 {
111 
112  return 0;
113 }

Referenced by main().

Here is the caller graph for this function:

◆ test_conversions()

static void test_conversions ( void **  state)
static

this function returns the next output time after ti_curr.

Definition at line 21 of file test_timebinmgr.c.

21  {
22 
24 
25  /*Convert an integer to and from loga*/
26  /* double loga_from_ti(unsigned int ti); */
27  assert_true(fabs(loga_from_ti(0) - logouts[0]) < 1e-6);
28  assert_true(fabs(loga_from_ti(TIMEBASE) - logouts[1]) < 1e-6);
29  assert_true(fabs(loga_from_ti(TIMEBASE-1) - (logouts[0] + (logouts[1]-logouts[0])*(TIMEBASE-1)/TIMEBASE)) < 1e-6);
30  assert_true(fabs(loga_from_ti(TIMEBASE+1) - (logouts[1] + (logouts[2]-logouts[1])/TIMEBASE)) < 1e-6);
31  assert_true(fabs(loga_from_ti(2*TIMEBASE) - logouts[2]) < 1e-6);
32  /* unsigned int ti_from_loga(double loga); */
33  assert_true(ti_from_loga(logouts[0]) == 0);
34  assert_true(ti_from_loga(logouts[1]) == TIMEBASE);
35  assert_true(ti_from_loga(logouts[2]) == 2*TIMEBASE);
36  double midpt = (logouts[2] + logouts[1])/2;
37  assert_true(ti_from_loga(midpt) == TIMEBASE+TIMEBASE/2);
38  assert_true(fabs(loga_from_ti(TIMEBASE+TIMEBASE/2)-midpt)< 1e-6);
39 
40  /*Check behaviour past end*/
41  assert_true(ti_from_loga(0) == 3*TIMEBASE);
42  assert_true(fabs(loga_from_ti(ti_from_loga(log(0.1))) - log(0.1)) < 1e-6);
43 
45  assert_int_equal(find_next_sync_point(0)->ti , TIMEBASE);
46  assert_int_equal(find_next_sync_point(TIMEBASE)->ti , 2 * TIMEBASE);
47  assert_int_equal(find_next_sync_point(TIMEBASE-1)->ti , TIMEBASE);
48  assert_int_equal(find_next_sync_point(TIMEBASE+1)->ti , 2*TIMEBASE);
49  assert_int_equal(find_next_sync_point(4 * TIMEBASE) , NULL);
50 
51  assert_int_equal(find_current_sync_point(0)->ti , 0);
52  assert_int_equal(find_current_sync_point(TIMEBASE)->ti , TIMEBASE);
53  assert_int_equal(find_current_sync_point(-1) , NULL);
54  assert_int_equal(find_current_sync_point(TIMEBASE-1) , NULL);
55 
56  assert_int_equal(find_current_sync_point(0)->write_snapshot, 1);
57  assert_int_equal(find_current_sync_point(TIMEBASE)->write_snapshot, 1);
58  assert_int_equal(find_current_sync_point(2 * TIMEBASE)->write_snapshot, 1);
59  assert_int_equal(find_current_sync_point(3 * TIMEBASE)->write_snapshot, 1);
60 }
#define TIMEIC
#define TIMEMAX
double loga_from_ti(int ti)
Definition: test_timefac.c:51
inttime_t ti_from_loga(double loga)
Definition: timebinmgr.c:236
SyncPoint * find_next_sync_point(inttime_t ti)
Definition: timebinmgr.c:174
SyncPoint * find_current_sync_point(inttime_t ti)
Definition: timebinmgr.c:188
void setup_sync_points(double TimeIC, double TimeMax, double no_snapshot_until_time, int SnapshotWithFOF)
Definition: timebinmgr.c:97
#define TIMEBASE
Definition: timebinmgr.h:14

References find_current_sync_point(), find_next_sync_point(), loga_from_ti(), logouts, setup_sync_points(), ti_from_loga(), TIMEBASE, TIMEIC, and TIMEMAX.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_dloga()

static void test_dloga ( void **  state)
static

Definition at line 71 of file test_timebinmgr.c.

71  {
72 
74 
75  inttime_t Ti_Current = ti_from_loga(log(0.55));
76 
77  /* unsigned int dti_from_dloga(double loga); */
78  /* double dloga_from_dti(unsigned int ti); */
79 
80  /*Get dloga from a timebin*/
81  /* double get_dloga_for_bin(int timebin); */
82  assert_true(fabs(get_dloga_for_bin(0, Ti_Current ))<1e-6);
83  assert_true(fabs(get_dloga_for_bin(TIMEBINS, Ti_Current )-(logouts[2]-logouts[1]))<1e-6);
84  assert_true(fabs(get_dloga_for_bin(TIMEBINS-2, Ti_Current)-(logouts[2]-logouts[1])/4)<1e-6);
85 
86  /*Enforce that an integer time is a power of two*/
87  /* unsigned int round_down_power_of_two(unsigned int ti); */
89  assert_true(round_down_power_of_two(TIMEBASE+1)==TIMEBASE);
90  assert_true(round_down_power_of_two(TIMEBASE-1)==TIMEBASE/2);
91 }
inttime_t round_down_power_of_two(inttime_t dti)
Definition: timebinmgr.c:286
double get_dloga_for_bin(int timebin, const inttime_t Ti_Current)
Definition: timebinmgr.c:279
#define TIMEBINS
Definition: timebinmgr.h:13
int32_t inttime_t
Definition: types.h:8

References get_dloga_for_bin(), logouts, round_down_power_of_two(), setup_sync_points(), ti_from_loga(), TIMEBASE, TIMEBINS, TIMEIC, and TIMEMAX.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_skip_first()

static void test_skip_first ( void **  state)
static

Definition at line 62 of file test_timebinmgr.c.

62  {
63 
65  assert_int_equal(find_current_sync_point(0)->write_snapshot, 0);
66 
68  assert_int_equal(find_current_sync_point(0)->write_snapshot, 1);
69 }

References find_current_sync_point(), setup_sync_points(), TIMEIC, and TIMEMAX.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ logouts

double logouts[4]

Definition at line 17 of file test_timebinmgr.c.

Referenced by setup(), test_conversions(), and test_dloga().

◆ outs

double outs[4] = {TIMEIC, 0.2, 0.8, TIMEMAX}

Definition at line 16 of file test_timebinmgr.c.

Referenced by setup().