1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.util.Random;
public class TripleTests {
private String alph = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private Random randGen = new Random();
@Test
public void basicTests() {
System.out.println("Hard Coded Tests");
assertEquals("abcabcabc", Solution.tripleTrouble("aaa", "bbb", "ccc"));
assertEquals("abcabcabcabcabcabc", Solution.tripleTrouble("aaaaaa","bbbbbb","cccccc"));
assertEquals("brrueordlnsl", Solution.tripleTrouble("burn", "reds", "roll"));
assertEquals("Supermans", Solution.tripleTrouble("Sea", "urn", "pms"));
assertEquals("LexLuthor", Solution.tripleTrouble("LLh","euo","xtr"));
}
@Test
public void randomTests() {
System.out.println("Testing 100 random inputs...");
for (int i = 0; i < 100; i++) {
int rand = randGen.nextInt(100);
String one = randStr(rand);
String two = randStr(rand);
String three = randStr(rand);
String msg = "Should work for:\n" + one + ",\n" + two + ",\n" + three + ".\n";
assertEquals(msg, tripleAns(one, two, three), Solution.tripleTrouble(one, two, three));
}
}
private String randStr(int n) {
String t = "";
for (int i = 0; i < n; i++) {
t += "" + alph.charAt(randGen.nextInt(alph.length()));
}
return t;
}
private String tripleAns(String a, String b, String c) {
String t = "";
for (int i = 0; i < a.length(); i++) {
t += a.substring(i, i+1) + b.substring(i, i+1) + c.substring(i, i+1);
}
return t;
}
}
|