Advertisement
scottashipp

Unit tests for has reverse twice

Feb 11th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.76 KB | None | 0 0
  1. /**
  2.  * Unit tests for the has reverse twice problem: Given two arrays, a1 and a2, determine if the reverse of a2 is found inside a1 twice.
  3.  * @author SShipp  
  4.  */
  5. @Test
  6. public void testHasReverseTwice() {
  7.         //hasMirrorTwice(a1, a2) should return true...matches found at indices 2,3 and 7,8
  8.         int[] a1 = {6, 1, 2, 1, 3, 1, 3, 2, 1, 5};
  9.         int[] a2 = {1, 2};  
  10.         assertTrue(hasReverseTwice(a1,a2));
  11.        
  12.         //hasMirrorTwice(a3, a4) should return false
  13.         int[] a3 = {5, 8, 4, 18, 5, 42, 4, 8, 5, 5};
  14.         int[] a4 = {4, 8, 5};  
  15.         assertFalse(hasReverseTwice(a3,a4));
  16.        
  17.         //hasMirrorTwice(a5, a6) should return true, matches at indices 1,2 and 8,9
  18.         int[] a5 = {6, 3, 42, 18, 12, 5, 3, 42, 3, 42};
  19.         int[] a6 = {42, 3};    
  20.         assertTrue(hasReverseTwice(a5,a6));
  21.        
  22.         //hasMirrorTwice(a7, a8) should return false, matches at indices 1-6 but the match at 5-10 overlaps and is invalid
  23.         int[] a7 = {6, 1, 2, 4, 2, 1, 2, 4, 2, 1, 5};
  24.         int[] a8 = {1, 2, 4, 2, 1};    
  25.         assertFalse(hasReverseTwice(a7,a8));
  26.        
  27.        
  28.         //hasMirrorTwice(a9, aa) should return true, matches at index 0 and index 1
  29.         int[] a9 = {0, 0};
  30.         int[] aa = {0};    
  31.         assertTrue(hasReverseTwice(a9,aa));
  32.        
  33.         //hasMirrorTwice(ab, ac) should return false, ac is longer than ab and thus can't be found in ab
  34.         int[] ab = {8, 9, 2, 1};
  35.         int[] ac = {5, 7, 1, 2, 9, 8};  
  36.         assertFalse(hasReverseTwice(ab,ac));
  37.        
  38.         //hasMirrorTwice with one empty array or two empty arrays should return false
  39.         int[] ad = {};
  40.         int[] ae = {1,2,3};
  41.         assertFalse(hasReverseTwice(ad,ae));
  42.         assertFalse(hasReverseTwice(ae,ad));
  43.        
  44.         //hasMirrorTwice with one or both null arrays should return false
  45.         assertFalse(hasReverseTwice(ae, null));
  46.         assertFalse(hasReverseTwice(null, ae));
  47.         assertFalse(hasReverseTwice(null,null));
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement