
add_executable(random_test random_test.c)
target_link_libraries(random_test jupiter-random)

# Generated test using original code:
#  https://prng.di.unimi.it/splitmix64.c
#  https://prng.di.unimi.it/xoshiro256plus.c
add_test(NAME random-1-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # values
  0xdaac60e1ed6a4f9b
  0x3156a1da0dc08435
  0xf9ba3e3285d046ab
  0x4fd194611dba7b01
  0x40b78599c31791bf
  0x03b1dd310503d6f4)

add_test(NAME random-1-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # values
  0x92b1179cb6482dad
  0xd8b0bf6f2737e699
  0x8a81ef9f9f3375fb
  0xdea7be12d20d3927
  0xedb750ad2bbb23f7
  0x1c244ced95be7009)

# JUMP 128
add_test(NAME random-j128-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J128
  # values
  0xaf8c124445b964fd
  0x856f2dc1f0496f96
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  0x50582f40f8b0d5eb
  0x7116e7e712a797a8)

add_test(NAME random-j128-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # values
  0xdaac60e1ed6a4f9b
  0x3156a1da0dc08435
  # JUMP
  J128
  # values
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  0x50582f40f8b0d5eb
  0x7116e7e712a797a8)

# JUMP 192
add_test(NAME random-j192-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J192
  # values
  0xfbff198246738b07
  0xde58af356de87797
  0x7460461f155f7036
  0x2efce58de368a134
  0x4e5f7275e3d48fba
  0x981b9df0f455ed5a)

add_test(NAME random-j192-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # values
  0xdaac60e1ed6a4f9b
  0x3156a1da0dc08435
  # JUMP
  J192
  # values
  0x7460461f155f7036
  0x2efce58de368a134
  0x4e5f7275e3d48fba
  0x981b9df0f455ed5a)

# These tests are generated by own code
# J32
add_test(NAME random-j32-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J32
  # values
  0xd4d155edf95bcc8b
  0x971a03ebd8aa37a5
  0xde3f02d910e3aa7e
  0x30e9a0e9c0fb7c60
  # JUMP
  J128
  # values
  0xb5475a3ed7c4cb73
  0x30ec063fa0b70019)

add_test(NAME random-j32-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J128
  # values
  0xaf8c124445b964fd
  0x856f2dc1f0496f96
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  # JUMP
  J32
  # values
  0xb5475a3ed7c4cb73
  0x30ec063fa0b70019)

# J48
add_test(NAME random-j48-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J48
  # values
  0x557116cd2a3b93e7
  0xe48e9814a2e9e5a2
  0xf4e54d2ae46d7054
  0x6fda34f2363b59c2
  # JUMP
  J128
  # values
  0x66fc1c6de4268539
  0x8e083462a07e67de)

add_test(NAME random-j48-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J128
  # values
  0xaf8c124445b964fd
  0x856f2dc1f0496f96
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  # JUMP
  J48
  # values
  0x66fc1c6de4268539
  0x8e083462a07e67de)

# J64
add_test(NAME random-j64-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J64
  # values
  0x15277fc2ed5b4fb7
  0x69676bf1e7478504
  0x30de26cba08e9b78
  0xe33f4054bd45acd6
  # JUMP
  J128
  # values
  0x952dfe75ddc86f35
  0x57e664c38d4e68d9)

add_test(NAME random-j64-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J128
  # values
  0xaf8c124445b964fd
  0x856f2dc1f0496f96
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  # JUMP
  J64
  # values
  0x952dfe75ddc86f35
  0x57e664c38d4e68d9)

# J96
add_test(NAME random-j96-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J96
  # values
  0x849a017a5141e74a
  0xfc03b9f6f098d97e
  0x0e9bb32bc31aefd9
  0x6bb87d6f2f1dfeee
  # JUMP
  J128
  # values
  0x182d03c9c04943a0
  0x0ed1996bbd29a048)

add_test(NAME random-j96-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J128
  # values
  0xaf8c124445b964fd
  0x856f2dc1f0496f96
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  # JUMP
  J96
  # values
  0x182d03c9c04943a0
  0x0ed1996bbd29a048)

