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

Side by Side Diff: ui/gfx/size_unittest.cc

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vector length and conversion to size Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/size_base.h" 5 #include "ui/gfx/size_base.h"
6 6
7 #include "base/basictypes.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 #include "ui/gfx/size.h" 9 #include "ui/gfx/size.h"
9 #include "ui/gfx/size_conversions.h" 10 #include "ui/gfx/size_conversions.h"
10 #include "ui/gfx/size_f.h" 11 #include "ui/gfx/size_f.h"
11 12
12 namespace ui { 13 namespace ui {
13 14
14 namespace { 15 namespace {
15 16
16 int TestSizeF(const gfx::SizeF& s) { 17 int TestSizeF(const gfx::SizeF& s) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 EXPECT_EQ(gfx::Size(-10, -10), 130 EXPECT_EQ(gfx::Size(-10, -10),
130 gfx::ToRoundedSize(gfx::SizeF(-10.0001f, -10.0001f))); 131 gfx::ToRoundedSize(gfx::SizeF(-10.0001f, -10.0001f)));
131 EXPECT_EQ(gfx::Size(-10, -10), 132 EXPECT_EQ(gfx::Size(-10, -10),
132 gfx::ToRoundedSize(gfx::SizeF(-10.4999f, -10.4999f))); 133 gfx::ToRoundedSize(gfx::SizeF(-10.4999f, -10.4999f)));
133 EXPECT_EQ(gfx::Size(-11, -11), 134 EXPECT_EQ(gfx::Size(-11, -11),
134 gfx::ToRoundedSize(gfx::SizeF(-10.5f, -10.5f))); 135 gfx::ToRoundedSize(gfx::SizeF(-10.5f, -10.5f)));
135 EXPECT_EQ(gfx::Size(-11, -11), 136 EXPECT_EQ(gfx::Size(-11, -11),
136 gfx::ToRoundedSize(gfx::SizeF(-10.9999f, -10.9999f))); 137 gfx::ToRoundedSize(gfx::SizeF(-10.9999f, -10.9999f)));
137 } 138 }
138 139
140 TEST(SizeTest, SizeOfVector) {
141 int int_tests[][2] = {
142 { 0, 0 },
143 { 0, -1 },
144 { -1, 0 },
145 { 1, -1 },
146 { 1, 1 },
147 { -1, 1 },
148 { -1, -1 }
149 };
150
151 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(int_tests); ++i) {
152 int abs0 = std::abs(int_tests[i][0]);
153 int abs1 = std::abs(int_tests[i][1]);
154 gfx::Size expected(abs0, abs1);
155 gfx::Vector2d vector(int_tests[i][0], int_tests[i][1]);
156 EXPECT_EQ(expected.ToString(), SizeOfVector2d(vector).ToString());
157 }
158
159 float float_tests[][2] = {
160 { 0, 0 },
161 { 0, -0.1f },
162 { -0.1f, 0 },
163 { 0.1f, -0.1f },
164 { 0.1f, 0.1f },
165 { -0.1f, 0.1f },
166 { -0.1f, -0.1f }
167 };
168
169 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(float_tests); ++i) {
170 float abs0 = std::abs(float_tests[i][0]);
171 float abs1 = std::abs(float_tests[i][1]);
172 gfx::SizeF expected(abs0, abs1);
173 gfx::Vector2dF vector(float_tests[i][0], float_tests[i][1]);
174 EXPECT_EQ(expected.ToString(), SizeOfVector2d(vector).ToString());
175 }
176 }
177
139 } // namespace ui 178 } // namespace ui
OLDNEW
« ui/gfx/point_f.h ('K') | « ui/gfx/size_f.h ('k') | ui/gfx/vector2d.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698