# which_python=/usr
# which_python=/usr/local
which_python=/usr/local/cpython-3.11

go: tags
	./this-pylint --which-2 None --which-3 ${which_python}/bin/pylint --to-pylint histogram
	${which_python}/bin/mypy --disallow-untyped-calls histogram
	(seq 11; seq 5; seq 2) > rm-me; ./histogram --percent --bin-function decile --input-file rm-me > first-actual.txt
	diff -u first-expected.txt first-actual.txt
	rm -f rm-me
	echo 1 | ./histogram
	(seq 10; seq 5; seq 2) | ./histogram
	(seq 11; seq 5; seq 2; seq 3) | ./histogram
	(seq 11; seq 5; seq 2; seq 3) | ./histogram --bin-function "square root"
	(seq 11; seq 5; seq 2; seq 3) | ./histogram --bin-function "sturges formula"
	(seq 11; seq 5; seq 2; seq 3) | ./histogram --bin-function "rice rule"
	(seq 11; seq 5; seq 2; seq 3) | ./histogram --bin-function "quartile"
	(seq 11; seq 5; seq 2; seq 3) | ./histogram --bin-function "decile"
	(seq 11; seq 5; seq 2; seq 3) | ./histogram --bin-function "twentyfifth-ile"
	(seq 11; seq 5; seq 2; seq 3) | ./histogram --bin-function "percentile"
	! ./histogram --bin-function "unknown"
	(seq 10; seq 5; seq 2) | ./histogram --force-string
	(seq 10; seq 5; seq 2) | ./histogram --display-width 20 | sort -n
	(seq 10; seq 5; seq 2) | ./histogram --tabbed | expand -20,40 | sort -n
	./histogram --help
	! ./histogram --bad
	find /usr/local -type f -ls | awk ' { print $$3 }' | ./histogram | sort -n | tail -20
	find /usr/local -type f -ls | awk ' { print $$3 }' | ./histogram --elide | sort -n > h.dat
	printf 'a\nb\na\nb\nc\na\n' | ./histogram
	find /usr/local -type f -ls | awk ' { print $$3 }' | sort | uniq -c | sort -n > u.dat
	diff -w -u h.dat u.dat
	./histogram < /dev/null
	seq 1000000 | ./histogram --bin-function 'square root' > /dev/null  # here we want to see if it takes prohibitively long to run
	@echo All tests passed.

.PHONY: tags
tags:
	ln -sf histogram histogram.py
	ctags-exuberant histogram.py || ctags histogram.py

install:
	./install-file --file histogram --directory /usr/local/bin/.

clean:
	rm -f h.dat u.dat first-actual.txt rm-me histogram.py tags
	rm -rf .mypy_cache