00001 00005 package edu.mit.csail.sdg.squander.util.test; 00006 00007 import static org.junit.Assert.assertEquals; 00008 import static org.junit.Assert.assertNotNull; 00009 import static org.junit.Assert.assertNull; 00010 import static org.junit.Assert.fail; 00011 00012 import java.util.Arrays; 00013 00014 public class TestUtils { 00015 00016 public static void assertArraysEqualNoOrdering(Object[] expected, Object[] actual) { 00017 if (expected == null) { 00018 assertNull(actual); 00019 return; 00020 } 00021 assertNotNull(actual); 00022 assertEquals("array lengths are different", expected.length, actual.length); 00023 for (Object obj : expected) { 00024 assertArrayContains(actual, obj); 00025 } 00026 } 00027 00028 public static void assertArraysEqualNoOrdering(int[] expected, int[] actual) { 00029 if (expected == null) { 00030 assertNull(actual); 00031 return; 00032 } 00033 assertNotNull(actual); 00034 assertEquals("array lengths are different", expected.length, actual.length); 00035 for (int obj : expected) { 00036 assertArrayContains(actual, obj); 00037 } 00038 } 00039 00040 public static void assertArrayContains(Object[] array, Object obj) { 00041 assertNotNull(array); 00042 for (Object arrObj : array) { 00043 if (arrObj == obj) 00044 return; 00045 } 00046 fail("Array does not contain given object: " + Arrays.toString(array) + ", obj = " + obj); 00047 } 00048 00049 public static void assertArrayContains(int[] array, int obj) { 00050 assertNotNull(array); 00051 for (int arrObj : array) { 00052 if (arrObj == obj) 00053 return; 00054 } 00055 fail("Array does not contain given int: " + Arrays.toString(array) + ", obj = " + obj); 00056 } 00057 00058 }