# J160
add_test(NAME random-j160-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J160
  # values
  0xb56badcd0a27ace5
  0xb2ca78e6b7d17859
  0xc39b89afbfd792e7
  0xf0be1e052a2e5b42
  # JUMP
  J128
  # values
  0x29b8f8cc5d070f8b
  0xff5c6784b3c7e264)

add_test(NAME random-j160-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J128
  # values
  0xaf8c124445b964fd
  0x856f2dc1f0496f96
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  # JUMP
  J160
  # values
  0x29b8f8cc5d070f8b
  0xff5c6784b3c7e264)

# J224
add_test(NAME random-j224-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J224
  # values
  0x8de66bbc1731646f
  0x283db6b3f7f3f0b8
  0xf66af0e2f67d6936
  0x6dc1821d07a848e7
  # JUMP
  J128
  # values
  0xd31d4828978c1a5d
  0xf982e2659deae859)

add_test(NAME random-j224-2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # JUMP
  J128
  # values
  0xaf8c124445b964fd
  0x856f2dc1f0496f96
  0xf0d59921234db7f6
  0x9b6d5492d8a80adc
  # JUMP
  J224
  # values
  0xd31d4828978c1a5d
  0xf982e2659deae859)

# float (Assumes FLT_MANT_DIG == 24)
add_test(NAME random-f-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # values
  .f0xdaac60 .f0x3156a1 .f0xf9ba3e .f0x4fd194 .f0x40b785 .f0x03b1dd
  .f0xb238d3 .f0x11017b .f0xa6a988 .f0xdb4000 .f0x5b3947 .f0x53cda8
  .f0x95aa43 .f0x2a6a59 .f0xa159be .f0x057cc5 .f0xfd5116 .f0x5965ef
  .f0x7e6232 .f0x13bf01 .f0xa94e36 .f0xa81fff .f0xb72316 .f0x5d9d87
  .f0x48866f .f0x7d81c7 .f0xa508fa .f0xbfc747 .f0x202904 .f0x4deb77
  .f0x7c01f8 .f0x7b54ce .f0x8bec36 .f0xa574dc .f0x9befb6 .f0xd3d99c
  .f0xc38367 .f0x6db256 .f0x6da000 .f0x6cac37 .f0x417427 .f0x690ab3
  .f0x82c8b2 .f0x0792bc .f0x7554d2 .f0x907ebf .f0xce3f16 .f0x76e4df
  .f0xd0393d .f0xd1e195 .f0x8f36b7 .f0x146ae0 .f0x54ef0e .f0xf8a137
  .f0x3a50cb .f0xb4591e .f0x126633 .f0xa656ad .f0xd7b339 .f0xd55610
  .f0xde6e5d .f0x977f54 .f0xa55940 .f0x30e7b0 .f0xaff6d3 .f0x729b96
  .f0xfabd5b .f0x0beb54 .f0x891806 .f0x7d7d98 .f0x69e471 .f0x2fd08c
  .f0xe931aa .f0xbdf68b .f0x1a8934 .f0x1f749b .f0xbef74b .f0x19039d
  .f0x8dc6f3 .f0xf3306d .f0xf31e70 .f0x1b599c .f0x699a5d .f0xc0cf13
  .f0x8ac90f .f0x09c46d .f0x1ec875 .f0x9a05c1 .f0x8fc83a .f0xee616e
  .f0xe2dc6b .f0xa13d95 .f0x466c10 .f0x80ebbf .f0xdd34d5 .f0xb998af
  .f0xa38cd3 .f0x084cc4 .f0x006e7f .f0x397367)

