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

Side by Side Diff: ui/gfx/geometry/safe_integer_conversions_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/safe_integer_conversions.h ('k') | ui/gfx/geometry/scroll_offset.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/geometry/safe_integer_conversions.h" 5 #include "ui/gfx/geometry/safe_integer_conversions.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 30 matching lines...) Expand all
41 float infinity = std::numeric_limits<float>::infinity(); 41 float infinity = std::numeric_limits<float>::infinity();
42 42
43 int int_max = std::numeric_limits<int>::max(); 43 int int_max = std::numeric_limits<int>::max();
44 int int_min = std::numeric_limits<int>::min(); 44 int int_min = std::numeric_limits<int>::min();
45 45
46 EXPECT_EQ(int_max, ToFlooredInt(infinity)); 46 EXPECT_EQ(int_max, ToFlooredInt(infinity));
47 EXPECT_EQ(int_max, ToFlooredInt(max)); 47 EXPECT_EQ(int_max, ToFlooredInt(max));
48 EXPECT_EQ(int_max, ToFlooredInt(max + 100)); 48 EXPECT_EQ(int_max, ToFlooredInt(max + 100));
49 49
50 EXPECT_EQ(-101, ToFlooredInt(-100.5f)); 50 EXPECT_EQ(-101, ToFlooredInt(-100.5f));
51 EXPECT_EQ(0, ToFlooredInt(0)); 51 EXPECT_EQ(0, ToFlooredInt(0.f));
52 EXPECT_EQ(100, ToFlooredInt(100.5f)); 52 EXPECT_EQ(100, ToFlooredInt(100.5f));
53 53
54 EXPECT_EQ(int_min, ToFlooredInt(-infinity)); 54 EXPECT_EQ(int_min, ToFlooredInt(-infinity));
55 EXPECT_EQ(int_min, ToFlooredInt(min)); 55 EXPECT_EQ(int_min, ToFlooredInt(min));
56 EXPECT_EQ(int_min, ToFlooredInt(min - 100)); 56 EXPECT_EQ(int_min, ToFlooredInt(min - 100));
57 } 57 }
58 58
59 TEST(SafeIntegerConversions, ToCeiledInt) { 59 TEST(SafeIntegerConversions, ToCeiledInt) {
60 EXPECT_EQ(0, ToCeiledInt(std::numeric_limits<float>::quiet_NaN())); 60 EXPECT_EQ(0, ToCeiledInt(std::numeric_limits<float>::quiet_NaN()));
61 61
62 float max = std::numeric_limits<int>::max(); 62 float max = std::numeric_limits<int>::max();
63 float min = std::numeric_limits<int>::min(); 63 float min = std::numeric_limits<int>::min();
64 float infinity = std::numeric_limits<float>::infinity(); 64 float infinity = std::numeric_limits<float>::infinity();
65 65
66 int int_max = std::numeric_limits<int>::max(); 66 int int_max = std::numeric_limits<int>::max();
67 int int_min = std::numeric_limits<int>::min(); 67 int int_min = std::numeric_limits<int>::min();
68 68
69 EXPECT_EQ(int_max, ToCeiledInt(infinity)); 69 EXPECT_EQ(int_max, ToCeiledInt(infinity));
70 EXPECT_EQ(int_max, ToCeiledInt(max)); 70 EXPECT_EQ(int_max, ToCeiledInt(max));
71 EXPECT_EQ(int_max, ToCeiledInt(max + 100)); 71 EXPECT_EQ(int_max, ToCeiledInt(max + 100));
72 72
73 EXPECT_EQ(-100, ToCeiledInt(-100.5f)); 73 EXPECT_EQ(-100, ToCeiledInt(-100.5f));
74 EXPECT_EQ(0, ToCeiledInt(0)); 74 EXPECT_EQ(0, ToCeiledInt(0.f));
75 EXPECT_EQ(101, ToCeiledInt(100.5f)); 75 EXPECT_EQ(101, ToCeiledInt(100.5f));
76 76
77 EXPECT_EQ(int_min, ToCeiledInt(-infinity)); 77 EXPECT_EQ(int_min, ToCeiledInt(-infinity));
78 EXPECT_EQ(int_min, ToCeiledInt(min)); 78 EXPECT_EQ(int_min, ToCeiledInt(min));
79 EXPECT_EQ(int_min, ToCeiledInt(min - 100)); 79 EXPECT_EQ(int_min, ToCeiledInt(min - 100));
80 } 80 }
81 81
82 TEST(SafeIntegerConversions, ToRoundedInt) { 82 TEST(SafeIntegerConversions, ToRoundedInt) {
83 EXPECT_EQ(0, ToRoundedInt(std::numeric_limits<float>::quiet_NaN())); 83 EXPECT_EQ(0, ToRoundedInt(std::numeric_limits<float>::quiet_NaN()));
84 84
(...skipping 15 matching lines...) Expand all
100 EXPECT_EQ(100, ToRoundedInt(100.1f)); 100 EXPECT_EQ(100, ToRoundedInt(100.1f));
101 EXPECT_EQ(101, ToRoundedInt(100.5f)); 101 EXPECT_EQ(101, ToRoundedInt(100.5f));
102 EXPECT_EQ(101, ToRoundedInt(100.9f)); 102 EXPECT_EQ(101, ToRoundedInt(100.9f));
103 103
104 EXPECT_EQ(int_min, ToRoundedInt(-infinity)); 104 EXPECT_EQ(int_min, ToRoundedInt(-infinity));
105 EXPECT_EQ(int_min, ToRoundedInt(min)); 105 EXPECT_EQ(int_min, ToRoundedInt(min));
106 EXPECT_EQ(int_min, ToRoundedInt(min - 100)); 106 EXPECT_EQ(int_min, ToRoundedInt(min - 100));
107 } 107 }
108 108
109 } // namespace gfx 109 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/safe_integer_conversions.h ('k') | ui/gfx/geometry/scroll_offset.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698