Created
May 15, 2015 09:34
-
-
Save yusufaytas/483cfccf55a143b2c270 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.yusufaytas.test.intercom; | |
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
public class PathsBetweenWordsTest { | |
@Test | |
public void testGetPaths(){ | |
List<String> expectedPath = new ArrayList<String>(); | |
expectedPath.add("dog"); | |
expectedPath.add("dot"); | |
expectedPath.add("cot"); | |
expectedPath.add("cat"); | |
String beginWord = "dog", endWord = "dog"; | |
Set<String> words = new HashSet<String>(expectedPath); | |
List<List<String>> paths = new PathsBetweenWords().getPaths(beginWord, endWord, words); | |
List<String> path = paths.get(0); | |
for (int i = 0; i < path.size(); i++) { | |
assertEquals(expectedPath.get(i), path.get(i)); | |
} | |
} | |
@Test | |
public void testGetPathsNoPath(){ | |
List<String> expectedPath = new ArrayList<String>(); | |
expectedPath.add("dog"); | |
expectedPath.add("cat"); | |
String beginWord = "dog", endWord = "cat"; | |
Set<String> words = new HashSet<String>(expectedPath); | |
List<List<String>> paths = new PathsBetweenWords().getPaths(beginWord, endWord, words); | |
assertEquals(0, paths.size()); | |
} | |
@Test | |
public void testGetPathsWithLoop(){ | |
List<String> expectedPath = new ArrayList<String>(); | |
expectedPath.add("dog"); | |
expectedPath.add("dot"); | |
expectedPath.add("cot"); | |
expectedPath.add("col"); | |
expectedPath.add("xol"); | |
expectedPath.add("xog"); | |
expectedPath.add("cat"); | |
String beginWord = "dog", endWord = "cat"; | |
Set<String> words = new HashSet<String>(expectedPath); | |
List<List<String>> paths = new PathsBetweenWords().getPaths(beginWord, endWord, words); | |
assertEquals(2, paths.size()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment