JavaAlgorithms
Elementary and no so elementary Java algorithms
stringAlgorithms/StringTests.java
Go to the documentation of this file.
00001 
00009 package stringAlgorithms;
00010 
00011 import static org.junit.Assert.*;
00012 
00013 import org.junit.Test;
00014 
00015 public class StringTests {
00016 
00017     @Test
00018     public void testReverse() {
00019         String s1 = "abcdefgh";
00020         String s1Rev = "hgfedcba";
00021         String s2 = "abcdefghi";
00022         String s2Rev = "ihgfedcba";
00023 
00024         assertTrue("Failed to reverse " + s1,
00025                 Algorithms.reverse(s1).equals(s1Rev));
00026         assertTrue("Failed to reverse " + s2,
00027                 Algorithms.reverse(s2).equals(s2Rev));
00028     }
00029 
00030     @Test
00031     public void testisSubstring() {
00032         assertTrue("run should be a substring of running", Algorithms.isSubstring("run", "running"));
00033         assertTrue("read should be a substring of read", Algorithms.isSubstring("read", "read"));
00034         assertTrue("foo should be a substring of \"big foo deal\"", Algorithms.isSubstring("foo", "big foo deal"));
00035         assertTrue("read should be a substring of \"you can read\"", Algorithms.isSubstring("read", "you can read"));
00036         assertTrue("read should be a substring of \"she was reading\"", Algorithms.isSubstring("read", "she was reading"));
00037         assertFalse("rolling is not a substring of \"stone roll down\"", Algorithms.isSubstring("rolling", "stone roll down"));
00038     }
00039 }
 All Classes Namespaces Files Functions Variables