Changeset 2867


Ignore:
Timestamp:
Jul 28, 2010 11:11:25 AM (9 years ago)
Author:
prsteel
Message:

Updated test cases for set equality and inequality.

Original test cases (#1, #2) relied upon a TypeError? being thrown,
which is no longer the case. These two tests now properly check for
equality and inequality between empty and non-empty sets.

Added test_equality_3, which tests set equality and inequality between
various Set and non-Set objects. This is actually an overdue test case
for revision #2820, which stopped Pyomo from failing when comparing
Set and non-Set objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/coopr/pyomo/tests/unit/test_set.py

    r2813 r2867  
    689689        self.model.tmpset3 = Set()
    690690
     691        self.model.S = RangeSet(0,5)
     692        self.model.T = RangeSet(0,5)
     693        self.model.R = RangeSet(0,3)
     694        self.model.Q_a = Set(initialize=[1,3,5,7])
     695        self.model.Q_c = Set(initialize=[3,5,7,9])
     696
    691697        self.instance = self.model.create(currdir+"setA.dat")
    692698        self.e1=('A1',1)
     
    804810
    805811    def test_eq1(self):
    806         """Various checks for set equality and inequality (1)"""
    807         try:
    808           self.failUnlessEqual( self.instance.A == self.instance.tmpset1, True)
    809           self.failUnlessEqual( self.instance.tmpset1 == self.instance.A, True)
    810           self.failUnlessEqual( self.instance.A != self.instance.tmpset1, False)
    811           self.failUnlessEqual( self.instance.tmpset1 != self.instance.A, False)
    812         except TypeError:
    813           pass
    814         else:
    815           self.fail("fail test_eq1")
     812        """ Various checks for set equality and inequality (1) """
     813        self.failUnlessEqual(self.instance.A != self.instance.tmpset1, True)
     814        self.failUnlessEqual(self.instance.tmpset1 != self.instance.A, True)
     815        self.failUnlessEqual(self.instance.A == self.instance.tmpset1, False)
     816        self.failUnlessEqual(self.instance.tmpset1 == self.instance.A, False)
    816817
    817818    def test_eq2(self):
    818         """Various checks for set equality and inequality (2)"""
    819         try:
    820           self.failUnlessEqual( self.instance.A == self.instance.tmpset2, False)
    821           self.failUnlessEqual( self.instance.tmpset2 == self.instance.A, False)
    822           self.failUnlessEqual( self.instance.A != self.instance.tmpset2, True)
    823           self.failUnlessEqual( self.instance.tmpset2 != self.instance.A, True)
    824         except TypeError:
    825           pass
    826         else:
    827           self.fail("fail test_eq2")
     819        """ Various checks for set equality and inequality (2) """
     820        self.failUnlessEqual(self.instance.A == self.instance.tmpset2, False)
     821        self.failUnlessEqual(self.instance.tmpset2 == self.instance.A, False)
     822        self.failUnlessEqual(self.instance.A != self.instance.tmpset2, True)
     823        self.failUnlessEqual(self.instance.tmpset2 != self.instance.A, True)
     824
     825    def test_eq3(self):
     826        """ Various checks for set equality and inequality (3) """
     827
     828        # Each test should be done with the arguments on each side to check
     829        # for commutativity
     830
     831        # Self-equality
     832        self.failUnlessEqual(self.instance.S == self.instance.S, True)
     833        self.failUnlessEqual(self.instance.S != self.instance.S, False)
     834
     835        # Equivalent members
     836        self.failUnlessEqual(self.instance.S == self.instance.T, True)
     837        self.failUnlessEqual(self.instance.T == self.instance.S, True)
     838
     839        # Subset/superset nonequality
     840        self.failUnlessEqual(self.instance.S != self.instance.R, True)
     841        self.failUnlessEqual(self.instance.R != self.instance.S, True)
     842
     843        # Manually initialized (Q_a) v. data file initialized (A["A"]) equality
     844        self.failUnlessEqual(self.instance.A["A"] == self.instance.Q_a, True)
     845        self.failUnlessEqual(self.instance.Q_a == self.instance.A["A"], True)
     846
     847        # Manually initialized (Q_c) v. data file initialized (A["C"]) equality
     848        self.failUnlessEqual(self.instance.A["C"] == self.instance.Q_c, True)
     849        self.failUnlessEqual(self.instance.Q_c == self.instance.A["C"], True)
     850
     851        # Comparison between Set and non-Set objects
     852        self.failUnlessEqual(self.instance.A == 1.0, False)
     853        self.failUnlessEqual(1.0 == self.instance.A, False)
     854
     855        # Comparison between Set and non-Set objects
     856        self.failUnlessEqual(self.instance.A != 1.0, True)
     857        self.failUnlessEqual(1.0 != self.instance.A, True)
    828858
    829859    def test_contains(self):
Note: See TracChangeset for help on using the changeset viewer.