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

Side by Side Diff: pkg/unittest/test/matchers_test.dart

Issue 15017013: Added a new matcher for pairwise comparison of iterables with a custom comparator. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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 library unittestTests; 5 library unittestTests;
6 import 'package:unittest/unittest.dart'; 6 import 'package:unittest/unittest.dart';
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 part 'test_utils.dart'; 9 part 'test_utils.dart';
10 10
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 shouldFail(d, unorderedEquals([1]), 516 shouldFail(d, unorderedEquals([1]),
517 "Expected: equals <[1]> unordered " 517 "Expected: equals <[1]> unordered "
518 "but: has too many elements (2 > 1)."); 518 "but: has too many elements (2 > 1).");
519 shouldFail(d, unorderedEquals([3, 2, 1]), 519 shouldFail(d, unorderedEquals([3, 2, 1]),
520 "Expected: equals <[3, 2, 1]> unordered " 520 "Expected: equals <[3, 2, 1]> unordered "
521 "but: has too few elements (2 < 3)."); 521 "but: has too few elements (2 < 3).");
522 shouldFail(d, unorderedEquals([3, 1]), 522 shouldFail(d, unorderedEquals([3, 1]),
523 "Expected: equals <[3, 1]> unordered " 523 "Expected: equals <[3, 1]> unordered "
524 "but: has no match for element <3> at position 0."); 524 "but: has no match for element <3> at position 0.");
525 }); 525 });
526
527 test('pairwise compare', () {
528 var c = [1, 2];
529 var d = [1, 2, 3];
530 var e = [1, 4, 9];
531 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e,
532 "less than or equal"),
533 "Expected: pairwise less than or equal <[1, 4, 9]> but: "
534 "not an Iterable.");
535 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"),
536 "Expected: pairwise less than or equal <[1, 4, 9]> but: "
537 "length was 2 instead of 3.");
538 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"));
539 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"),
540 "Expected: pairwise less than <[1, 4, 9]> but: "
541 "<1> not less than <1> at position 0.");
542 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of"));
543 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"),
544 "Expected: pairwise double <[1, 4, 9]> but: "
545 "<1> not double <1> at position 0.");
546 });
526 }); 547 });
527 548
528 group('Map Matchers', () { 549 group('Map Matchers', () {
529 550
530 test('isEmpty', () { 551 test('isEmpty', () {
531 var a = new Map(); 552 var a = new Map();
532 shouldPass({}, isEmpty); 553 shouldPass({}, isEmpty);
533 shouldPass(a, isEmpty); 554 shouldPass(a, isEmpty);
534 a['foo'] = 'bar'; 555 a['foo'] = 'bar';
535 shouldFail(a, isEmpty, "Expected: empty but: was <{foo: bar}>."); 556 shouldFail(a, isEmpty, "Expected: empty but: was <{foo: bar}>.");
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 w.price = 10; 730 w.price = 10;
710 shouldPass(w, new HasPrice(10)); 731 shouldPass(w, new HasPrice(10));
711 shouldPass(w, new HasPrice(greaterThan(0))); 732 shouldPass(w, new HasPrice(greaterThan(0)));
712 shouldFail(w, new HasPrice(greaterThan(10)), 733 shouldFail(w, new HasPrice(greaterThan(10)),
713 'Expected: Widget with a price that is a value greater than <10> ' 734 'Expected: Widget with a price that is a value greater than <10> '
714 'but: price was <10>.'); 735 'but: price was <10>.');
715 }); 736 });
716 }); 737 });
717 } 738 }
718 739
OLDNEW
« pkg/unittest/lib/src/iterable_matchers.dart ('K') | « pkg/unittest/lib/src/iterable_matchers.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698