"""
TestManager.py
Author: Mike Lynch
Date: 12-19-06
COMS-W4115: Prof. Edwards

Maintains consistency between test cases and outputs, ensuring that
there are no duplicate expected outputs and that no test case is 
without expected output and vice versa
"""

import os

dsplExt = ".dspl"
errExt = ".err"
outExt = ".out"

def translateExt(originalFilename, newExt):
    dotPos = originalFilename.rfind(".")
    return originalFilename[:dotPos] + newExt

sourceFiles = os.listdir("testcases")
outFiles = os.listdir("testcases%scorrect" % (os.path.sep))

noOutput = []
noSource = []
duplicates = []

for sf in sourceFiles:
    if not sf.endswith(".dspl"):
        continue
    if translateExt(sf, errExt) not in outFiles and \
           translateExt(sf, outExt) not in outFiles:
        noOutput.append(sf)
        

for outFile in outFiles:
    if not outFile.endswith(errExt) and not outFile.endswith(outExt):
        continue
    
    if translateExt(outFile, dsplExt) not in sourceFiles:
        noSource.append(outFile)

    if outFile.endswith(errExt) and \
       translateExt(outFile, outExt) in outFiles:
        duplicates.append((outFile, translateExt(outFile, outExt)))

print "Files without an expected output file: %d" % (len(noOutput))
for nout in noOutput:
    print nout

print "\nFiles without a corresponding source file: %d" % (len(noSource))
for ns in noSource:
    print ns

print "\nDuplicate output files: %d" % (len(duplicates))
for d in duplicates:
    print "`%s' and `%s'" % (d[0], d[1])
