예제 #1
0
파일: tests.py 프로젝트: cbwheadon/maths
 def test_simplest_form(self):
   fq1 = FractionWithConstant()
   fq1.const = -2
   fq1.num = 3
   fq1.denom = 2
   fq1.save()
   fq2 = fq1.simplest_form()
   self.assertEquals(fq2.const, -3)
   self.assertEquals(fq2.num, 1)      
   self.assertEquals(fq2.denom, 2)
예제 #2
0
파일: tests.py 프로젝트: cbwheadon/maths
 def test_basic_creation(self):
   fq = FractionWithConstant()
   fq.const = 1
   fq.num = 2
   fq.denom = 3
   fq.save()
   fqs = FractionWithConstant.objects.all()
   fq = fqs[0]
   self.assertEquals(fq.const,1)      
   self.assertEquals(fq.num,2)      
   self.assertEquals(fq.denom,3)
   desc = fq.describe()
   self.assertEquals(desc,'1 2/3')
예제 #3
0
파일: tests.py 프로젝트: cbwheadon/maths
 def test_zero_division_error(self):
   fq1 = FractionWithConstant()
   fq1.const = 1
   fq1.num = 4
   fq1.denom = 2
   fq1.save()
   fq2 = FractionWithConstant()
   fq2.const = 2
   fq2.num = 0
   fq2.denom = 0
   fq2.save()
   tst = fq1 == fq2
   self.assertEquals(tst,'ZeroDivisionError')  
예제 #4
0
파일: tests.py 프로젝트: cbwheadon/maths
 def test_two_fractions_not_equal(self):
   fq1 = FractionWithConstant()
   fq1.const = 1
   fq1.num = 4
   fq1.denom = 2
   fq1.save()
   fq2 = FractionWithConstant()
   fq2.const = 2
   fq2.num = 1
   fq2.denom = 2
   fq2.save()
   tst = fq1 == fq2
   self.assertEquals(tst,False)   
예제 #5
0
파일: tests.py 프로젝트: cbwheadon/maths
def createFraction(i,oper):
      if oper.oper_name == "+":      
        fs = ((3,1,2),(5,1,3)),((0,4,7),(0,2,5)),((3,2,3),(2,5,7)),((-3,3,4),(0,1,2))
        f_ans = (8,5,6),(0,34,35),(6,8,21),(-3,1,4)
      if oper.oper_name == "*":      
        fs = ((0,-1,3),(0,9,16)),((1,1,2),(2,1,5)),((-1,5,9),(-2,1,7)),((-2,3,5),(1,1,4))
        f_ans = (0,-3,16),(3,3,10),(3,1,3),(-3,1,4)        
      if oper.oper_name == "/":
        fs = ((0,1,2),(0,1,6)),((0,1,2),(3,0,1)),((2,1,2),(1,1,10)),((0,-3,4),(0,1,4))
        f_ans = (3,0,1),(0,1,6),(2,3,11),(-3,0,0)  
      if oper.oper_name == "-":
        fs = ((0,3,4),(0,1,4)),((15,3,4),(8,5,6)),((4,3,5),(1,9,10)),((0,1,2),(0,1,2))
        f_ans = (0,1,2),(6,11,12),(2,7,10),(0,1,0)
      q1 = FractionWithConstant()
      q1.const = fs[i][0][0]
      q1.num = fs[i][0][1]
      q1.denom = fs[i][0][2]
      q2 = FractionWithConstant()
      q2.const = fs[i][1][0]
      q2.num = fs[i][1][1]
      q2.denom = fs[i][1][2]
      ans = FractionWithConstant()
      ans.const = f_ans[i][0]
      ans.num = f_ans[i][1]
      ans.denom = f_ans[i][2]
      return[q1,q2,ans]