| OLD | NEW |
| (Empty) |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Tests for the geometry module.""" | |
| 6 | |
| 7 import unittest | |
| 8 | |
| 9 from devil.utils import geometry as g | |
| 10 | |
| 11 | |
| 12 class PointTest(unittest.TestCase): | |
| 13 def testStr(self): | |
| 14 p = g.Point(1, 2) | |
| 15 self.assertEquals(str(p), '(1, 2)') | |
| 16 | |
| 17 def testAdd(self): | |
| 18 p = g.Point(1, 2) | |
| 19 q = g.Point(3, 4) | |
| 20 r = g.Point(4, 6) | |
| 21 self.assertEquals(p + q, r) | |
| 22 | |
| 23 def testAdd_TypeErrorWithInvalidOperands(self): | |
| 24 # pylint: disable=pointless-statement | |
| 25 p = g.Point(1, 2) | |
| 26 with self.assertRaises(TypeError): | |
| 27 p + 4 # Can't add point and scalar. | |
| 28 with self.assertRaises(TypeError): | |
| 29 4 + p # Can't add scalar and point. | |
| 30 | |
| 31 def testMult(self): | |
| 32 p = g.Point(1, 2) | |
| 33 r = g.Point(2, 4) | |
| 34 self.assertEquals(2 * p, r) # Multiply by scalar on the left. | |
| 35 | |
| 36 def testMult_TypeErrorWithInvalidOperands(self): | |
| 37 # pylint: disable=pointless-statement | |
| 38 p = g.Point(1, 2) | |
| 39 q = g.Point(2, 4) | |
| 40 with self.assertRaises(TypeError): | |
| 41 p * q # Can't multiply points. | |
| 42 with self.assertRaises(TypeError): | |
| 43 p * 4 # Can't multiply by a scalar on the right. | |
| 44 | |
| 45 class RectangleTest(unittest.TestCase): | |
| 46 def testStr(self): | |
| 47 r = g.Rectangle(g.Point(0, 1), g.Point(2, 3)) | |
| 48 self.assertEquals(str(r), '[(0, 1), (2, 3)]') | |
| 49 | |
| 50 def testCenter(self): | |
| 51 r = g.Rectangle(g.Point(0, 1), g.Point(2, 3)) | |
| 52 c = g.Point(1, 2) | |
| 53 self.assertEquals(r.center, c) | |
| 54 | |
| 55 def testFromJson(self): | |
| 56 r1 = g.Rectangle(g.Point(0, 1), g.Point(2, 3)) | |
| 57 r2 = g.Rectangle.FromDict({'top': 1, 'left': 0, 'bottom': 3, 'right': 2}) | |
| 58 self.assertEquals(r1, r2) | |
| OLD | NEW |