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

Side by Side Diff: pkg/source_maps/test/utils_test.dart

Issue 12207008: Move source maps package to the dart repo, so it can be used by other internal (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: updates Created 7 years, 9 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
« no previous file with comments | « pkg/source_maps/test/span_test.dart ('k') | pkg/source_maps/test/vlq_test.dart » ('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 (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 /// Tests for the binary search utility algorithm.
6 library test.utils_test;
7
8 import 'package:unittest/unittest.dart';
9 import 'package:source_maps/src/utils.dart';
10
11 main() {
12 group('binary search', () {
13 test('empty', () {
14 expect(binarySearch([], (x) => true), -1);
15 });
16
17 test('single element', () {
18 expect(binarySearch([1], (x) => true), 0);
19 expect(binarySearch([1], (x) => false), 1);
20 });
21
22 test('no matches', () {
23 var list = [1, 2, 3, 4, 5, 6, 7];
24 expect(binarySearch(list, (x) => false), list.length);
25 });
26
27 test('all match', () {
28 var list = [1, 2, 3, 4, 5, 6, 7];
29 expect(binarySearch(list, (x) => true), 0);
30 });
31
32 test('compare with linear search', () {
33 for (int size = 0; size < 100; size++) {
34 var list = [];
35 for (int i = 0; i < size; i++) {
36 list.add(i);
37 }
38 for (int pos = 0; pos <= size; pos++) {
39 expect(binarySearch(list, (x) => x >= pos),
40 _linearSearch(list, (x) => x >= pos));
41 }
42 }
43 });
44 });
45 }
46
47 _linearSearch(list, predicate) {
48 if (list.length == 0) return -1;
49 for (int i = 0; i < list.length; i++) {
50 if (predicate(list[i])) return i;
51 }
52 return list.length;
53 }
54
OLDNEW
« no previous file with comments | « pkg/source_maps/test/span_test.dart ('k') | pkg/source_maps/test/vlq_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698