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

Side by Side Diff: test/cctest/test-utils.cc

Issue 3181036: Created collector class and used it to collect identifiers during scanning. (Closed)
Patch Set: Created 10 years, 3 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
« src/utils.h ('K') | « src/utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 } 124 }
125 125
126 // Different lengths 126 // Different lengths
127 for (int i = 0; i < 32; i++) { 127 for (int i = 0; i < 32; i++) {
128 TestMemCopy(buffer1, buffer2, 3, 7, i); 128 TestMemCopy(buffer1, buffer2, 3, 7, i);
129 } 129 }
130 130
131 buffer2.Dispose(); 131 buffer2.Dispose();
132 buffer1.Dispose(); 132 buffer1.Dispose();
133 } 133 }
134
135
136 TEST(Collector) {
137 Collector<int> collector(8);
138 const int kLoops = 5;
139 const int kSequentialSize = 1000;
140 const int kBlockSize = 7;
141 for (int loop = 0; loop < kLoops; loop++) {
142 Vector<int> block = collector.AddBlock(7, 0xbadcafe);
143 for (int i = 0; i < kSequentialSize; i++) {
144 collector.Add(i);
145 }
146 for (int i = 0; i < kBlockSize - 1; i++) {
147 block[i] = i * 7;
148 }
149 }
150 Vector<int> result = collector.ToVector();
151 CHECK_EQ(kLoops * (kBlockSize + kSequentialSize), result.length());
152 for (int i = 0; i < kLoops; i++) {
153 int offset = i * (kSequentialSize + kBlockSize);
154 for (int j = 0; j < kBlockSize - 1; j++) {
155 CHECK_EQ(j * 7, result[offset + j]);
156 }
157 CHECK_EQ(0xbadcafe, result[offset + kBlockSize - 1]);
158 for (int j = 0; j < kSequentialSize; j++) {
159 CHECK_EQ(j, result[offset + kBlockSize + j]);
160 }
161 }
162 result.Dispose();
163 }
164
165
166 TEST(SequenceCollector) {
167 SequenceCollector<int> collector(8);
168 const int kLoops = 5000;
169 const int kMaxSequenceSize = 13;
170 int total_length = 0;
171 for (int loop = 0; loop < kLoops; loop++) {
172 int seq_length = loop % kMaxSequenceSize;
173 collector.StartSequence();
174 for (int j = 0; j < seq_length; j++) {
175 collector.Add(j);
176 }
177 Vector<int> sequence = collector.EndSequence();
178 for (int j = 0; j < seq_length; j++) {
179 CHECK_EQ(j, sequence[j]);
180 }
181 total_length += seq_length;
182 }
183 Vector<int> result = collector.ToVector();
184 CHECK_EQ(total_length, result.length());
185 int offset = 0;
186 for (int loop = 0; loop < kLoops; loop++) {
187 int seq_length = loop % kMaxSequenceSize;
188 for (int j = 0; j < seq_length; j++) {
189 CHECK_EQ(j, result[offset]);
190 offset++;
191 }
192 }
193 result.Dispose();
194 }
OLDNEW
« src/utils.h ('K') | « src/utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698