1 package testcomtest;
2 import static org.junit.Assert.*;
4 import org.junit.*;
5 import comtest.Strings;
6
8
13 public class StringsTest {
14
15
16
17
19 @Test
20 public void testStrings() { Strings list = new Strings();
22 assertEquals("From: Strings line: 11", 0, list.size());
23 list.add("one"); assertEquals("From: Strings line: 16", 1, list.size()); assertEquals("From: Strings line: 16", "one", list.get(0));
24 list.add("two"); assertEquals("From: Strings line: 17", 2, list.size()); assertEquals("From: Strings line: 17", "one", list.get(0));
25 ; ; assertEquals("From: Strings line: 18", "two", list.get(1));
26 }
28
29
31 @Test
32 public void testAdd() { Strings l1 = new Strings(), l2 = new Strings();
34 l1.add("one"); l1.add("two");
35 l2.add("three"); l2.add("four");
36 l1.add(l2);
37 assertEquals("From: Strings line: 35", "three", l1.get(2)); assertEquals("From: Strings line: 35", "four", l1.get(3));
38 }
40
41
43 @Test
44 public void testClone() { Strings l1 = new Strings(), l2;
46 l1.add("one"); l1.add("two");
47 l2 = l1.clone();
48 l1.set(1,"three");
49 assertEquals("From: Strings line: 52", "one", l2.get(0)); assertEquals("From: Strings line: 52", "two", l2.get(1)); assertEquals("From: Strings line: 52", "three", l1.get(1));
50 }
52
53
55 @Test
56 public void testReplace() { Strings l1 = new Strings();
58 l1.add("one");
59 l1.add("two");
60 l1.add("three");
61 l1.add("four");
62 l1.replace("o","p");
63 assertEquals("From: Strings line: 85", "pne", l1.get(0));
64 assertEquals("From: Strings line: 86", "twp", l1.get(1));
65 assertEquals("From: Strings line: 87", "three", l1.get(2));
66 assertEquals("From: Strings line: 88", "fpur", l1.get(3));
67 }
69
70
72 @Test
73 public void testToString118() { Strings list = new Strings();
75 assertEquals("From: Strings line: 120", "!", list.toString("|","!"));
76 list.add("one");
77 assertEquals("From: Strings line: 122", "one!", list.toString("|","!"));
78 list.add("two");
79 assertEquals("From: Strings line: 124", "one|two!", list.toString("|","!"));
80 assertEquals("From: Strings line: 125", "one|two", list.toString("|",""));
81 assertEquals("From: Strings line: 126", "one|two", list.toString("|",null));
82 }
84
85
87 @Test
88 public void testToString146() { Strings list = new Strings();
90 assertEquals("From: Strings line: 148", "", list.toString("|"));
91 list.add("one");
92 assertEquals("From: Strings line: 150", "one", list.toString("|"));
93 list.add("two");
94 assertEquals("From: Strings line: 152", "one|two", list.toString("|"));
95 } }