1 // Tags: JDK1.0 |
|
2 |
|
3 // Copyright (C) 1998, 2002 Cygnus Solutions |
|
4 |
|
5 // This file is part of Mauve. |
|
6 |
|
7 // Mauve is free software; you can redistribute it and/or modify |
|
8 // it under the terms of the GNU General Public License as published by |
|
9 // the Free Software Foundation; either version 2, or (at your option) |
|
10 // any later version. |
|
11 |
|
12 // Mauve is distributed in the hope that it will be useful, |
|
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 // GNU General Public License for more details. |
|
16 |
|
17 // You should have received a copy of the GNU General Public License |
|
18 // along with Mauve; see the file COPYING. If not, write to |
|
19 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 // Boston, MA 02111-1307, USA. */ |
|
21 |
|
22 package gnu.testlet.java.util.Random; |
|
23 import gnu.testlet.Testlet; |
|
24 import gnu.testlet.TestHarness; |
|
25 import java.util.Random; |
|
26 |
|
27 public class basic implements Testlet |
|
28 { |
|
29 public void test (TestHarness harness) |
|
30 { |
|
31 Random rand; |
|
32 |
|
33 rand = new Random(122760); |
|
34 harness.check (rand.nextInt(), -1524104671); |
|
35 |
|
36 harness.check (rand.nextLong(), 2785759620113032781L); |
|
37 |
|
38 harness.check (String.valueOf(rand.nextDouble()), "0.8173322904425151"); |
|
39 |
|
40 harness.check (String.valueOf(rand.nextFloat()), "0.8239248"); |
|
41 |
|
42 byte[] b = new byte[0]; |
|
43 rand.nextBytes(b); |
|
44 harness.check (rand.nextInt(), -899478426); |
|
45 |
|
46 rand = new Random(122760); |
|
47 rand.nextInt(); |
|
48 rand.nextLong(); |
|
49 rand.nextDouble(); |
|
50 rand.nextFloat(); |
|
51 b = new byte[3]; |
|
52 rand.nextBytes(b); |
|
53 harness.check (b[0], 102); |
|
54 harness.check (b[1], 12); |
|
55 harness.check (b[2], 99); |
|
56 harness.check (rand.nextInt(), -1550323395); |
|
57 |
|
58 rand = new Random(122760); |
|
59 rand.nextInt(); |
|
60 rand.nextLong(); |
|
61 rand.nextDouble(); |
|
62 rand.nextFloat(); |
|
63 b = new byte[4]; |
|
64 rand.nextBytes(b); |
|
65 harness.check (b[0], 102); |
|
66 harness.check (b[1], 12); |
|
67 harness.check (b[2], 99); |
|
68 harness.check (b[3], -54); |
|
69 harness.check (rand.nextInt(), -1550323395); |
|
70 |
|
71 rand = new Random(122760); |
|
72 rand.nextInt(); |
|
73 rand.nextLong(); |
|
74 rand.nextDouble(); |
|
75 rand.nextFloat(); |
|
76 b = new byte[5]; |
|
77 rand.nextBytes(b); |
|
78 harness.check (b[0], 102); |
|
79 harness.check (b[1], 12); |
|
80 harness.check (b[2], 99); |
|
81 harness.check (b[3], -54); |
|
82 harness.check (b[4], 61); |
|
83 harness.check (rand.nextInt(), -270809961); |
|
84 |
|
85 // Spot check for negative numbers. This is a regression test |
|
86 // an old Classpath bug. |
|
87 boolean ok = true; |
|
88 rand = new Random (0); |
|
89 for (int i=0; i < 1000000; ++i) |
|
90 { |
|
91 int x = rand.nextInt (1000); |
|
92 if (x < 0 || x >= 1000) |
|
93 ok = false; |
|
94 } |
|
95 harness.check (ok); |
|
96 } |
|
97 } |
|