• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2008 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6//     * Redistributions of source code must retain the above copyright
7//       notice, this list of conditions and the following disclaimer.
8//     * Redistributions in binary form must reproduce the above
9//       copyright notice, this list of conditions and the following
10//       disclaimer in the documentation and/or other materials provided
11//       with the distribution.
12//     * Neither the name of Google Inc. nor the names of its
13//       contributors may be used to endorse or promote products derived
14//       from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28// Test Math.min().
29
30assertEquals(Number.POSITIVE_INFINITY, Math.min());
31assertEquals(1, Math.min(1));
32assertEquals(1, Math.min(1, 2));
33assertEquals(1, Math.min(2, 1));
34assertEquals(1, Math.min(1, 2, 3));
35assertEquals(1, Math.min(3, 2, 1));
36assertEquals(1, Math.min(2, 3, 1));
37
38var o = {};
39o.valueOf = function() { return 1; };
40assertEquals(1, Math.min(2, 3, '1'));
41assertEquals(1, Math.min(3, o, 2));
42assertEquals(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / Math.min(-0, +0));
43assertEquals(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / Math.min(+0, -0));
44assertEquals(Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY / Math.min(+0, -0, 1));
45assertEquals(-1, Math.min(+0, -0, -1));
46assertEquals(-1, Math.min(-1, +0, -0));
47assertEquals(-1, Math.min(+0, -1, -0));
48assertEquals(-1, Math.min(-0, -1, +0));
49
50
51
52// Test Math.max().
53
54assertEquals(Number.NEGATIVE_INFINITY, Math.max());
55assertEquals(1, Math.max(1));
56assertEquals(2, Math.max(1, 2));
57assertEquals(2, Math.max(2, 1));
58assertEquals(3, Math.max(1, 2, 3));
59assertEquals(3, Math.max(3, 2, 1));
60assertEquals(3, Math.max(2, 3, 1));
61
62var o = {};
63o.valueOf = function() { return 3; };
64assertEquals(3, Math.max(2, '3', 1));
65assertEquals(3, Math.max(1, o, 2));
66assertEquals(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Math.max(-0, +0));
67assertEquals(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Math.max(+0, -0));
68assertEquals(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY / Math.max(+0, -0, -1));
69assertEquals(1, Math.max(+0, -0, +1));
70assertEquals(1, Math.max(+1, +0, -0));
71assertEquals(1, Math.max(+0, +1, -0));
72assertEquals(1, Math.max(-0, +1, +0));