Anagrams { public static List<String> generate(String input) { List<String> anagrams = new ArrayList<String>(); char[] chars = input.toCharArray(); int inputLength = chars.length; int maxAnagrams = calculateTotalAnagramsForWordSize(inputLength); for (int a = 0; a < maxAnagrams; a++) { int pickPosition = calculatePickPosition(inputLength, a); System.out.println("pick at " + pickPosition); int dropPosition = calculateDropPosition(inputLength, pickPosition, a); System.out.println("drop at " + dropPosition); char movingLetter = chars[pickPosition]; System.out.println("moving " + movingLetter); char[] output = new char[inputLength]; for (int i = 0; i < inputLength; i++) { if (dropPosition == i) { output[dropPosition] = movingLetter; output[pickPosition] = chars[i]; } else { output[i] = chars[i]; } } anagrams.add(String.valueOf(output)); } return anagrams; }  static List<String> generate(String input);  }
@Test public void testCalculateTotalAnagrams() throws Exception { String input = "four"; List<String> output = Anagrams.generate(input); assertThat(output).hasSize(24); }
@Test public void testOriginalWordIsAnAnagramOfItself() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("biro"); }
@Test public void testOriginalWordIsAnAnagramOfItself2() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("biro"); }
@Test public void testNewForCIPoints() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("ibro"); }
@Test public void testNewForCIPoints2() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("ibro"); }
@Test public void testSwapFirstLetterIntoSecondPosition() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("ibro"); }
@Test public void testSwapFirstLetterIntoThirdPosition() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("ribo"); }
@Test public void testSwapFirstLetterIntoFourthPosition() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("oirb"); }
@Test public void testSwapFirstLetterIntoAllPositions() throws Exception { String input = "blundell"; List<String> output = Anagrams.generate(input); assertThat(output).contains( "blundell", "lbundell", "ulbndell", "nlubdell", "dlunbell", "elundbll", "llundebl", "llundelb"); }
@Test public void testSwapSecondLetterIntoFirstPosition() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("ibro"); }
@Test public void testSwapSecondLetterIntoSecondPosition() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("biro"); }
@Ignore @Test public void testSwapSecondLetterIntoThirdPosition() throws Exception { String input = "biro"; List<String> output = Anagrams.generate(input); assertThat(output).contains("brio"); }