Exemplo n.º 1
0
 def test__div__KnownValues(self):
     """__div__ should give known result with known input"""
     x=units.NumberDict()
     x=units.NumberDict([('t1',1),('t2',2)])
     y=10.0
     result1=x/y
     self.assertEqual((.1,.20), (result1['t1'],result1['t2']))
Exemplo n.º 2
0
 def test__add__KnownValues(self):
     """__add__ should give known result with known input
     for non-string data types, addition must be commutative"""
     x=units.NumberDict()
     y=units.NumberDict()
     x['t1'],x['t2']= 1,2
     y['t1'],y['t2']=2,1
     result1,result2=x+y,y+x
     self.assertEqual((3,3), (result1['t1'],result1['t2']))
     self.assertEqual((3,3), (result2['t1'],result2['t2']))
Exemplo n.º 3
0
    def test__sub__KnownValues(self):
        """__sub__ should give known result with known input
        commuting the input should result in equal magnitude, opposite sign"""

        x=units.NumberDict()
        y=units.NumberDict()
        x['t1'],x['t2']= 1,2
        y['t1'],y['t2']= 2,1
        result1,result2=x-y,y-x
        self.assertEqual((-1,1), (result1['t1'],result1['t2']))
        self.assertEqual((1,-1), (result2['t1'],result2['t2']))
Exemplo n.º 4
0
 def test__mul__KnownValues(self):
     """__mul__ should give known result with known input"""
     x=units.NumberDict([('t1',1),('t2',2)])
     y=10
     result1,result2=x*y,y*x
     self.assertEqual((10,20), (result1['t1'],result1['t2']))
     self.assertEqual((10,20), (result2['t1'],result2['t2']))
Exemplo n.º 5
0
 def test__UknownKeyGives0(self):
     """a NumberDict instance should initilize using integer and non-integer indices
     a NumberDict instance should initilize all entries with an initial value of 0"""
     x=units.NumberDict()
     #integer test
     self.assertEqual(x[0],0)
     #string test
     self.assertEqual(x['t'],0)