Skip to content

Instantly share code, notes, and snippets.

@yusufaytas
Created May 15, 2015 09:34
Show Gist options
  • Save yusufaytas/483cfccf55a143b2c270 to your computer and use it in GitHub Desktop.
Save yusufaytas/483cfccf55a143b2c270 to your computer and use it in GitHub Desktop.
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