Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: ui/gfx/geometry/scroll_offset_unittest.cc

Issue 584503005: Make scroll offset type of float in cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: link crbug to TODO Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/scroll_offset.cc ('k') | ui/gfx/gfx.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 #include <cmath>
6 #include <limits>
7
8 #include "base/basictypes.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/geometry/scroll_offset.h"
11
12 namespace gfx {
13
14 TEST(ScrollOffsetTest, IsZero) {
15 ScrollOffset zero(0, 0);
16 ScrollOffset nonzero(0.1, -0.1);
17
18 EXPECT_TRUE(zero.IsZero());
19 EXPECT_FALSE(nonzero.IsZero());
20 }
21
22 TEST(ScrollOffsetTest, Add) {
23 ScrollOffset f1(3.1, 5.1);
24 ScrollOffset f2(4.3, -1.3);
25
26 const struct {
27 ScrollOffset expected;
28 ScrollOffset actual;
29 } scroll_offset_tests[] = {
30 { ScrollOffset(3.1, 5.1), f1 + ScrollOffset() },
31 { ScrollOffset(3.1 + 4.3, 5.1f - 1.3), f1 + f2 },
32 { ScrollOffset(3.1 - 4.3, 5.1f + 1.3), f1 - f2 }
33 };
34
35 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(scroll_offset_tests); ++i)
36 EXPECT_EQ(scroll_offset_tests[i].expected.ToString(),
37 scroll_offset_tests[i].actual.ToString());
38 }
39
40 TEST(ScrollOffsetTest, Negative) {
41 const struct {
42 ScrollOffset expected;
43 ScrollOffset actual;
44 } scroll_offset_tests[] = {
45 { ScrollOffset(-0.3, -0.3), -ScrollOffset(0.3, 0.3) },
46 { ScrollOffset(0.3, 0.3), -ScrollOffset(-0.3, -0.3) },
47 { ScrollOffset(-0.3, 0.3), -ScrollOffset(0.3, -0.3) },
48 { ScrollOffset(0.3, -0.3), -ScrollOffset(-0.3, 0.3) }
49 };
50
51 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(scroll_offset_tests); ++i)
52 EXPECT_EQ(scroll_offset_tests[i].expected.ToString(),
53 scroll_offset_tests[i].actual.ToString());
54 }
55
56 TEST(ScrollOffsetTest, Scale) {
57 double double_values[][4] = {
58 { 4.5, 1.2, 3.3, 5.6 },
59 { 4.5, -1.2, 3.3, 5.6 },
60 { 4.5, 1.2, 3.3, -5.6 },
61 { 4.5, 1.2, -3.3, -5.6 },
62 { -4.5, 1.2, 3.3, 5.6 },
63 { -4.5, 1.2, 0, 5.6 },
64 { -4.5, 1.2, 3.3, 0 },
65 { 4.5, 0, 3.3, 5.6 },
66 { 0, 1.2, 3.3, 5.6 }
67 };
68
69 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(double_values); ++i) {
70 ScrollOffset v(double_values[i][0], double_values[i][1]);
71 v.Scale(double_values[i][2], double_values[i][3]);
72 EXPECT_EQ(v.x(), double_values[i][0] * double_values[i][2]);
73 EXPECT_EQ(v.y(), double_values[i][1] * double_values[i][3]);
74 }
75
76 double single_values[][3] = {
77 { 4.5, 1.2, 3.3 },
78 { 4.5, -1.2, 3.3 },
79 { 4.5, 1.2, 3.3 },
80 { 4.5, 1.2, -3.3 },
81 { -4.5, 1.2, 3.3 },
82 { -4.5, 1.2, 0 },
83 { -4.5, 1.2, 3.3 },
84 { 4.5, 0, 3.3 },
85 { 0, 1.2, 3.3 }
86 };
87
88 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(single_values); ++i) {
89 ScrollOffset v(single_values[i][0], single_values[i][1]);
90 v.Scale(single_values[i][2]);
91 EXPECT_EQ(v.x(), single_values[i][0] * single_values[i][2]);
92 EXPECT_EQ(v.y(), single_values[i][1] * single_values[i][2]);
93 }
94 }
95
96 TEST(ScrollOffsetTest, ClampScrollOffset) {
97 ScrollOffset a;
98
99 a = ScrollOffset(3.5, 5.5);
100 EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString());
101 a.SetToMax(ScrollOffset(2.5, 4.5));
102 EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString());
103 a.SetToMax(ScrollOffset(3.5, 5.5));
104 EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString());
105 a.SetToMax(ScrollOffset(4.5, 2.5));
106 EXPECT_EQ(ScrollOffset(4.5, 5.5).ToString(), a.ToString());
107 a.SetToMax(ScrollOffset(8.5, 10.5));
108 EXPECT_EQ(ScrollOffset(8.5, 10.5).ToString(), a.ToString());
109
110 a.SetToMin(ScrollOffset(9.5, 11.5));
111 EXPECT_EQ(ScrollOffset(8.5, 10.5).ToString(), a.ToString());
112 a.SetToMin(ScrollOffset(8.5, 10.5));
113 EXPECT_EQ(ScrollOffset(8.5, 10.5).ToString(), a.ToString());
114 a.SetToMin(ScrollOffset(11.5, 9.5));
115 EXPECT_EQ(ScrollOffset(8.5, 9.5).ToString(), a.ToString());
116 a.SetToMin(ScrollOffset(7.5, 11.5));
117 EXPECT_EQ(ScrollOffset(7.5, 9.5).ToString(), a.ToString());
118 a.SetToMin(ScrollOffset(3.5, 5.5));
119 EXPECT_EQ(ScrollOffset(3.5, 5.5).ToString(), a.ToString());
120 }
121
122 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/scroll_offset.cc ('k') | ui/gfx/gfx.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698