1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3# 4############################################################################# 5## 6## Copyright (C) 2016 The Qt Company Ltd. 7## Contact: https://www.qt.io/licensing/ 8## 9## This file is part of the test suite of Qt for Python. 10## 11## $QT_BEGIN_LICENSE:GPL-EXCEPT$ 12## Commercial License Usage 13## Licensees holding valid commercial Qt licenses may use this file in 14## accordance with the commercial license agreement provided with the 15## Software or, alternatively, in accordance with the terms contained in 16## a written agreement between you and The Qt Company. For licensing terms 17## and conditions see https://www.qt.io/terms-conditions. For further 18## information use the contact form at https://www.qt.io/contact-us. 19## 20## GNU General Public License Usage 21## Alternatively, this file may be used under the terms of the GNU 22## General Public License version 3 as published by the Free Software 23## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 24## included in the packaging of this file. Please review the following 25## information to ensure the GNU General Public License requirements will 26## be met: https://www.gnu.org/licenses/gpl-3.0.html. 27## 28## $QT_END_LICENSE$ 29## 30############################################################################# 31 32'''Test cases for PointF class''' 33 34import os 35import sys 36import unittest 37 38sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 39from shiboken_paths import init_paths 40init_paths() 41 42from sample import PointF 43 44class PointFTest(unittest.TestCase): 45 '''Test case for PointF class, including operator overloads.''' 46 47 def testConstructor(self): 48 '''Test PointF class constructor.''' 49 pt = PointF(5.0, 2.3) 50 self.assertEqual(pt.x(), 5.0) 51 self.assertEqual(pt.y(), 2.3) 52 53 def testPlusOperator(self): 54 '''Test PointF class + operator.''' 55 pt1 = PointF(5.0, 2.3) 56 pt2 = PointF(0.5, 3.2) 57 self.assertEqual(pt1 + pt2, PointF(5.0 + 0.5, 2.3 + 3.2)) 58 59 def testEqualOperator(self): 60 '''Test PointF class == operator.''' 61 pt1 = PointF(5.0, 2.3) 62 pt2 = PointF(5.0, 2.3) 63 pt3 = PointF(0.5, 3.2) 64 self.assertTrue(pt1 == pt1) 65 self.assertTrue(pt1 == pt2) 66 self.assertFalse(pt1 == pt3) 67 68 def testModifiedMethod(self): 69 pt1 = PointF(0.0, 0.0) 70 pt2 = PointF(10.0, 10.0) 71 expected = PointF((pt1.x() + pt2.x()) / 2.0, (pt1.y() + pt2.y()) / 2.0) 72 self.assertEqual(pt1.midpoint(pt2), expected) 73 74if __name__ == '__main__': 75 unittest.main() 76