1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2<html> 3 <head> 4 <title>Tests for the Helper functions</title> 5<!-- 6 $Id: ArrayTests.html 130 2006-11-30 20:44:53Z wingedfox $ 7 $HeadURL: https://svn.debugger.ru/repos/jslibs/BrowserExtensions/tags/BrowserExtensions.003/tests/ArrayTests.html $ 8 9 Automated tests for the Array extensions 10 @author Ilya Lebedev <ilya@lebedev.net> 11--> 12 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 13 <title>BrowserExtensions/Array extensions tests</title> 14 <link rel="stylesheet" type="text/css" href="../css/jsUnitStyle.css"> 15 <script language="JavaScript" type="text/javascript" src="jsUnitCore.js"></script> 16 <script language="JavaScript" type="text/javascript" src="../helpers.js"></script> 17 <script language="JavaScript" type="text/javascript" src="../arrayextensions.js"></script> 18 <script language="JavaScript" type="text/javascript"> 19 function testIndexOf() { 20 var arr = [1,2,3,4,4,3,2,1] 21 assertEquals("Look for non-existent value (-1)", -1, arr.indexOf(-1)); 22 assertEquals("Look for non-existent value (null)", -1, arr.indexOf(null)); 23 assertEquals("Look for the existent value return its index", 2, arr.indexOf(3)); 24 assertEquals("Look for the existent value from a point return its index", 2, arr.indexOf(3,1)); 25 assertEquals("Look for the existent value from a point return its index", 2, arr.indexOf(3,2)); 26 assertEquals("Look for the existent value from a point return its index", 5, arr.indexOf(3,4)); 27 } 28 function testLastIndexOf() { 29 var arr = [1,2,3,4,4,3,2,1] 30 assertEquals("Look for non-existent value (-1)", -1, arr.lastIndexOf(-1)); 31 assertEquals("Look for non-existent value (null)", -1, arr.lastIndexOf(null)); 32 assertEquals("Look for the existent value return its index", 6, arr.lastIndexOf(2)); 33 assertEquals("Look for the existent value from a point return its index", 6, arr.lastIndexOf(2,7)); 34 assertEquals("Look for the existent value from a point return its index", 6, arr.lastIndexOf(2,6)); 35 assertEquals("Look for the existent value from a point return its index", 1, arr.lastIndexOf(2,5)); 36 } 37 function testMap() { 38 var arr = [1,2,3,4]; 39 var m = function(v) { 40 return v+1; 41 } 42 try { 43 assertObjectEquals("Non-function return array itself (null)", arr, arr.map(null)); 44 } catch (e) { info ('Some error thrown: ' + e.message) } 45 try { 46 assertObjectEquals("Non-function return array itself (234)", arr, arr.map(234)); 47 } catch (e) { info ('Some error thrown: ' + e.message) } 48 try { 49 assertObjectEquals("Valid callback does modify the array", [2,3,4,5], arr.lastIndexOf(m)); 50 } catch (e) { info ('Some error thrown: ' + e.message) } 51 } 52 function testUnique() { 53 var arr = [1,2,3,4,4,3,2,1] 54 assertObjectEquals("Empty array is unique", [], [].unique()); 55 assertObjectEquals("Duplicate values will be removed)", [1,2,3,4], arr.unique()); 56 } 57 function testRange() { 58 assertNull("Null, when end is incorrect", Array.range('null')); 59 assertObjectEquals("Array with 0 when only 0 supplied ", [0], Array.range(0)); 60 assertObjectEquals("Array with 1..5 values when 1, 5 supplied ", [1,2,3,4,5], Array.range(1,5)); 61 assertObjectEquals("Array with -5..0 when only -5 supplied ", [-5,-4,-3,-2,-1,0], Array.range(-5)); 62 assertObjectEquals("Array with -2..2 when -2, 2 supplied ", [-2,-1,0,1,2], Array.range(-2,2)); 63 assertObjectEquals("Array with -2..2 when 2, -2 supplied ", [-2,-1,0,1,2], Array.range(2,-2)); 64 assertObjectEquals("Array with -1,-0.5,0 when -1, 0 , 0.5 supplied ", [-1,-0.5,0], Array.range(-1,0,0.5)); 65 assertObjectEquals("Array with 0,-0.5,-1 when -1, 0 , -0.5 supplied ", [0,-0.5,-1], Array.range(-1,0,-0.5)); 66 } 67 function testFlatten() { 68 assertObjectEquals("Empty array, when empty array is supplied", [], [].flatten()); 69 assertObjectEquals("Empty array, when array of empty arrays is supplied", [], [[],[],[]].flatten()); 70 assertObjectEquals("Empty array, when cols are beyound the array borders", [], [[1,2],[1,2],[1]].flatten(10)); 71 assertObjectEquals("Array with values, when correct array is supplied", [1,2,3,4,5], [[1,2],[3,4],[5]].flatten()); 72 assertObjectEquals("Array with cpecific column, when values is supplied", [1,3,5], [[1,2],[3,4],[5]].flatten(0)); 73 assertObjectEquals("Array with cpecific column, when values is supplied", [1,2,3,4,5], [[1,2,6],[3,4,7],[5]].flatten([0,1])); 74 75 } 76 </script> 77 </head> 78 <body> 79 <h1>Tests for the Array extensions</h1> 80 <p>This page contains tests for the Helpers functions. To see them, take a look at the source.</p> 81 </body> 82</html> 83