###############################################################################
# Coq Unit Testing project                                                    #
# Copyright 2015-2020 Catherine Dubois, Richard Genestier and Alain Giorgetti #
# Samovar - FEMTO-ST institute                                                #
###############################################################################

###############################################################################
#      This file is distributed under the terms of the                        #
#       GNU Lesser General Public License Version 2.1                         #
###############################################################################

# File: examples/coq/Makefile

WHY3SHARE=$(shell why3 --print-datadir)
# =/usr/local/share/why3 on my machine (Alain)

include $(WHY3SHARE)/Makefile.config
# The file /usr/local/share/why3/Makefile.config now contains:
# BIGINTLIB   = zarith
# INCLUDE     = -I /usr/lib/ocaml/zarith -I /usr/local/lib/ocaml/4.02.3/why3

.PHONY: all formal compile doc \
 rt \
 rt_listnat rt_blist rt_endoline rt_endofun rt_permut rt_revsubex rt_trans rt_rom \
 sc \
 sc_interval sc_endoline sc_endofun sc_fact sc_permline sc_permut \
 bet nrbet clean

# To check non-regression
all: formal compile rt sc bet nrbet clean

# Code presented at JFLA'19.
formal : prelude.v bFinFun.v \
 sc_interval.v val_sc_interval.v \
 listnat.v \
 blist.v sc_blist.v val_sc_blist.v \
 endoline.v sc_endoline.v val_sc_endoline.v \
 permline.v sc_permline.v val_sc_permline.v \
 cut.v \
 endofun.v sc_endofun.v val_sc_endofun.v \
 permut.v sc_permut.v val_sc_permut.v \
 revsubex.v \
 fact.v \
 qc.v qc_listnat.v
	coqc prelude.v
	coqc bFinFun.v
	coqc listnat.v    # Lists of natural numbers
	coqc blist.v      # Lists of natural numbers smaller than a given constant
	coqc endoline.v   # Endofunctions in one-line notation
	coqc permline.v   # Permutations in one-line notation
	coqc cut.v        # Tools for Coq unit testing with Prolog
	coqc endofun.v    # Endofunctions as natural functions
	coqc permut.v     # Permutations as injective endofunctions
	coqc revsubex.v   # Reversed subexcedant lists
	coqc fact.v       # Factorials
	coqc sc_interval.v     # Coq iterator in an interval
	coqc val_sc_interval.v # Tests of this iterator
	coqc sc_blist.v        # NEW IN CUT 2.2: Why3/OCaml generator of blists
	coqc val_sc_blist.v    # BET with this generator
	coqc sc_endoline.v     # Why3/OCaml generator of endofunctions in one-line notation
	coqc val_sc_endoline.v # BET with this generator
	coqc sc_endofun.v
	coqc val_sc_endofun.v
	coqc sc_permline.v
	coqc val_sc_permline.v
	coqc sc_permut.v
	coqc val_sc_permut.v
	coqc qc.v
	coqc qc_listnat.v

# Code presented in [DGG16].
compile : prelude.v bFinFun.v \
 listnat.v blist.v endoline.v \
 permline.v \
 cut.v \
 endofun.v permut.v \
 revsubex.v \
 operations.v trans.v map.v exec.v rom.v
	coqc prelude.v
	coqc bFinFun.v
	coqc listnat.v    # Lists of natural numbers
	coqc blist.v      # Lists of natural numbers smaller than a given constant
	coqc endoline.v   # Endofunctions in one-line notation
	coqc permline.v   # Permutations in one-line notation
	coqc cut.v        # Tools for Coq unit testing with Prolog
	coqc endofun.v    # Endofunctions as natural functions
	coqc permut.v     # Permutations as injective endofunctions
	coqc revsubex.v   # Reversed subexcedant lists
	coqc operations.v # Isthmic and non-isthmic map operations on permutations
	coqc trans.v      # Transitivity, cases of preservation by insertion
	coqc map.v        # Local maps, isthmic and non-isthmic operations on local maps
	coqc exec.v       # Boolean functions corresponding to lemmas in map.v
	coqc rom.v        # Recursive dependent type for rooted maps

doc: prelude.v bFinFun.v \
 sc_interval.v val_sc_interval.v \
 qc.v \
 listnat.v  qc_listnat.v  val_qc_listnat.v \
 blist.v    qc_blist.v    val_qc_blist.v    sc_blist.v    val_sc_blist.v \
 endoline.v qc_endoline.v val_qc_endoline.v sc_endoline.v val_sc_endoline.v \
 cut.v \
 endofun.v                val_qc_endofun.v  sc_endofun.v  val_sc_endofun.v \
 fact.v                                     sc_fact.v     val_sc_fact.v \
 permline.v                                 sc_permline.v val_sc_permline.v \
 permut.v   qc_permline.v val_qc_permut.v   sc_permut.v   val_sc_permut.v \
 revsubex.v qc_revsubex.v val_qc_revsubex.v \
 operations.v \
 trans.v val_qc_trans.v \
 map.v \
 exec.v \
 rom.v val_qc_rom.v
	coqdoc --latex -toc -utf8 --light $^ -o cut-examples.tex
	pdflatex cut-examples.tex
	pdflatex cut-examples.tex

# Test campaign presented in the paper entitled
# "Tests and Proofs for Custom Data Generators"

