1 // Copyright (c) 2007 Hernadi Laszlo |
|
2 |
|
3 // This file is part of Mauve. |
|
4 |
|
5 // Mauve is free software; you can redistribute it and/or modify |
|
6 // it under the terms of the GNU General Public License as published by |
|
7 // the Free Software Foundation; either version 2, or (at your option) |
|
8 // any later version. |
|
9 |
|
10 // Mauve is distributed in the hope that it will be useful, |
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 // GNU General Public License for more details. |
|
14 |
|
15 // You should have received a copy of the GNU General Public License |
|
16 // along with Mauve; see the file COPYING. If not, write to |
|
17 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
18 // Boston, MA 02111-1307, USA. |
|
19 |
|
20 // Tags: JDK1.5 |
|
21 |
|
22 package gnu.testlet.java.util.Scanner; |
|
23 |
|
24 import java.io.FileNotFoundException; |
|
25 import java.io.FileOutputStream; |
|
26 import java.io.IOException; |
|
27 |
|
28 import java.util.Random; |
|
29 import java.util.Scanner; |
|
30 |
|
31 public class LotsOfPMShort extends Base |
|
32 { |
|
33 public LotsOfPMShort () |
|
34 { |
|
35 this.isEnabled = false; |
|
36 this.fileName = this.getClass ().getName () + ".txt"; |
|
37 } |
|
38 |
|
39 @Override protected void doTest () |
|
40 { |
|
41 this.myHarness.checkPoint ("Reading lots of shorts"); |
|
42 |
|
43 short[] numbers = new short[10000]; |
|
44 long runID = System.currentTimeMillis (); |
|
45 Random rand = new Random (runID); |
|
46 int i; |
|
47 short tmp; |
|
48 final short max = 20000, mean = max >> 1; |
|
49 StringBuilder tmpBuff = new StringBuilder (10000); |
|
50 FileOutputStream fos = null; |
|
51 |
|
52 myHarness.debug ("runID : " + runID); |
|
53 |
|
54 for (i = 0; i < numbers.length; i++) |
|
55 { |
|
56 tmp = (short) ((short) (rand.nextFloat () * max) - mean); |
|
57 numbers[i] = tmp; |
|
58 } |
|
59 tmpBuff.insert (0, "" + numbers[0]); |
|
60 |
|
61 for (i = 1; i < numbers.length; i++) |
|
62 { |
|
63 tmpBuff.append (" " + numbers[i]); |
|
64 } |
|
65 |
|
66 try |
|
67 { |
|
68 fos = new FileOutputStream (this.aktFile); |
|
69 fos.write (tmpBuff.toString ().getBytes ()); |
|
70 fos.flush (); |
|
71 fos.close (); |
|
72 |
|
73 Scanner s = new Scanner (aktFile); |
|
74 i = 0; |
|
75 while (s.hasNextShort ()) |
|
76 { |
|
77 tmp = s.nextShort (); |
|
78 this.myHarness.check (tmp, numbers[i], |
|
79 "nextShort() -> " + tmp + " != " + |
|
80 numbers[i]); |
|
81 i++; |
|
82 } |
|
83 this.myHarness.check (i, numbers.length, |
|
84 "Incomplete read... (" + i + " / " + |
|
85 numbers.length + ")"); |
|
86 s.close (); |
|
87 } |
|
88 catch (FileNotFoundException e) |
|
89 { |
|
90 this.myHarness.fail ("Could not create file"); |
|
91 } |
|
92 catch (IOException e) |
|
93 { |
|
94 this.myHarness.fail ("Could not write to File \"" + |
|
95 this.aktFile.getName () + "\""); |
|
96 } |
|
97 } |
|
98 |
|
99 } |
|