Exemplo n.º 1
0
END_TEST

START_TEST (test_line_throughpoint) {
  VECTOR3
   a = vectorCreate (100.0, 5.56, 0.0),
   b = vectorCreate (5012.0, -12.45, 0.0),
   m = vectorCreate (0.0, 0.0, 0.0);
  float
   x = 0, y = 0;
  LINE * q = line_createThroughPoints (&a, &b, LINE_DONOTSET);
  line_coordsAtT (q, 0, &x, &y);
  m = vectorCreate (x, y, 0.0);
  fail_unless (
    vector_cmp (&a, &m) == true,
    "When creating a line through two points, the first point must correspond to a T value of 0. (expecting %.3f,%.3f, got %.3f,%.3f)",
    a.x, a.y, x, y
  );
  line_coordsAtT (q, 1, &x, &y);
  m = vectorCreate (x, y, 0.0);
  fail_unless (
    vector_cmp (&b, &m) == true,
    "When creating a line through two points, the second point must correspond to a T value of 1. (expecting %.3f,%.3f, got %.3f,%.3f)",
    a.x, a.y, x, y
  );
}
Exemplo n.º 2
0
END_TEST

START_TEST (test_line_flip) {
  line_coordsAtT (j, -1.1, &f.x, &f.y);
  line_coordsAtT (j, 4.3, &g.x, &g.y);
  line_resize (j, 4.3, -1.1);
  line_coordsAtT (j, 0, &h.x, &h.y);
  line_coordsAtT (j, 1, &i.x, &i.y);
  fail_unless (
    vector_cmp (&f, &i) == true &&
    vector_cmp (&g, &h) == true,
    "A new t-0 that is smaller than the t-1 is allowed, and should flip the line's direction as well as changing its length."
  );
}
Exemplo n.º 3
0
END_TEST

START_TEST (test_line_shrink) {
  line_coordsAtT (j, 0, &f.x, &f.y);
  line_coordsAtT (j, 1, &g.x, &g.y);
  fail_unless (
    line_resize (j, 5, 5) == false,
    "The same t-value is not allowed as both the t-0 point and the t-1 point."
  );
  line_coordsAtT (j, 0, &h.x, &h.y);
  line_coordsAtT (j, 1, &i.x, &i.y);
  fail_unless (
    vector_cmp (&f, &h) == true &&
    vector_cmp (&g, &i) == true,
    "An invalid resize attempt cannot alter the line's dimensions"
  );
}
Exemplo n.º 4
0
/* Find index i such that finish[i] == false && need[i] <= a. */
int find_i(int* work, bool* finish) {
    int i;
    for (i = 0; i < CUSTOMERS; i++) { //no for loop initial declarations
        bool* finish_ptr = finish + i;
        if (*(finish_ptr) == false && vector_cmp(need[i], work)) {
            /* Such i exists. */
            return i;
        }
    }
    
    /* Such i does not exist. */
    return -1; //return -1 instead of null, to comply with int return type
}
Exemplo n.º 5
0
Arquivo: main.c Projeto: texane/fsub
int main(int ac, char** av)
{
  int error = 0;

  matrix_t* a = NULL;
  matrix_t* const_a = NULL;
  vector_t* x = NULL;
  vector_t* const_b = NULL;
  vector_t* b = NULL;

#if CONFIG_FSUB_SEQ
  vector_t* bseq = NULL;
#endif

  if (matrix_create_lower(&const_a, CONFIG_ASIZE) == -1)
    goto on_error;
  if (matrix_create_empty(&a, CONFIG_ASIZE) == -1)
    goto on_error;

  if (vector_create(&const_b, CONFIG_ASIZE) == -1)
    goto on_error;
  if (vector_create_empty(&b, CONFIG_ASIZE) == -1)
    goto on_error;
#if CONFIG_FSUB_SEQ
  if (vector_create_empty(&bseq, CONFIG_ASIZE) == -1)
    goto on_error;
#endif

  if (vector_create_empty(&x, CONFIG_ASIZE) == -1)
    goto on_error;

#if CONFIG_FSUB_PTHREAD
  fsub_pthread_initialize();
#endif

  /* apply forward substitution: ax = b */
  size_t i;
  for (i = 0; i < CONFIG_ITER_COUNT; ++i)
  {
    struct timeval tms[4];

    matrix_copy(a, const_a);
    vector_copy(b, const_b);
#if CONFIG_FSUB_SEQ
    vector_copy(bseq, const_b);
#endif

#if CONFIG_FSUB_PTHREAD
    gettimeofday(&tms[0], NULL);
    fsub_pthread_apply(const_a, b);
    gettimeofday(&tms[1], NULL);
    timersub(&tms[1], &tms[0], &tms[2]);
#elif CONFIG_FSUB_XKAAPI
    gettimeofday(&tms[0], NULL);
    fsub_xkaapi_apply(const_a, b);
    gettimeofday(&tms[1], NULL);
    timersub(&tms[1], &tms[0], &tms[2]);
#endif

#if CONFIG_FSUB_GSL
    fsub_gsl_apply(a, x, const_b);
#endif

#if CONFIG_FSUB_SEQ
    gettimeofday(&tms[0], NULL);
    fsub_seq_apply(a, bseq);
    gettimeofday(&tms[1], NULL);
    timersub(&tms[1], &tms[0], &tms[3]);
#endif

    /* report times */
#if CONFIG_TIME
#if CONFIG_FSUB_PTHREAD || CONFIG_FSUB_XKAAPI
    printf("par: %lu\n", tms[2].tv_sec * 1000000 + tms[2].tv_usec);
#endif
#if CONFIG_FSUB_SEQ
    printf("seq: %lu\n", tms[3].tv_sec * 1000000 + tms[3].tv_usec);
#endif
#endif

    /* check against gsl implm */
#if CONFIG_FSUB_GSL
#if CONFIG_FSUB_SEQ
    if (vector_cmp(bseq, x))
    {
      printf("invalid seq\n");
      error = -1;
    }
#endif
#if CONFIG_FSUB_PTHREAD || CONFIG_FSUB_XKAAPI
    if (vector_cmp(b, x))
    {
      printf("invalid parallel\n");
      error = -1;
    }
#endif
    if (error == -1)
    {
      vector_print(b);
      vector_print(x);
      goto on_error;
    }
#endif
  }

#if CONFIG_FSUB_PTHREAD
  fsub_pthread_finalize();
#endif

 on_error:
  if (a != NULL)
    matrix_destroy(a);
  if (const_a != NULL)
    matrix_destroy(const_a);
  if (x != NULL)
    vector_destroy(x);
  if (b != NULL)
    vector_destroy(b);
  if (const_b != NULL)
    vector_destroy(const_b);
#if CONFIG_SEQ
  if (bseq != NULL)
    vector_destroy(bseq);
#endif

  return error;
}