Download:
child 9:f3aad748ea73
parent 7:6a4073144143
8:dd50fe10144c
Anton Shestakov <engored@ya.ru>, Wed, 12 Dec 2012 19:41:08 +0900
More tests.

1 файлов изменено, 17 вставок(+), 12 удалений(-) [+]
test/underscore-methods.js file | annotate | diff | comparison | revisions
--- a/test/underscore-methods.js Wed Dec 12 19:09:41 2012 +0900
+++ b/test/underscore-methods.js Wed Dec 12 19:41:08 2012 +0900
@@ -14,17 +14,11 @@
}
});
-/*
- TODO: test
- sortBy
- groupBy
- sortedIndex
- shuffle
-*/
+// TODO: test sortedIndex
test('Underscore methods: basics', function() {
- equal(shard.first(), a, 'first() works');
- equal(shard.last(), c, 'last() works');
+ strictEqual(shard.first(), a, 'first() works');
+ strictEqual(shard.last(), c, 'last() works');
deepEqual(shard.initial(), [a, b], 'initial() works');
deepEqual(shard.rest(), [b, c], 'rest() works');
@@ -38,18 +32,29 @@
equal(shard.all(_.identity), true, 'all() works');
equal(shard.any(), true, 'any() works');
+
+ deepEqual(shard.sortBy(function(model) {
+ return -model.get('data').charCodeAt(0);
+ }), [c, b, a], 'sortBy() works');
+
+ deepEqual(shard.groupBy(function(model) {
+ return model.get('data').charCodeAt(0) % 2;
+ }), {0: [b], 1: [a, c]}, 'groupBy() works');
+
+ var sh = shard.shuffle().reduce(function(memo, model) { return memo += model.get('data'); }, '');
+ ok(sh.length == 3 && _(sh).contains('a') && _(sh).contains('b') && _(sh).contains('c'), 'shuffle() works');
});
test('Underscore methods: searching and filtering', function() {
- equal(shard.min(function(model) {
+ strictEqual(shard.min(function(model) {
return model.get('data').charCodeAt(0);
}), a, 'min() works');
- equal(shard.max(function(model) {
+ strictEqual(shard.max(function(model) {
return model.get('data').charCodeAt(0);
}), c, 'max() works');
- equal(shard.find(function(model) {
+ strictEqual(shard.find(function(model) {
return model.get('data') == 'b';
}), b, 'find() works');