#!/usr/local/bin/python
#
# File:        orderingtest
# Copyright:   (c) 2002 The Regents of the University of California
# Release:     $Name: release-0-8-8 $
# Revision:    @(#) $Revision: 1.3 $
# Date:        $Date: 2003/08/06 16:57:40 $
# Description: Exercise array ordering code
#
# Try to exercise everything possible in Python.

from Ordering.IntOrderTest import *
from Numeric import *

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__':
    counter = TestCounter()
    A = makeColumnIMatrix(10, 1)
    counter.describeTest("makeColumnIMatrix(10,1) != None")
    counter.evalTest(A, 1)

    counter.describeTest("isIMatrixTwo(A)")
    counter.evalTest(isIMatrixTwo(A), 1)

    counter.describeTest("isColumnIMatrixTwo(A)")
    counter.evalTest(isColumnIMatrixTwo(A), 1)

    counter.describeTest("isRowIMatrixTwo(A)")
    counter.evalTest(isRowIMatrixTwo(A), 1)

    counter.describeTest("A = ensureRow(A) then isIMatrixTwo(A)")
    A = ensureRow(A)
    counter.evalTest(isIMatrixTwo(A), 1)

    counter.describeTest("A = ensureColumn(A) then isIMatrixTwo(A)")
    A = ensureColumn(A)
    counter.evalTest(isIMatrixTwo(A), 1)

    A = None

    A = makeRowIMatrix(10, 0)
    counter.describeTest("A != None and isIMatrixTwo(A)")
    counter.evalTest(A and isIMatrixTwo(A), 1)
    counter.describeTest("A != None and isColumnIMatrixTwo(A)")
    counter.evalTest(A and isColumnIMatrixTwo(A), 1)
    A = None

    A = makeRowIMatrix(10, 1)
    counter.describeTest("A != None and isIMatrixTwo(A)")
    counter.evalTest(A and isIMatrixTwo(A), 1)
    A = None

    A = createColumnIMatrix(10, 1)
    counter.describeTest("A = createColumnIMatrix -> A != None")
    counter.evalTest(A and isIMatrixTwo(A), 1)
    A = None

    A = makeIMatrix(4, 1)
    counter.describeTest("A != None and isIMatrixFour(A)")
    counter.evalTest(A and isIMatrixFour(A), 1)
    A = None

    counter.describeTest("isSliceWorking(1)")
    counter.evalTest(isSliceWorking(1), 1)
    
    counter.describeTest("isSliceWorking(0)")
    counter.evalTest(isSliceWorking(0), 1)

    counter.finish()
0