# double (Assumes DBL_MANT_DIG == 53)
add_test(NAME random-d-1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0xe220a8397b1dcdaf
  0x6e789e6aa1b965f4
  0x06c45d188009454f
  0xf88bb8a8724c81ec
  # values
  .d0x1b558c1c3dad49 .d0x062ad43b41b810 .d0x1f3747c650ba08
  .d0x09fa328c23b74f .d0x0816f0b33862f2 .d0x00763ba620a07a
  .d0x16471a74e43aa1 .d0x02202f775141f1 .d0x14d53117da3eb2
  .d0x1b68001f71aaa0 .d0x0b6728f7d96e3d .d0x0a79b50c268441
  .d0x12b5487bc54ab7 .d0x054d4b2f991218 .d0x142b37d28ef18c
  .d0x00af98ae248cff .d0x1faa22cce188a5 .d0x0b2cbdeea92e97
  .d0x0fcc4656bc9a45 .d0x0277e0243dbe8d .d0x1529c6db53bac1
  .d0x1503ffe6eb085c .d0x16e462cc70e012 .d0x0bb3b0ea22f9c9
  .d0x0910cde3e670c3 .d0x0fb038e493fe74 .d0x14a11f41333f54
  .d0x17f8e8eb1538d1 .d0x0405209f062c3d .d0x09bd6efc09d39f
  .d0x0f803f0847e4e0 .d0x0f6a99c5b859e2 .d0x117d86cc71991e
  .d0x14ae9b8ecf1a4f .d0x137df6c626ab63 .d0x1a7b339bd6ef14
  .d0x18706cee94bb7d .d0x0db64ac5d9e414 .d0x0db400113d565a
  .d0x0d9586fb094606 .d0x082e84f1954cb2 .d0x0d21567a7bbe1e
  .d0x10591642276304 .d0x00f25786dc7035 .d0x0eaa9a4f0073d4
  .d0x120fd7eb0c7f59 .d0x19c7e2c7b05f47 .d0x0edc9bec05e213
  .d0x1a0727b1f06500 .d0x1a3c32ba4163ec .d0x11e6d6f3e82a35
  .d0x028d5c02ccd8e2 .d0x0a9de1c9629930 .d0x1f1426e1cbf60a
  .d0x074a196285933c .d0x168b23cf734aaa .d0x024cc6763c066d
  .d0x14cad5ad515f3d .d0x1af6673786d4ec .d0x1aaac2081bb2ea
  .d0x1bcdcba0d08048 .d0x12efea8f3d5042 .d0x14ab280d2a95b7
  .d0x061cf60d7b2275 .d0x15feda655d7956 .d0x0e5372df6e166d
  .d0x1f57ab6adfe327 .d0x017d6a82575969 .d0x112300dacba67e
  .d0x0fafb30c2f6f7d .d0x0d3c8e3e655c38 .d0x05fa1184684330
  .d0x1d26354d45541e .d0x17bed17ec4b30a .d0x035126994d8456
  .d0x03ee9376629b68 .d0x17dee9773c71cb .d0x032073b4622a79
  .d0x11b8de7028207c .d0x1e660db4106495 .d0x1e63ce0dd83539
  .d0x036b33941bd8b0 .d0x0d334bad788361 .d0x1819e26f42f6eb
  .d0x115921f2edcf2b .d0x01388db9eab508 .d0x03d90eb8c1e720
  .d0x1340b826c34df0 .d0x11f9075b0e360a .d0x1dcc2dd8fe8491
  .d0x1c5b8d70dec5f5 .d0x1427b2a2322be2 .d0x08cd821149e3c0
  .d0x101d77f5d326cf .d0x1ba69abb4004f2 .d0x173315f136eef9
  .d0x14719a6987b134 .d0x01099881afb4ec .d0x000dcff264dd18
  .d0x072e6cecaed877)

# n (test for limited number)
add_test(NAME random-1-3
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # values
  .n2  999
  .n10 999
  .n23 999
  .n100 999
  .n1000 9999
  .n4294967295 999999
  0x1ff164958ec39adf)

add_test(NAME random-1-4
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # values
  .n1048576  1013994
  0x1ff164958ec39adf)

# quality test (original tests calculate quality for 10^12 trials, but it's too
# expensive...)
add_test(NAME random-Q-d1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # quality
  .Qd1000000 6 1.0e-3
  0x5acb31feae79540f)

