randperm.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <test_common.h>
  2. #include <igl/randperm.h>
  3. #include <random>
  4. TEST(randperm, default_rng_reproduce_identity)
  5. {
  6. int n = 100;
  7. Eigen::VectorXi I1, I2;
  8. std::srand(6);
  9. igl::randperm(100, I1);
  10. std::srand(6);
  11. igl::randperm(100, I2);
  12. test_common::assert_eq(I1, I2);
  13. }
  14. namespace randperm
  15. {
  16. template<typename URBG>
  17. void test_reproduce()
  18. {
  19. int n = 100;
  20. Eigen::VectorXi I1, I2;
  21. URBG rng1(6);
  22. URBG rng2(6);
  23. igl::randperm(100, I1, rng1);
  24. igl::randperm(100, I2, rng2);
  25. test_common::assert_eq(I1, I2);
  26. }
  27. }
  28. TEST(randperm, minstd_rand0_reproduce_identity)
  29. {
  30. randperm::test_reproduce<std::minstd_rand0>();
  31. }
  32. TEST(randperm, minstd_rand_reproduce_identity)
  33. {
  34. randperm::test_reproduce<std::minstd_rand>();
  35. }
  36. TEST(randperm, mt19937_reproduce_identity)
  37. {
  38. randperm::test_reproduce<std::mt19937>();
  39. }
  40. TEST(randperm, mt19937_64_reproduce_identity)
  41. {
  42. randperm::test_reproduce<std::mt19937_64>();
  43. }
  44. TEST(randperm, ranlux24_base_reproduce_identity)
  45. {
  46. randperm::test_reproduce<std::ranlux24_base>();
  47. }
  48. TEST(randperm, ranlux48_base_reproduce_identity)
  49. {
  50. randperm::test_reproduce<std::ranlux48_base>();
  51. }
  52. TEST(randperm, ranlux24_reproduce_identity)
  53. {
  54. randperm::test_reproduce<std::ranlux24>();
  55. }
  56. TEST(randperm, ranlux48_reproduce_identity)
  57. {
  58. randperm::test_reproduce<std::ranlux48>();
  59. }
  60. TEST(randperm, knuth_b_reproduce_identity)
  61. {
  62. randperm::test_reproduce<std::knuth_b>();
  63. }