Upstream version 11.39.266.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / third_party / tvcm / src / tvcm / iteration_helpers_test.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7 <link rel="import" href="/tvcm/iteration_helpers.html">
8 <script>
9 'use strict';
10
11 tvcm.unittest.testSuite(function() {
12   var comparePossiblyUndefinedValues = tvcm.comparePossiblyUndefinedValues;
13   var compareArrays = tvcm.compareArrays;
14
15   test('comparePossiblyUndefinedValues', function() {
16     function cmp(x, y) {
17       assertNotUndefined(x);
18       assertNotUndefined(y);
19       return x - y;
20     }
21
22     assertTrue(comparePossiblyUndefinedValues(0, 1, cmp) < 0);
23     assertTrue(comparePossiblyUndefinedValues(1, 0, cmp) > 0);
24     assertTrue(comparePossiblyUndefinedValues(1, 1, cmp) == 0);
25
26     assertTrue(comparePossiblyUndefinedValues(0, undefined, cmp) < 0);
27     assertTrue(comparePossiblyUndefinedValues(undefined, 0, cmp) > 0);
28     assertTrue(comparePossiblyUndefinedValues(undefined, undefined, cmp) == 0);
29   });
30
31   test('compareArrays', function() {
32     function cmp(x, y) {
33       assertNotUndefined(x);
34       assertNotUndefined(y);
35       return x - y;
36     }
37
38     assertTrue(compareArrays([1], [2], cmp) < 0);
39     assertTrue(compareArrays([2], [1], cmp) > 0);
40
41     assertTrue(compareArrays([1], [1, 2], cmp) < 0);
42     assertTrue(compareArrays([1, 2], [1], cmp) > 0);
43
44     assertTrue(compareArrays([], [1], cmp) < 0);
45     assertTrue(compareArrays([1], [], cmp) > 0);
46
47     assertTrue(compareArrays([2], [1], cmp) > 0);
48
49     assertTrue(compareArrays([], [], cmp) == 0);
50     assertTrue(compareArrays([1], [1], cmp) == 0);
51   });
52 });
53 </script>