add_test(NAME random-Q-d2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # quality
  .Qd10000000000 6 1.0e-5
  0x3eb6bc6d4ba851c0)

add_test(NAME random-Q-e1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # quality
  .Qe1000000 6 3.0e-2
  0x8813f1c056a23cb6)

add_test(NAME random-Q-e2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # quality
  .Qe10000000000 6 2.5e-4
  0x10a44d82ed33eeb4)

add_test(NAME random-Q-o1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # quality
  .Qo1000000 6 0.7
  0xce1a0537d45537d4)

add_test(NAME random-Q-o2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # quality
  .Qo10000000000 6 2.5e-3
  0x465bf670257e985d)

## Distribution test
add_test(NAME random-C-d1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # distribution
  .Cd20 1000000 1.0e-2
  0x5acb31feae79540f)

add_test(NAME random-C-d2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # distribution
  .Cd2000 10000000000 2.0e-3
  0x3eb6bc6d4ba851c0)

add_test(NAME random-C-e1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # distribution
  .Ce20 1000000 5.0e-2
  0x8813f1c056a23cb6)

add_test(NAME random-C-e2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # distribution
  .Ce2000 10000000000 1.0e-2
  0x10a44d82ed33eeb4)

add_test(NAME random-C-o1
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # distribution
  .Co20 1000000 5.0e-2
  0xce1a0537d45537d4)

add_test(NAME random-C-o2
  COMMAND $<TARGET_FILE:random_test>
  # seeds
  0x53cb9f0c747ea2ea
  0x2c829abe1f4532e1
  0xc584133ac916ab3c
  0x3ee5789041c98ac3
  # distribution
  .Co2000 10000000000 3.0e-3
  0x465bf670257e985d)

## These tests can be very heavy for debug builds
set(_A LABELS heavy)
if (NOT JUPITER_TEST_ENABLE_HEAVY_TESTS)
  list(APPEND _A DISABLED TRUE)
endif()
set_tests_properties(
  random-Q-d2 random-Q-e2 random-Q-o2
  random-C-d2 random-C-e2 random-C-o2
  PROPERTIES ${_A})


## MPI

if (JUPITER_USE_MPI)
  add_executable(random_test_mpi random_test_mpi.c)
  target_link_libraries(random_test_mpi jupiter-random)

  add_test(NAME random_test_mpi COMMAND $<TARGET_FILE:random_test_mpi>)
endif()

## Fortran

if (JUPITER_RANDOM_ENABLE_F90)
  add_library(librandom_test_f90 random_test.f90)
  get_target_property(__LIBTYPE librandom_test_f90 TYPE)
  if("${__LIBTYPE}" STREQUAL "SHARED_LIBRARY")
    target_compile_definitions(librandom_test_f90 PRIVATE
      JUPITER_RANDOM_TEST_F90_EXPORT)
    target_compile_definitions(librandom_test_f90 INTERFACE
      JUPITER_RANDOM_TEST_F90_IMPORT)
  endif()
  target_link_libraries(librandom_test_f90 jupiter-random-f90)

  set_target_properties(librandom_test_f90 PROPERTIES
    OUTPUT_NAME random-test-f90)

  if(NOT "${CMAKE_GENERATOR}" MATCHES "Ninja" AND "${CMAKE_VERSION}" VERSION_LESS "3.18")
    find_package(FortranPreprocessFlags REQUIRED)
    set_target_properties(librandom_test_f90 PROPERTIES
      COMPILE_FLAGS "$<$<COMPILE_LANGUAGE:Fortran>:${Fortran_PREPROCESS_FLAGS}")
  else()
    set_target_properties(librandom_test_f90 PROPERTIES
      Fortran_PREPROCESS ON)
  endif()

  add_executable(random_test_f90 random_test_f90.c)
  target_link_libraries(random_test_f90 librandom_test_f90)
endif()

if(TARGET random_test_f90)
  add_test(NAME random-test-f90 COMMAND $<TARGET_FILE:random_test_f90>)
endif()
