KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > db4ounit > ArrayAssert


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package db4ounit;
22
23
24 public class ArrayAssert {
25     
26     public static void contains(long[] array, long expected) {
27         if (-1 != indexOf(array, expected)) {
28             return;
29         }
30         Assert.fail("Expecting '" + expected + "'.");
31     }
32     
33     public static void areEqual(Object JavaDoc[] expected, Object JavaDoc[] actual) {
34         if (expected == actual) return;
35         if (expected == null || actual == null) Assert.areSame(expected, actual);
36         Assert.areEqual(expected.length, actual.length);
37         for (int i = 0; i < expected.length; i++) {
38             Assert.areEqual(expected[i], actual[i]);
39         }
40     }
41
42     public static void areEqual(byte[] expected, byte[] actual) {
43         if (expected == actual) return;
44         if (expected == null || actual == null) Assert.areSame(expected, actual);
45         Assert.areEqual(expected.length, actual.length);
46         for (int i = 0; i < expected.length; i++) {
47             Assert.areEqual(expected[i], actual[i]);
48         }
49     }
50
51     public static void areNotEqual(byte[] expected, byte[] actual) {
52         Assert.areNotSame(expected, actual);
53         for (int i = 0; i < expected.length; i++) {
54             if (expected[i] != actual[i]) return;
55         }
56         Assert.isTrue(false);
57     }
58
59     public static void areEqual(int[] expected, int[] actual) {
60         if (expected == actual) return;
61         if (expected == null || actual == null) Assert.areSame(expected, actual);
62         Assert.areEqual(expected.length, actual.length);
63         for (int i = 0; i < expected.length; i++) {
64             Assert.areEqual(expected[i], actual[i]);
65         }
66     }
67
68     public static void areEqual(double[] expected, double[] actual) {
69         if (expected == actual) return;
70         if (expected == null || actual == null) Assert.areSame(expected, actual);
71         Assert.areEqual(expected.length, actual.length);
72         for (int i = 0; i < expected.length; i++) {
73             Assert.areEqual(expected[i], actual[i]);
74         }
75     }
76     
77     private static int indexOf(long[] array, long expected) {
78         for (int i = 0; i < array.length; ++i) {
79             if (expected == array[i]) {
80                 return i;
81             }
82         }
83         return -1;
84     }
85 }
86
Popular Tags