Test of parseInt method, of class StringUtils.
()
| 44 | * Test of parseInt method, of class StringUtils. |
| 45 | */ |
| 46 | @Test |
| 47 | public void testParseInt() |
| 48 | { |
| 49 | System.out.println("parseInt"); |
| 50 | Random rand = RandomUtil.getRandom(); |
| 51 | for(int radix = Character.MIN_RADIX; radix <= Character.MAX_RADIX; radix++) |
| 52 | { |
| 53 | for(int trials = 0; trials < 1000; trials++) |
| 54 | { |
| 55 | String preFix = ""; |
| 56 | String postFix = ""; |
| 57 | |
| 58 | int prefixSize = rand.nextInt(3); |
| 59 | int postFixSize = rand.nextInt(3); |
| 60 | for(int i =0 ; i < prefixSize; i++) |
| 61 | preFix += Character.toString((char) rand.nextInt(128)); |
| 62 | for(int i =0 ; i < postFixSize; i++) |
| 63 | postFix += Character.toString((char) rand.nextInt(128)); |
| 64 | |
| 65 | |
| 66 | //first test a large int |
| 67 | int truth = rand.nextInt(); |
| 68 | String test = preFix + Integer.toString(truth, radix) + postFix; |
| 69 | |
| 70 | assertEquals(truth, StringUtils.parseInt(test, prefixSize, test.length()-postFixSize, radix)); |
| 71 | |
| 72 | //now a small one |
| 73 | |
| 74 | //first test a large int |
| 75 | truth = rand.nextInt(10)*(rand.nextInt(1)*2-1); |
| 76 | test = preFix + Integer.toString(truth, radix) + postFix; |
| 77 | |
| 78 | assertEquals(truth, StringUtils.parseInt(test, prefixSize, test.length()-postFixSize, radix)); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testParseDouble() |