Ejemplo n.º 1
0
VALUE rb_gsl_multiset_init_last(VALUE mm)
{
  gsl_multiset *m;
  Data_Get_Struct(mm, gsl_multiset, m);
  gsl_multiset_init_last(m);
  return Qnil;
}
Ejemplo n.º 2
0
Archivo: test.c Proyecto: lemahdi/mglib
int
main (void)
{
  size_t i, j;
  int status = 0, s;
  gsl_multiset * c ;

  gsl_ieee_env_setup ();

  c = gsl_multiset_alloc (6,3);

  /* Test multisets in forward order */

  gsl_multiset_init_first (c);

  i = 0;

  do
    {
      if ( i >= 56 )
        {
          status = 1;
          break;
        }
      for (j = 0; j < 3; j++)
        {
          status |= (c->data[j] != c63[i][j]);
        }

      {
        int s1 = gsl_multiset_valid (c);
        gsl_test (s1, "gsl_multiset_valid (%u)", i);
      }

      i++;
    }
  while (gsl_multiset_next(c) == GSL_SUCCESS);

  gsl_test(status, "gsl_multiset_next, 6 choose 3 multiset, 56 steps");

  gsl_multiset_next(c);
  gsl_multiset_next(c);
  gsl_multiset_next(c);
  for (j = 0; j < 3; j++)
    {
      status |= (c->data[j] != c63[55][j]);
    }
  gsl_test(status, "gsl_multiset_next on the last multiset");

  {
    int s1 = gsl_multiset_valid (c);
    gsl_test (s1, "gsl_multiset_valid on the last multiset");
  }

  {
    gsl_multiset * d = gsl_multiset_alloc (6,3);
    gsl_multiset_memcpy (d, c);

    status = 0;

    for (j = 0; j < 3; j++)
      {
        status |= (d->data[j] != c->data[j]);
      }

    gsl_test (status, "gsl_multiset_memcpy, 6 choose 3 multiset");
    gsl_multiset_free(d);
  }


  /* Now test multisets in reverse order */

  gsl_multiset_init_last (c);

  i = 56;
  do
    {
      if ( i == 0 )
        {
          status = 1;
          break;
        }

      i--;

      for (j = 0; j < 3; j++)
        {
          status |= (c->data[j] != c63[i][j]);
        }

      {
        int s1 = gsl_multiset_valid (c);
        gsl_test (s1, "gsl_multiset_valid (%u)", i);
      }
    }
  while (gsl_multiset_prev(c) == GSL_SUCCESS);

  gsl_test(status, "gsl_multiset_prev, 6 choose 3 multiset, 20 steps");

  gsl_multiset_prev(c);
  gsl_multiset_prev(c);
  gsl_multiset_prev(c);
  for (j = 0; j < 3; j++)
    {
      status |= (c->data[j] != c63[0][j]);
    }
  gsl_test(status, "gsl_multiset_prev on the first multiset");

  {
    int s1 = gsl_multiset_valid (c);
    gsl_test (s1, "gsl_multiset_valid on the first multiset");
  }

  {
    gsl_multiset * d = gsl_multiset_alloc (6,3);
    gsl_multiset_memcpy (d, c);

    status = 0;

    for (j = 0; j < 3; j++)
      {
        status |= (d->data[j] != c->data[j]);
      }

    gsl_test (status, "gsl_multiset_memcpy, 6 choose 3 multiset");
    gsl_multiset_free(d);
  }

  gsl_multiset_free (c);

  c = gsl_multiset_calloc(7, 0);
  /* should return GSL_FAILURE every time */
  status |= (gsl_multiset_next(c) != GSL_FAILURE);
  status |= (gsl_multiset_next(c) != GSL_FAILURE);
  status |= (gsl_multiset_prev(c) != GSL_FAILURE);
  status |= (gsl_multiset_prev(c) != GSL_FAILURE);
  gsl_test(status, "gsl_multiset 7 choose 0");
  gsl_multiset_free (c);

  c = gsl_multiset_calloc(1, 1);
  /* should return GSL_FAILURE every time */
  for(j = 0; j < 1; j++)
  {
    status |= (gsl_multiset_get(c, j) != j);
  }
  status |= (gsl_multiset_next(c) != GSL_FAILURE);
  for(j = 0; j < 1; j++)
  {
    status |= (gsl_multiset_get(c, j) != j);
  }
  status |= (gsl_multiset_next(c) != GSL_FAILURE);
  for(j = 0; j < 1; j++)
  {
    status |= (gsl_multiset_get(c, j) != j);
  }
  status |= (gsl_multiset_prev(c) != GSL_FAILURE);
  for(j = 0; j < 1; j++)
  {
    status |= (gsl_multiset_get(c, j) != j);
  }
  status |= (gsl_multiset_prev(c) != GSL_FAILURE);
  for(j = 0; j < 1; j++)
  {
    status |= (gsl_multiset_get(c, j) != j);
  }
  gsl_test(status, "gsl_multiset 7 choose 7");
  gsl_multiset_free (c);

  c = gsl_multiset_calloc(6, 3);

  gsl_set_error_handler (&my_error_handler);

  c->data[0] = 1;
  c->data[1] = 2;
  c->data[2] = 1;
  s = gsl_multiset_valid (c);
  gsl_test (!s, "gsl_multiset_valid on an invalid multiset (1,1,2)");

  c->data[0] = 2;
  c->data[1] = 1;
  c->data[2] = 0;
  s = gsl_multiset_valid (c);
  gsl_test (!s, "gsl_multiset_valid on an invalid multiset (2,1,0)");

  c->data[0] = 1;
  c->data[1] = 2;
  c->data[2] = 0;
  s = gsl_multiset_valid (c);
  gsl_test (!s, "gsl_multiset_valid on an invalid multiset (1,2,0)");

  {
    gsl_multiset * d = gsl_multiset_alloc (6,4);
    int s = gsl_multiset_memcpy (d, c);
    gsl_test (!s, "gsl_multiset_memcpy, (6,4) vs (6,3)");
    gsl_multiset_free(d);
  }

  {
    gsl_multiset * d = gsl_multiset_alloc (7,3);
    int s = gsl_multiset_memcpy (d, c);
    gsl_test (!s, "gsl_multiset_memcpy, (7,3) vs (6,3)");
    gsl_multiset_free(d);
  }

  {
    gsl_multiset * d = gsl_multiset_alloc (7,2);
    int s = gsl_multiset_memcpy (d, c);
    gsl_test (!s, "gsl_multiset_memcpy, (7,2) vs (6,3)");
    gsl_multiset_free(d);
  }


  gsl_multiset_free (c);

  exit (gsl_test_summary());
}