示例#1
0
    def lnPressed(self):
        self.equalsPressed()
        if self.labelAns == 'ERROR':
            return

        try:
            self.ans = str(Mathlibrary.ln(float(self.labelAns.text())))
        except:
            self.labelAns.setText('ERROR')
            self.labelWrite.setText('')
            self.lastCharacter = ''
            self.lastButton = ''
            self.decimalPoint = False
            self.ans = '0'
            return

        self.labelAns.setText(self.ans)
        self.labelWrite.setText('')
        self.lastCharacter = ''
        self.lastButton = 'dig'
        self.decimalPoint = False
示例#2
0
class MathLibraryTestLn(unittest.TestCase):
    def setUp(self):
        self.mathlib = Mathlibrary()

    def testLnNegative(self):
        with self.assertRaises(ValueError):
            self.mathlib.ln(-123)
        with self.assertRaises(ValueError):
            self.mathlib.ln(-0.00001)
        with self.assertRaises(ValueError):
            self.mathlib.ln(-41928501)

    def testLnZero(self):
        with self.assertRaises(ValueError):
            self.mathlib.ln(0)
        with self.assertRaises(ValueError):
            self.mathlib.ln(0.00000)

    def testLnNaturalNumberGreaterThanOne(self):
        self.assertAlmostEqual(self.mathlib.ln(math.e), 1)
        self.assertAlmostEqual(self.mathlib.ln(2), 0.693147180)
        self.assertAlmostEqual(self.mathlib.ln(42), 3.73766961828)
        self.assertAlmostEqual(self.mathlib.ln(17349), 9.76129014682632)

    def testLnNaturalNumberLowerThanOne(self):
        self.assertAlmostEqual(self.mathlib.ln(0.8257), -0.19152376755875)
        self.assertAlmostEqual(self.mathlib.ln(0.541), -0.6143360001356)
        self.assertAlmostEqual(self.mathlib.ln(0.0042), -5.472670753692814)