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

Side by Side Diff: runtime/vm/intermediate_language_test.cc

Issue 321593004: Refactor RangeBoundary +/- infinity to be distinct RangeBoundary kinds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 #include "vm/unit_test.h" 6 #include "vm/unit_test.h"
7 7
8 namespace dart { 8 namespace dart {
9 9
10 TEST_CASE(InstructionTests) { 10 TEST_CASE(InstructionTests) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 RangeBoundary::FromConstant(0)); 46 RangeBoundary::FromConstant(0));
47 Range* positive = new Range( 47 Range* positive = new Range(
48 RangeBoundary::FromConstant(0), 48 RangeBoundary::FromConstant(0),
49 RangeBoundary::FromConstant(100)); 49 RangeBoundary::FromConstant(100));
50 Range* negative = new Range( 50 Range* negative = new Range(
51 RangeBoundary::FromConstant(-1), 51 RangeBoundary::FromConstant(-1),
52 RangeBoundary::FromConstant(-100)); 52 RangeBoundary::FromConstant(-100));
53 Range* range_x = new Range( 53 Range* range_x = new Range(
54 RangeBoundary::FromConstant(-15), 54 RangeBoundary::FromConstant(-15),
55 RangeBoundary::FromConstant(100)); 55 RangeBoundary::FromConstant(100));
56 EXPECT(negative->IsNegative());
57 EXPECT(positive->IsPositive());
56 EXPECT(zero->Overlaps(0, 0)); 58 EXPECT(zero->Overlaps(0, 0));
57 EXPECT(positive->Overlaps(0, 0)); 59 EXPECT(positive->Overlaps(0, 0));
58 EXPECT(!negative->Overlaps(0, 0)); 60 EXPECT(!negative->Overlaps(0, 0));
59 EXPECT(range_x->Overlaps(0, 0)); 61 EXPECT(range_x->Overlaps(0, 0));
62 EXPECT(range_x->IsWithin(-15, 100));
63 EXPECT(!range_x->IsWithin(-15, 99));
64 EXPECT(!range_x->IsWithin(-14, 100));
65 }
66
67
68 TEST_CASE(RangeTestsInfinity) {
69 // +/- inf overflowed.
70 EXPECT(RangeBoundary::NegativeInfinity().Overflowed());
71 EXPECT(RangeBoundary::PositiveInfinity().Overflowed());
72
73 Range* all = new Range(RangeBoundary::NegativeInfinity(),
74 RangeBoundary::PositiveInfinity());
75 EXPECT(all->Overlaps(0, 0));
76 EXPECT(all->Overlaps(-1, 1));
77 EXPECT(!all->IsWithin(0, 100));
78 Range* positive = new Range(RangeBoundary::FromConstant(0),
79 RangeBoundary::PositiveInfinity());
80 EXPECT(positive->IsPositive());
81 EXPECT(!positive->IsNegative());
82 EXPECT(positive->Overlaps(0, 1));
83 EXPECT(positive->Overlaps(1, 100));
84 EXPECT(positive->Overlaps(-1, 0));
85 EXPECT(!positive->Overlaps(-2, -1));
86 Range* negative = new Range(RangeBoundary::NegativeInfinity(),
87 RangeBoundary::FromConstant(-1));
88 EXPECT(negative->IsNegative());
89 EXPECT(!negative->IsPositive());
90 EXPECT(!negative->Overlaps(0, 1));
91 EXPECT(!negative->Overlaps(1, 100));
92 EXPECT(negative->Overlaps(-1, 0));
93 EXPECT(negative->Overlaps(-2, -1));
94 Range* negpos = new Range(RangeBoundary::NegativeInfinity(),
95 RangeBoundary::FromConstant(0));
96 EXPECT(!negpos->IsNegative());
97 EXPECT(!negpos->IsPositive());
98
99 Range* a = new Range(RangeBoundary::NegativeInfinity(),
100 RangeBoundary::FromConstant(1));
101
102 Range* b = new Range(RangeBoundary::NegativeInfinity(),
103 RangeBoundary::FromConstant(31));
104
105 Range* c = new Range(RangeBoundary::NegativeInfinity(),
106 RangeBoundary::FromConstant(32));
107
108 EXPECT(a->OnlyLessThanOrEqualTo(31));
109 EXPECT(b->OnlyLessThanOrEqualTo(31));
110 EXPECT(!c->OnlyLessThanOrEqualTo(31));
111
112 Range* unsatisfiable = new Range(RangeBoundary::PositiveInfinity(),
113 RangeBoundary::NegativeInfinity());
114 EXPECT(unsatisfiable->IsUnsatisfiable());
115
116 Range* unsatisfiable_right = new Range(RangeBoundary::PositiveInfinity(),
117 RangeBoundary::FromConstant(0));
118 EXPECT(unsatisfiable_right->IsUnsatisfiable());
119
120 Range* unsatisfiable_left = new Range(RangeBoundary::FromConstant(0),
121 RangeBoundary::NegativeInfinity());
122 EXPECT(unsatisfiable_left->IsUnsatisfiable());
60 } 123 }
61 124
62 } // namespace dart 125 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698