-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStringHelperTests.java
More file actions
104 lines (92 loc) · 2.69 KB
/
StringHelperTests.java
File metadata and controls
104 lines (92 loc) · 2.69 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* $Header$
*
* Copyright (C) 2019 Cefalo AS.
* All Rights Reserved. No use, copying or distribution of this
* work may be made except in accordance with a valid license
* agreement from Cefalo AS. This notice must be included on all
* copies, modifications and derivatives of this work.
*/
package com.cefalo.tdd;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author <a href="mailto:fmshaon@gmail.com">Ferdous Mahmud Shaon</a>
* @author last modified by $Author$
* @version $Revision$ $Date$
*/
public class StringHelperTests {
/*
* Truncate A if it is present in the first two characters of a String
* Sample input and Output:
* "BCDE" => "BCDE"
* "ABCD" => "BCD"
* "AACD" => "CD"
* "BACD" => "BCD"
* "AAAA" => "AA"
* "MNAA" => "MNAA"
* "A" => ""
* "" => ""
*/
@Test
public void testTruncateFirst2As_ANotPresent() {
assertEquals("BCDE", StringHelper.truncateFirst2As("BCDE"));
}
@Test
public void testTruncateFirst2As_AInFirstCharOnly() {
assertEquals("BCD", StringHelper.truncateFirst2As("ABCD"));
}
@Test
public void testTruncateFirst2As_AInFirstTwoCharsOnly() {
assertEquals("CD", StringHelper.truncateFirst2As("AACD"));
}
@Test
public void testTruncateFirst2As_AInSecondCharOnly() {
assertEquals("BCD", StringHelper.truncateFirst2As("BACD"));
}
@Test
public void testTruncateFirst2As_AInAllChars() {
assertEquals("AA", StringHelper.truncateFirst2As("AAAA"));
}
@Test
public void testTruncateFirst2As_ANotInFirstTwoChars() {
assertEquals("MNAA", StringHelper.truncateFirst2As("MNAA"));
}
@Test
public void testTruncateFirst2As_AInOneCharString() {
assertEquals("", StringHelper.truncateFirst2As("A"));
}
@Test
public void testTruncateFirst2As_EmptyString() {
assertEquals("", StringHelper.truncateFirst2As(""));
}
/*
* Swap tbe last two characters of a String
* Sample input and Output:
* "AB" => "BA"
* "ABCD" => "ABDC"
* "AACDEFGHIJ" => "AACDEFGHJI"
* "A => "A"
* "" => ""
*/
@Test
public void testSwapLastTwoChars_TwoCharOnlyString() {
assertEquals("BA", StringHelper.swapLastTwoChars("AB"));
}
@Test
public void testSwapLastTwoChars_MoreThanTwoCharString() {
assertEquals("ABDC", StringHelper.swapLastTwoChars("ABCD"));
}
@Test
public void testSwapLastTwoChars_LargeString() {
assertEquals("AACDEFGHJI", StringHelper.swapLastTwoChars("AACDEFGHIJ"));
}
@Test
public void testSwapLastTwoChars_OneCharString() {
assertEquals("A", StringHelper.swapLastTwoChars("A"));
}
@Test
public void testSwapLastTwoChars_EmptyString() {
assertEquals("", StringHelper.swapLastTwoChars(""));
}
}