Пример #1
0
static void contains_negative_test(void) {
    Array array;

    array = ia_of_string("10, 20, 30");
    check_expect_b(contains_negative(array), false);
    a_free(array);

    array = ia_of_string("0, 0, 1, 1, 1");
    check_expect_b(contains_negative(array), false);
    a_free(array);

    array = ia_of_string("-1, -3");
    check_expect_b(contains_negative(array), true);
    a_free(array);

    array = ia_of_string("1, 3, -99");
    check_expect_b(contains_negative(array), true);
    a_free(array);

    array = ia_of_string("-1, 3, 99");
    check_expect_b(contains_negative(array), true);
    a_free(array);

    array = ia_of_string("");
    check_expect_b(contains_negative(array), false);
    a_free(array);
}
Пример #2
0
int exact_test_helper(double *pval, int *num_tbls, int k, double pvalthresh, int num_entries,
                      int N, double numerator, int *margins, int *ex_cells, int *co_cells,
                      int num_co_cells, int *tbl, int **mar_stack, int co_in, int T_rem, int T_obs){
  int res = UNDER_THRESH;
  if (co_in >= num_co_cells){
    derive_remaining_cells( k, N, margins, ex_cells, tbl, mar_stack[co_in] );
    if (contains_negative(tbl, num_entries) == 0){
      double addp = exp( numerator - denom( k, num_entries, N,  tbl) );
      pval[0] += addp;
      if (T_obs < sum_cells(tbl, ex_cells, k)){ // T > T_x
        pval[1] += addp;
      }
      num_tbls[0] += 1;
    }
  if ((pval[0]+pval[1])/2 > pvalthresh) {	
      res = OVER_THRESH;
    }
  }
  else {
    // Define required variables
    int i, cell, val, MarRem;
    double coef;
    int *mar_rems;
    
    cell     = co_cells[co_in];
    coef     = num_ones( cell );
    mar_rems = mar_stack[co_in];
    
    // Determine which variables are in the margin
    MarRem = min_affected_margin( k, cell, mar_rems );
    
    // Iterate over the possible values the current cell can take
    for (val = 0; val < min(MarRem, (int) floor(T_rem/coef)) + 1; val++){
      // Update margins
      for (i=0; i < k; i++){
        if (cell & (1 << i)) mar_stack[co_in+1][i] = mar_rems[i] - val;
        else mar_stack[co_in+1][i] = mar_rems[i];
      }
      
      // Create new table using the current value
      tbl[cell] = val;
      res = exact_test_helper( pval, num_tbls, k, pvalthresh, num_entries, N, numerator,
                               margins, ex_cells, co_cells, num_co_cells, tbl,
                               mar_stack, co_in + 1, T_rem-coef*val, T_obs);
      if (res < 0) {
        break;
      }
    }
  }
  return res;
}