#! /usr/bin/env python

# Make sure that we advertize all the documentation we wrote.

import os
import re

nbdir = os.environ['nbdir']

# Make sure that all the existing documentation about algorithms is in
# Algorithm.ipynb.

referenced = set(re.findall(r'(\w+\.\w+\.ipynb)',
                            open(nbdir + '/Algorithms.ipynb').read()))

existing = set([f
                for f in os.listdir(path=nbdir)
                if re.match(r'(\w+\.\w+)\.ipynb', f)])

status = 0
dre = referenced - existing
if dre:
    print("error: referenced, not existing:", dre)
    status = 1
der = existing - referenced
if der:
    print("error: existing, not referenced:", der)
    status = 1

exit(status)
