#!/usr/local/bin/python
#
# File:        sorttest
# Copyright:   (c) 2002 The Regents of the University of California
# Release:     $Name: release-0-8-8 $
# Revision:    $Revision: 1.1 $
# Date:        $Date: 2002/06/13 23:32:18 $
# Description: Excercise interfaces and abstract classes
#

import sort.MergeSort
import sort.QuickSort
import sort.HeapSort
import sort.SortTest

class TestCounter:
  partno = 0
  numpass = 0
  numfail = 0
  numxfail = 0
  numxpass = 0

  def __init__(self, numparts = -1):
    self.numparts = numparts
    print "NPARTS", numparts

  def describeTest(self, description):
    self.partno = self.partno + 1
    print "PART", self.partno
    print "COMMENT:", description

  def evalTest(self, result, expected):
    if (result):
      if (expected):
        self.numpass = self.numpass + 1
        print "RESULT", self.partno, "PASS"
      else:
        self.numxpass = self.numxpass + 1
        print "RESULT", self.partno, "XPASS"
    else:
      if (expected):
        self.numfail = self.numfail + 1
        print "RESULT", self.partno, "FAIL"
      else:
        self.numxfail = self.numxfail + 1
        print "RESULT", self.partno, "XFAIL"
        
  def finish(self):
    if (self.numparts < 0):
      self.numparts = self.partno
    if (self.numpass == self.numparts):
      print "TEST_RESULT PASS"
    else:
      if (self.numpass + self.numxfail == self.numparts):
        print "TEST_RESULT XFAIL"
      else:
        print "TEST_RESULT FAIL"

if __name__ == '__main__':
    test = TestCounter(4)
    merge = sort.MergeSort.MergeSort()
    quick = sort.QuickSort.QuickSort()
    heap = sort.HeapSort.HeapSort()
    test.describeTest("merge != None")
    test.evalTest(merge, 1)
    test.describeTest("quick != None")
    test.evalTest(quick, 1)
    test.describeTest("heap != None")
    test.evalTest(heap, 1)
    test.describeTest("sort.SortTest.stressTest([merge, quick, heap])")
    test.evalTest(sort.SortTest.stressTest([merge, quick, heap]), 1)
    test.finish()
