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)
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)
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')
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')