|
| 1 | +package com.ctci.arraysandstrings; |
| 2 | + |
| 3 | + |
| 4 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +class TestCheckPermutation { |
| 10 | + |
| 11 | + @Test |
| 12 | + void testPermutationStringWithEmpty() { |
| 13 | + String a1 = ""; |
| 14 | + String a2 = ""; |
| 15 | + |
| 16 | + String b1 = "1234567890 qwertyuiopasdfghjklzxcvbnm !@#$%^&*()-="; |
| 17 | + String b2 = ""; |
| 18 | + |
| 19 | + String c1 = ""; |
| 20 | + String c2 = "1234567890 qwertyuiopasdfghjklzxcvbnm !@#$%^&*()-="; |
| 21 | + |
| 22 | + |
| 23 | + boolean resultA = CheckPermutation.isOnePermutationOfOther(a1, a2); |
| 24 | + boolean resultB = CheckPermutation.isOnePermutationOfOther(b1, b2); |
| 25 | + boolean resultC = CheckPermutation.isOnePermutationOfOther(c1, c2); |
| 26 | + |
| 27 | + assertTrue(resultA); |
| 28 | + assertFalse(resultB); |
| 29 | + assertFalse(resultC); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + void testPermutationStringAllCharacter() { |
| 34 | + String a1 = "1234567890 qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM !@#$%^&*()-="; |
| 35 | + String a2 = "!@#$%^&*()-= 1234567890 qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM"; |
| 36 | + |
| 37 | + String b1 = "~!@#$%^&*([{<>}])+-=:;'\\\",./? "; |
| 38 | + String b2 = " ?/.,\"\\';:=-+)}]><[{(*&^%$#@!~"; |
| 39 | + |
| 40 | + String c1 = "Â Ă Ơ Ô Ư Ê â ă ơ ô ư ê"; |
| 41 | + String c2 = "ê ư ô ơ ă â Ê Ư Ô Ơ Ă Â"; |
| 42 | + |
| 43 | + String d1 = "ÂÂ ĂĂ ƠƠ ÔÔ ƯƯ ÊÊ ââ ăă ơơ ôô ưư êê"; |
| 44 | + String d2 = "ê ư ô ơ ă â Ê Ư Ô Ơ Ă Â"; |
| 45 | + |
| 46 | + |
| 47 | + boolean resultA = CheckPermutation.isOnePermutationOfOther(a1, a2); |
| 48 | + boolean resultB = CheckPermutation.isOnePermutationOfOther(b1, b2); |
| 49 | + boolean resultC = CheckPermutation.isOnePermutationOfOther(c1, c2); |
| 50 | + boolean resultD = CheckPermutation.isOnePermutationOfOther(d1, d2); |
| 51 | + |
| 52 | + assertTrue(resultA); |
| 53 | + assertTrue(resultB); |
| 54 | + assertTrue(resultC); |
| 55 | + assertFalse(resultD); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void testPermutationWithAsciiAndStringEmpty() { |
| 60 | + String a1 = ""; |
| 61 | + String a2 = ""; |
| 62 | + |
| 63 | + String b1 = "1234567890 qwertyuiopasdfghjklzxcvbnm !@#$%^&*()-="; |
| 64 | + String b2 = ""; |
| 65 | + |
| 66 | + String c1 = ""; |
| 67 | + String c2 = "1234567890 qwertyuiopasdfghjklzxcvbnm !@#$%^&*()-="; |
| 68 | + |
| 69 | + |
| 70 | + boolean resultA = CheckPermutation.isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(a1, a2); |
| 71 | + boolean resultB = CheckPermutation.isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(b1, b2); |
| 72 | + boolean resultC = CheckPermutation.isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(c1, c2); |
| 73 | + |
| 74 | + assertTrue(resultA); |
| 75 | + assertFalse(resultB); |
| 76 | + assertFalse(resultC); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + void testPermutationWithAsciiAndStringAllCharacter() { |
| 81 | + String a1 = "1234567890 qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM !@#$%^&*()-="; |
| 82 | + String a2 = "!@#$%^&*()-= 1234567890 qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM"; |
| 83 | + |
| 84 | + String b1 = "~!@#$%^&*([{<>}])+-=:;'\\\",./? "; |
| 85 | + String b2 = " ?/.,\"\\';:=-+)}]><[{(*&^%$#@!~"; |
| 86 | + |
| 87 | + String c1 = "Â Ă Ơ Ô Ư Ê â ă ơ ô ư ê"; |
| 88 | + String c2 = "ê ư ô ơ ă â Ê Ư Ô Ơ Ă Â"; |
| 89 | + |
| 90 | + String d1 = "Â Ă Ơ Ô Ư Ê â ă ơ ô ư ê"; |
| 91 | + String e2 = "ê ư ô ơ ă â Ê Ư Ô Ơ Ă Â"; |
| 92 | + |
| 93 | + |
| 94 | + boolean resultA = CheckPermutation.isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(a1, a2); |
| 95 | + boolean resultB = CheckPermutation.isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(b1, b2); |
| 96 | + boolean resultC = CheckPermutation.isOnePermutationOfOtherGivenThatStringsContainOnlyAscii(c1, c2); |
| 97 | + |
| 98 | + assertTrue(resultA); |
| 99 | + assertTrue(resultB); |
| 100 | + assertFalse(resultC); |
| 101 | + } |
| 102 | +} |
0 commit comments