Home | History | Annotate | Download | only in base
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('base.iteration_helpers');
      8 
      9 base.unittest.testSuite('base.iteration_helpers', function() {
     10   var comparePossiblyUndefinedValues = base.comparePossiblyUndefinedValues;
     11   var compareArrays = base.compareArrays;
     12 
     13   test('comparePossiblyUndefinedValues', function() {
     14     function cmp(x, y) {
     15       assertNotUndefined(x);
     16       assertNotUndefined(y);
     17       return x - y;
     18     }
     19 
     20     assertTrue(comparePossiblyUndefinedValues(0, 1, cmp) < 0);
     21     assertTrue(comparePossiblyUndefinedValues(1, 0, cmp) > 0);
     22     assertTrue(comparePossiblyUndefinedValues(1, 1, cmp) == 0);
     23 
     24     assertTrue(comparePossiblyUndefinedValues(0, undefined, cmp) < 0);
     25     assertTrue(comparePossiblyUndefinedValues(undefined, 0, cmp) > 0);
     26     assertTrue(comparePossiblyUndefinedValues(undefined, undefined, cmp) == 0);
     27   });
     28 
     29   test('compareArrays', function() {
     30     function cmp(x, y) {
     31       assertNotUndefined(x);
     32       assertNotUndefined(y);
     33       return x - y;
     34     }
     35 
     36     assertTrue(compareArrays([1], [2], cmp) < 0);
     37     assertTrue(compareArrays([2], [1], cmp) > 0);
     38 
     39     assertTrue(compareArrays([1], [1, 2], cmp) < 0);
     40     assertTrue(compareArrays([1, 2], [1], cmp) > 0);
     41 
     42     assertTrue(compareArrays([], [1], cmp) < 0);
     43     assertTrue(compareArrays([1], [], cmp) > 0);
     44 
     45     assertTrue(compareArrays([2], [1], cmp) > 0);
     46 
     47     assertTrue(compareArrays([], [], cmp) == 0);
     48     assertTrue(compareArrays([1], [1], cmp) == 0);
     49   });
     50 });
     51