# -*- Makefile -*-

# The test suite no longer runs in parallel, but it ALWAYS tries to run all the
# tests, even without 'make -k'
TESTS :=																\
  test/test-pywrap-functions.py														\
  test/test-pylib-projections.py													\
  test/test-poseutils.py														\
  test/test-cameramodel.py														\
  test/test-poseutils-lib.py														\
  test/test-projections.py														\
  test/test-projection--special-cases.py__pinhole											\
  test/test-projection--special-cases.py__stereographic											\
  test/test-projection--special-cases.py__lonlat											\
  test/test-projection--special-cases.py__latlon											\
  test/test-gradients.py														\
  test/test-py-gradients.py														\
  test/test-cahvor															\
  test/test-optimizer-callback.py													\
  test/test-basic-sfm.py														\
  test/test-basic-calibration.py													\
  test/test-surveyed-calibration.py													\
  test/test-surveyed-calibration.py__--distance__8											\
  test/test-surveyed-calibration.py__--oversample__10											\
  test/test-surveyed-calibration.py__--do-sample											\
  test/test-surveyed-calibration.py__--do-sample__--distance__8										\
  test/test-surveyed-calibration.py__--do-sample__--oversample__10									\
  test/test-projection-uncertainty.py__--fixed__cam0__--model__opencv4__--do-sample							\
  test/test-projection-uncertainty.py__--fixed__frames__--model__opencv4__--do-sample__--Nsamples__200					\
  test/test-projection-uncertainty.py__--fixed__cam0__--model__splined									\
  test/test-linearizations.py														\
  test/test-lensmodel-string-manipulation												\
  test/test-CHOLMOD-factorization.py													\
  test/test-projection-diff.py														\
  test/test-graft-models.py														\
  test/test-convert-lensmodel.py													\
  test/test-stereo.py															\
  test/test-solvepnp.py															\
  test/test-match-feature.py														\
  test/test-triangulation.py														\
  test/test-uncertainty-broadcasting.py__--q-calibration-stdev__0.3__--q-observation-stdev__0.3__--q-observation-stdev-correlation__0.5	\
  test/test-parser-cameramodel														\
  test/test-extrinsics-moved-since-calibration.py											\
  test/test-broadcasting.py														\
  test/test-compute-chessboard-corners-parsing.py											\
  test/test-rectification-maps.py													\
  test/test-save-load-image.py \
  test/test-worst_direction_stdev.py

# triangulation-uncertainty tests. Lots and lots of tests to exhaustively try
# out different scenarios
BASE := test/test-triangulation-uncertainty.py__--do-sample__--model__opencv4__--observed-point__-40__0__200__--Ncameras__3__--cameras__2__1__--q-observation-stdev-correlation__0.6
TESTS_TRIANGULATION_UNCERTAINTY := \
  $(foreach stabilization,__--stabilize-coords NONE, \
  $(foreach fixed,cam0 frames, \
  $(foreach only,observation calibration, \
  $(BASE)$(if $(filter NONE,$(stabilization)),,$(stabilization))__--fixed__$(fixed)__--q-$(only)-stdev__0.5)))
# Both sets of noise. Looking at different camera
BASE := test/test-triangulation-uncertainty.py__--do-sample__--model__opencv4__--Ncameras__2__--cameras__1__0__--q-observation-stdev__0.5__--q-calibration-stdev__0.5
# Different amounts of correlation and near/far
TESTS_TRIANGULATION_UNCERTAINTY := $(TESTS_TRIANGULATION_UNCERTAINTY) \
  $(foreach stabilization,__--stabilize-coords NONE, \
  $(foreach fixed,cam0 frames, \
  $(foreach corr,0.1 0.9, \
  $(foreach where,near far, \
  $(BASE)$(if $(filter NONE,$(stabilization)),,$(stabilization))__--fixed__$(fixed)__--q-observation-stdev-correlation__$(corr)__--observed-point__$(if $(filter near,$(where)),-2__0__10,-40__0__200)))))

TESTS_external_data := test/test-stereo-range.py



# TESTS_TRIANGULATION_UNCERTAINTY not included in TESTS yet, so TESTS_NOSAMPLING
# includes none of those
TESTS_NOSAMPLING := $(foreach t,$(TESTS),$(if $(filter --do-sample,$(subst __, ,$t)),,$t))
TESTS := $(TESTS) $(TESTS_TRIANGULATION_UNCERTAINTY)

# TESTS_external_data is not included in any other set, and must be requested
# explicitly

# Define the set for each "make test-xxx" command
TESTS_all                       := $(TESTS)
TESTS_nosampling                := $(TESTS_NOSAMPLING)
TESTS_triangulation_uncertainty := $(TESTS_TRIANGULATION_UNCERTAINTY)

# "test-all" is the full set of tests
# "test-nosampling" excludes the very time-consuming tests
# "test-external-data" is everything that needs data other than what's in the repo
TESTS_ALL_TARGETS := test-all test-nosampling test-triangulation-uncertainty test-external-data
$(TESTS_ALL_TARGETS): all
	@FAILED=""; $(foreach t,$(TESTS_$(subst -,_,$(patsubst test-%,%,$@))),echo "========== RUNNING: $(subst __, ,$t)"; $(subst __, ,$t) || FAILED="$$FAILED $t"; ) test -z "$$FAILED" || echo "SOME TEST SETS FAILED: $$FAILED !"; test -z "$$FAILED" && echo "ALL TEST SETS PASSED!"
.PHONY: $(TESTS_ALL_TARGETS)

test:
	@echo "Which test set should we run? I know about '$(TESTS_ALL_TARGETS)'" >> /dev/stderr; false
.PHONY: test
