aboutsummaryrefslogtreecommitdiffstats
path: root/unittest/RationalTestCase.py
blob: 74133998ec2cd5a11767b45b2d80d38e895c8a5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# -*- coding: utf-8 -*-

# ******************************************************************************
#
# Copyright (C) 2006-2007 Olivier Tilloy <olivier@tilloy.net>
#
# This file is part of the pyexiv2 distribution.
#
# pyexiv2 is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# pyexiv2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyexiv2; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA.
#
#
# File:      RationalTestCase.py
# Author(s): Olivier Tilloy <olivier@tilloy.net>
#
# ******************************************************************************

import unittest
import pyexiv2

class RationalTestCase(unittest.TestCase):

    """
    Test case on the pyexiv2.Rational class.
    """

    def testConstructor(self):
        """
        Test that the rational number constructor works as expected.
        """
        r = pyexiv2.Rational(2, 1)
        self.assertEqual(r.numerator, 2)
        self.assertEqual(r.denominator, 1)

    def testException(self):
        """
        Test that the constructor throws an exception when denominator is zero.
        """
        self.assertRaises(ZeroDivisionError, pyexiv2.Rational, 1, 0)

    def testEquality(self):
        """
        Test the (non) equality of two rational numbers.
        """
        r1 = pyexiv2.Rational(2, 1)
        r2 = pyexiv2.Rational(2, 1)
        r3 = pyexiv2.Rational(3, 1)
        self.assertEqual(r1, r2)
        self.assertNotEqual(r1, r3)