forked from task032015/stringProblem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringProblemTest.java
More file actions
47 lines (42 loc) · 1.43 KB
/
Copy pathstringProblemTest.java
File metadata and controls
47 lines (42 loc) · 1.43 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
package apple;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class stringProblemTest {
@DataProvider(name= "inputPositiveTesting")
public Object[][] generateDataSetPositive() {
return new Object [][]{
new Object[] {"cantalope",'a',"cntlope","iterate"},
new Object[] {"cantalope",'a',"cntlope","oneLine"}
};
}
@DataProvider(name= "inputNegativeTesting")
public Object[][] generateDataSetNegative() {
return new Object [][]{
new Object[] {"cantalope",'a',"ctlope","iterate"},
new Object[] {"cantalope",'a',"ctlope","oneLine"}
};
}
@Test(dataProvider = "inputPositiveTesting")
public void testUserMapping(String word,char charRemove, String result, String method){
Assert.assertEquals(stringExample(word,charRemove, method), result);
}
@Test(dataProvider = "inputNegativeTesting")
public void testUserMappingNeg(String word,char charRemove, String result, String method){
Assert.assertNotEquals(stringExample(word,charRemove, method), result);
}
public String stringExample(String word, char charRemove, String method) {
String result="";
if(method == "iterate"){
char[] charList = word.toCharArray();
for(char c:charList){
if(c != charRemove){
result = result + c;
}
}
} else if(method == "oneLine"){
result = word.replaceAll(Character.toString(charRemove), "");
}
return result;
}
}