1 27 package org.htmlparser.tests.lexerTests; 28 29 import org.htmlparser.lexer.PageIndex; 30 import org.htmlparser.tests.ParserTestCase; 31 32 public class PageIndexTests extends ParserTestCase 33 { 34 35 static 36 { 37 System.setProperty ("org.htmlparser.tests.lexerTests.PageIndexTests", "PageIndexTests"); 38 } 39 40 43 public PageIndexTests (String name) 44 { 45 super (name); 46 } 47 48 public void testAppend1 () 49 { 50 PageIndex index; 51 int pos; 52 int[] list; 53 54 index = new PageIndex (null); 55 56 for (int i = 0; i < 10000; i++) 57 { 58 pos = index.row (i); 59 assertTrue ("append not at end", pos == i); 60 assertTrue ("wrong position", pos == index.add (i)); 61 } 62 63 list = index.get (); 64 for (int i = 0; i < 10000; i++) 65 assertTrue ("wrong value", list[i] == i); 66 } 67 68 public void testAppend2 () 69 { 70 PageIndex index; 71 int pos; 72 int[] list; 73 74 index = new PageIndex (null); 75 76 for (int i = 0; i < 10000; i++) 77 { 78 pos = index.row (i + 42); 79 assertTrue ("append not at end", pos == i); 80 assertTrue ("wrong position", pos == index.add (i + 42)); 81 } 82 83 list = index.get (); 84 for (int i = 0; i < 10000; i++) 85 assertTrue ("wrong value", list[i] == i + 42); 86 } 87 88 public void testAppend3 () 89 { 90 PageIndex index; 91 int pos; 92 int[] list; 93 94 index = new PageIndex (null); 95 96 for (int i = 0; i < 10000; i++) 97 { 98 pos = index.row (i * 42); 99 assertTrue ("append not at end", pos == i); 100 assertTrue ("wrong position", pos == index.add (i * 42)); 101 } 102 103 list = index.get (); 104 for (int i = 0; i < 10000; i++) 105 assertTrue ("wrong value", list[i] == i * 42); 106 } 107 108 public void testInsert () 109 { 110 PageIndex index; 111 double d; 112 int n; 113 int pos; 114 int[] list; 115 116 index = new PageIndex (null); 117 118 for (int i = 0; i < 10000; i++) 119 { 120 d = Math.random (); 121 d -= 0.5; 122 n = (int)(d * 100838); 123 pos = index.row (n); 124 125 if (0 <= pos - 1) 127 assertTrue ("search error less " + pos + " " + index.elementAt (pos - 1) + " " + n, index.elementAt (pos - 1) <= n); 128 if (pos + 1 < index.size ()) 129 assertTrue ("search error greater " + pos + " " + index.elementAt (pos + 1) + " " + n, index.elementAt (pos + 1) > n); 130 } 131 132 list = index.get (); 133 n = Integer.MIN_VALUE; 134 for (int i = 0; i < list.length; i++) 135 { 136 assertTrue ("wrong order", list[i] > n); 137 n = list[i]; 138 } 139 } 140 } 141 | Popular Tags |