Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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.
- * @author SShipp
- */
- @Test
- public void testHasReverseTwice() {
- //hasMirrorTwice(a1, a2) should return true...matches found at indices 2,3 and 7,8
- int[] a1 = {6, 1, 2, 1, 3, 1, 3, 2, 1, 5};
- int[] a2 = {1, 2};
- assertTrue(hasReverseTwice(a1,a2));
- //hasMirrorTwice(a3, a4) should return false
- int[] a3 = {5, 8, 4, 18, 5, 42, 4, 8, 5, 5};
- int[] a4 = {4, 8, 5};
- assertFalse(hasReverseTwice(a3,a4));
- //hasMirrorTwice(a5, a6) should return true, matches at indices 1,2 and 8,9
- int[] a5 = {6, 3, 42, 18, 12, 5, 3, 42, 3, 42};
- int[] a6 = {42, 3};
- assertTrue(hasReverseTwice(a5,a6));
- //hasMirrorTwice(a7, a8) should return false, matches at indices 1-6 but the match at 5-10 overlaps and is invalid
- int[] a7 = {6, 1, 2, 4, 2, 1, 2, 4, 2, 1, 5};
- int[] a8 = {1, 2, 4, 2, 1};
- assertFalse(hasReverseTwice(a7,a8));
- //hasMirrorTwice(a9, aa) should return true, matches at index 0 and index 1
- int[] a9 = {0, 0};
- int[] aa = {0};
- assertTrue(hasReverseTwice(a9,aa));
- //hasMirrorTwice(ab, ac) should return false, ac is longer than ab and thus can't be found in ab
- int[] ab = {8, 9, 2, 1};
- int[] ac = {5, 7, 1, 2, 9, 8};
- assertFalse(hasReverseTwice(ab,ac));
- //hasMirrorTwice with one empty array or two empty arrays should return false
- int[] ad = {};
- int[] ae = {1,2,3};
- assertFalse(hasReverseTwice(ad,ae));
- assertFalse(hasReverseTwice(ae,ad));
- //hasMirrorTwice with one or both null arrays should return false
- assertFalse(hasReverseTwice(ae, null));
- assertFalse(hasReverseTwice(null, ae));
- assertFalse(hasReverseTwice(null,null));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement