#--- maxLH_check test (Python) ------------------------------------------------

find_package(Python3 REQUIRED COMPONENTS Interpreter)

#--- helper macro -------------------------------------------------------------
macro(add_maxLH_test test_name msr_file expected_value)
  add_test(
    NAME ${test_name}
    COMMAND Python3::Interpreter
      ${CMAKE_CURRENT_SOURCE_DIR}/maxLH_check.py
      $<TARGET_FILE:musrfit>
      ${CMAKE_SOURCE_DIR}/doc/examples/${msr_file}
      ${expected_value}
      1e-4
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc/examples
  )
endmacro()

#--- register ctest(s) -------------------------------------------------------

# single histogram fits (maxLH)
add_maxLH_test(test-histo-MusrRoot      test-histo-MusrRoot.msr       3971.7)
add_maxLH_test(test-histo-PSI-BIN       test-histo-PSI-BIN.msr        663.89)
add_maxLH_test(test-histo-ROOT-NPP      test-histo-ROOT-NPP.msr      249.12)
add_maxLH_test(test-histo-HAL9500       test-histo-HAL9500.msr        1286509.8)
add_maxLH_test(test-histo-HAL9500-RRF   test-histo-HAL9500-RRF.msr   22187.4)
add_maxLH_test(test-histo-muMinus       test-histo-muMinus.msr        238962.6)

# asymmetry fits (chisq)
add_maxLH_test(test-asy-PSI-BIN         test-asy-PSI-BIN.msr          566.76)
add_maxLH_test(test-asy-MUD             test-asy-MUD.msr              133.96)
add_maxLH_test(test-asy-HAL9500-RRF     test-asy-HAL9500-RRF.msr     7402.28)
add_maxLH_test(test-asy-LF-BaB6         test-asy-LF-BaB6.msr         1911.88)
add_maxLH_test(test-asy-LSCO-ZF         test-LSCO-asy-ZF.msr          700.76)

#--- NeXus based tests. These can only work if musrfit was built with
#--- -Dnexus=1, otherwise the msr-files cannot be read at all -----------------
if (nexus)
  # NeXus IDF V2 / HDF5
  add_maxLH_test(test-histo-NeXus2      test-histo-NeXus2.msr         4228.9)
  add_maxLH_test(test-asy-NeXus2        test-asy-NeXus2.msr           1159.8)

  # the ISIS example data of this one is an HDF4 file, hence it additionally
  # needs -DHAVE_HDF4=1
  if (HAVE_HDF4)
    add_maxLH_test(test-histo-NeXus     test-histo-NeXus.msr          3273.57)
  endif (HAVE_HDF4)
endif (nexus)