# Random testing in Coq (QuickCheck)
# Separated for time measurements
rt: rt_listnat rt_blist rt_endoline rt_endofun rt_permut rt_revsubex rt_trans rt_rom

# Added in CUT 2.1.
rt_listnat: qc.v qc_listnat.v val_qc_listnat.v
	coqc qc.v             # Tools for Coq random testing with QuickChick
	coqc qc_listnat.v     # Random generators of lists of natural numbers
	coqc val_qc_listnat.v

# Added in CUT 2.1.
rt_blist: qc.v qc_blist.v val_qc_blist.v
	coqc qc.v
	coqc qc_blist.v       # Random generators of bounded lists
	coqc val_qc_blist.v

rt_endoline: qc.v qc_endoline.v val_qc_endoline.v
	coqc qc.v
	coqc qc_endoline.v    # Random generators of endofunctions in one-line notation
	coqc val_qc_endoline.v

rt_endofun: qc.v qc_listnat.v qc_endoline.v val_qc_endofun.v
	coqc qc.v
	coqc qc_listnat.v
	coqc qc_blist.v
	coqc qc_endoline.v
	coqc val_qc_endofun.v

rt_permut: qc.v qc_endoline.v qc_permline.v val_qc_permut.v
	coqc qc.v
	coqc qc_endoline.v
	coqc qc_permline.v
	coqc val_qc_permut.v

# Added in CUT 2.1.
rt_revsubex: qc.v qc_revsubex.v val_qc_revsubex.v
	coqc qc.v
	coqc qc_revsubex.v
	coqc val_qc_revsubex.v

rt_trans: qc.v qc_permline.v val_qc_trans.v
	coqc qc.v
	coqc qc_permline.v
	coqc val_qc_trans.v

# Added in CUT 2.0.
rt_rom: rom.v qc.v qc_revsubex.v qc_rom.v val_qc_rom.v
	coqc rom.v
	coqc qc.v
	coqc qc_revsubex.v
	coqc qc_rom.v       # Random generator of ROM terms
	coqc val_qc_rom.v


# Bounded exhaustive testing in Coq (SmallCheck*), added in CUT 2.1,
# extended with sc_blist in CUT 2.2.
sc: compile sc_interval sc_endoline sc_endofun sc_blist sc_fact sc_permline sc_permut

sc_interval: Sc.v sc_interval.v val_sc_interval.v
	coqc Sc.v
	coqc sc_interval.v
	coqc val_sc_interval.v

sc_blist: prelude.v cut.v listnat.v blist.v Sc.v sc_interval.v sc_blist.v val_sc_blist.v
	coqc prelude.v
	coqc cut.v
	coqc listnat.v
	coqc blist.v
	coqc Sc.v
	coqc sc_interval.v
	coqc sc_blist.v
	coqc val_sc_blist.v

sc_endoline: prelude.v cut.v listnat.v blist.v endoline.v Sc.v sc_interval.v sc_endoline.v val_sc_endoline.v
	coqc prelude.v
	coqc cut.v
	coqc listnat.v
	coqc blist.v
	coqc endoline.v
	coqc Sc.v
	coqc sc_interval.v
	coqc sc_endoline.v
	coqc val_sc_endoline.v

sc_endofun: prelude.v cut.v listnat.v blist.v endoline.v endofun.v Sc.v sc_interval.v sc_endoline.v sc_endofun.v val_sc_endofun.v
	coqc prelude.v
	coqc cut.v
	coqc listnat.v
	coqc blist.v
	coqc endoline.v
	coqc endofun.v
	coqc Sc.v
	coqc sc_interval.v
	coqc sc_endoline.v
	coqc sc_endofun.v
	coqc val_sc_endofun.v

sc_fact: prelude.v bFinFun.v listnat.v endofun.v permut.v revsubex.v fact.v Sc.v sc_interval.v sc_fact.v val_sc_fact.v
	coqc bFinFun.v
	coqc prelude.v
	coqc listnat.v
	coqc endofun.v
	coqc permut.v
	coqc revsubex.v
	coqc fact.v
	coqc Sc.v
	coqc sc_interval.v
	coqc sc_fact.v
	coqc val_sc_fact.v

sc_permline: prelude.v cut.v permline.v Sc.v sc_interval.v sc_permline.v val_sc_permline.v
	coqc prelude.v
	coqc cut.v
	coqc permline.v
	coqc Sc.v
	coqc sc_interval.v
	coqc sc_permline.v
	coqc val_sc_permline.v

sc_permut: prelude.v cut.v endofun.v permut.v operations.v Sc.v sc_interval.v sc_permline.v sc_permut.v val_sc_permut.v
	coqc prelude.v
	coqc cut.v
	coqc endofun.v
	coqc permut.v
	coqc operations.v
	coqc Sc.v
	coqc sc_interval.v
	coqc sc_permline.v
	coqc sc_permut.v
	coqc val_sc_permut.v

# Bounded exhaustive testing with Prolog

# Reflexive BET
bet: compile
	coqc val_permut.v
	coqc val_operations.v
	coqc val_trans.v
	coqc val_map.v

# Non-reflexive BET. Warning: long
nrbet: compile
	coqc val_permut_non_refl.v

clean:
	rm -f *.glob *.vo .*.aux *.bak *.cmi *.cmx *.o
