From f0ac5cb096cbf97f2a76ed176cc555408f5a5153 Mon Sep 17 00:00:00 2001 From: Gard Spreemann Date: Fri, 13 Mar 2020 13:57:14 +0100 Subject: Add test for python3-phat. --- debian/tests/python.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 debian/tests/python.py (limited to 'debian/tests/python.py') diff --git a/debian/tests/python.py b/debian/tests/python.py new file mode 100755 index 0000000..eaad48f --- /dev/null +++ b/debian/tests/python.py @@ -0,0 +1,46 @@ +import phat + +def main(): + files = ["single_triangle"] + + for file in files: + ref = [] + with open("debian/tests/reference/%s.txt" %(file), "r") as f: + f.readline() + for line in f: + splitline = line.strip().split(" ") + assert(len(splitline) == 2) + ref.append((int(splitline[0]), int(splitline[1]))) + ref.sort() + + cols = [] + with open("examples/%s.dat" %(file), "r") as f: + for line in f: + if not line.startswith("#") and line.strip() != "": + splitline = line.rstrip().split(" ") + cols.append((int(splitline[0]), [int(x) for x in splitline[1:]])) + + for repr in phat.representations: + for alg in phat.reductions: + for dualize in [False, True]: + print("File %s, representation %s, algorithm %s, dualization %s" %(file, repr, alg, str(dualize))) + + bd = phat.boundary_matrix(representation=repr) + bd.columns = cols + if dualize: + pairs = list(bd.compute_persistence_pairs_dualized(reduction=alg)) + else: + pairs = list(bd.compute_persistence_pairs(reduction=alg)) + pairs.sort() + + if ref == pairs: + print("OK!") + else: + print("ERROR!") + print("Got", pairs) + print("Expected", ref) + exit(1) + + +if __name__ == "__main__": + main() -- cgit v1.2.3