Path: blob/master/test/jdk/java/io/Serializable/oldTests/ArrayOpsTest.java
41153 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223public class ArrayOpsTest {24public static boolean verify(int a[], int b[]) {25boolean result = true;2627if (a.length != b.length) {28System.err.println("\nInt array lengths differ: " +29a.length + " != " + b.length);30result = false;31}3233for (int i = 0; i < a.length; i++) {34if (a[i] != b[i]) {35System.err.println("\nInt array contents differ " +36"at index " + i + ": " + a[i] + " != " + b[i]);37result = false;38}39}40return result;41}4243public static boolean verify(byte a[], byte b[]) {44boolean result = true;4546if (a.length != b.length) {47System.err.println("\nByte array lengths differ: " +48a.length + " != " + b.length);49result = false;50}5152for (int i = 0; i < a.length; i++) {53if (a[i] != b[i]) {54System.err.println("\nByte array contents differ at index " +55i + ": " + a[i] + " != " + b[i]);56result = false;57}58}59return result;60}6162public static boolean verify(char a[], char b[]) {63boolean result = true;6465if (a.length != b.length) {66System.err.println("\nChar array lengths differ: " +67a.length + " != " + b.length);68result = false;69}7071for (int i = 0; i < a.length; i++) {72if (a[i] != b[i]) {73System.err.println("\nChar array contents differ at index " +74i + ": " + a[i] + " != " + b[i]);75result = false;76}77}78return result;79}8081public static boolean verify(short a[], short b[]) {82boolean result = true;8384if (a.length != b.length) {85System.err.println("\nShort array lengths differ: " +86a.length + " != " + b.length);87result = false;88}8990for (int i = 0; i < a.length; i++) {91if (a[i] != b[i]) {92System.err.println("\nShort array contents differ at index " +93i + ": " + a[i] + " != " + b[i]);94result = false;95}96}97return result;98}99100public static boolean verify(boolean a[], boolean b[]) {101boolean result = true;102103if (a.length != b.length) {104System.err.println("\nBoolean array lengths differ: " +105a.length + " != " + b.length);106result = false;107}108109for (int i = 0; i < a.length; i++) {110if (a[i] != b[i]) {111System.err.println("\nBoolean array contents differ at index " +112i + ": " + a[i] + " != " + b[i]);113result = false;114}115}116return result;117}118119public static boolean verify(float a[], float b[]) {120boolean result = true;121122if (a.length != b.length) {123System.err.println("\nFloat array lengths differ: " +124a.length + " != " + b.length);125result = false;126}127128for (int i = 0; i < a.length; i++) {129if (a[i] != b[i]) {130System.err.println("\nFloat array contents differ at index " +131i + ": " + a[i] + " != " + b[i]);132result = false;133}134}135return result;136}137138public static boolean verify(double a[], double b[]) {139boolean result = true;140141if (a.length != b.length) {142System.err.println("\nDouble array lengths differ: " +143a.length + " != " + b.length);144result = false;145}146147for (int i = 0; i < a.length; i++) {148if (a[i] != b[i]) {149System.err.println("\nDouble array contents differ at index " +150i + ": " + a[i] + " != " + b[i]);151result = false;152}153}154return result;155}156157public static boolean verify(long a[], long b[]) {158boolean result = true;159160if (a.length != b.length) {161System.err.println("\nLong array lengths differ: " +162a.length + " != " + b.length);163result = false;164}165166for (int i = 0; i < a.length; i++) {167if (a[i] != b[i]) {168System.err.println("\nLong array contents differ at index " +169i + ": " + a[i] + " != " + b[i]);170result = false;171}172}173return result;174}175176public static boolean verify(String a[], String b[]) {177boolean result = true;178179if (a.length != b.length) {180System.err.println("\nString array lengths differ: " +181a.length + " != " + b.length);182result = false;183}184185for (int i = 0; i < a.length; i++) {186if (!a[i].equals(b[i])) {187System.err.println("\nString array contents differ at index " +188i + ": " + a[i] + " != " + b[i]);189result = false;190}191}192return result;193}194195public static boolean verify(PrimitivesTest a[], PrimitivesTest b[]) {196boolean result = true;197198if (a.length != b.length) {199System.err.println("\nPrimitivesTest array lengths differ: " +200a.length + " != " + b.length);201result = false;202}203204for (int i = 0; i < a.length; i++) {205if (a[i] == null && b[i] == null) {206continue;207}208209if (!a[i].equals(b[i])) {210System.err.println("\nPrimitivesTest array contents differ at " +211"index " + i + ": " + a[i] + " != " + b[i]);212result = false;213}214}215return result;216}217}218219220