• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import unittest
6
7from crossbench.action_runner.display_rectangle import DisplayRectangle
8from crossbench.benchmarks.loading.point import Point
9
10
11class DisplayRectangleTestCase(unittest.TestCase):
12
13  def test_display_rectangle_mul(self):
14    rect: DisplayRectangle = DisplayRectangle(Point(1, 2), 3, 4)
15
16    rect = rect * 5
17
18    self.assertEqual(rect.origin.x, 5)
19    self.assertEqual(rect.origin.y, 10)
20    self.assertEqual(rect.width, 15)
21    self.assertEqual(rect.height, 20)
22
23  def test_display_rectangle_shift_by(self):
24    rect: DisplayRectangle = DisplayRectangle(Point(1, 2), 3, 4)
25    rect2: DisplayRectangle = DisplayRectangle(Point(10, 20), 30, 40)
26
27    rect = rect.shift_by(rect2)
28
29    self.assertEqual(rect.origin.x, 11)
30    self.assertEqual(rect.origin.y, 22)
31    self.assertEqual(rect.width, 3)
32    self.assertEqual(rect.height, 4)
33
34  def test_display_rectangle_mid_x(self):
35    rect: DisplayRectangle = DisplayRectangle(Point(1, 2), 6, 8)
36
37    self.assertEqual(rect.mid_x, 4)
38
39  def test_display_rectangle_mid_y(self):
40    rect: DisplayRectangle = DisplayRectangle(Point(1, 2), 6, 8)
41
42    self.assertEqual(rect.mid_y, 6)
43
44  def test_display_rectangle_middle(self):
45    rect: DisplayRectangle = DisplayRectangle(Point(1, 2), 6, 8)
46
47    self.assertEqual(rect.middle, Point(4, 6))
48
49  def test_display_rectangle_truthy(self):
50    self.assertFalse(DisplayRectangle(Point(1, 2), 0, 0))
51    self.assertFalse(DisplayRectangle(Point(5, 6), 0, 1))
52    self.assertFalse(DisplayRectangle(Point(3, 4), 1, 0))
53    self.assertTrue(DisplayRectangle(Point(1, 2), 1, 1))
54