Professional Documents
Culture Documents
Test Automation Application Exercises - 2017
Test Automation Application Exercises - 2017
Test Automation Application Exercises - 2017
2017.04.20
Instructions
Here are a couple of coding problems we would like you to complete. Please answer with the language you
feel most comfortable using.
Please add your answers to this document and email it back to us in .DOCX format.
Questions
1.a) Write classes to find any pairs of numbers in a sequence that add up to 10. Example:
Sample input: 1, 8, 2, 3, 5, 7
Sample output: (8,2), (3, 7)
Answer:
_________________________
import java.util.ArrayList;
import java.util.List;
// default constructor
public SumTheNumbers() {
}
_________________________
1.b) Write 5 sample test inputs and corresponding output pairs for your function. Bonus: Write your answer
as a unit test.
Answer:
_________________________
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.testng.annotations.Test;
import junit.framework.Assert;
import junit.framework.TestCase;
@Test(priority = 2)
public void testLessTwoSize() {
SumTheNumbers sumTheNumbers = new SumTheNumbers();
list = new ArrayList<Integer>(Arrays.asList(1));
sumTheNumbers.readingTheInput(list);
sumTheNumbers.returnPairs();
// System.out.println(sumTheNumbers.toString(li));
Assert.assertEquals("Cann't make a pair if a list size is less than 2",
sumTheNumbers.toString());
}
@Test(priority = 3)
public void testToUnableToGeneratePairs() {
SumTheNumbers sumTheNumbers = new SumTheNumbers();
list = new ArrayList<Integer>(Arrays.asList(1, 2, 3));
sumTheNumbers.readingTheInput(list);
sumTheNumbers.returnPairs();
Assert.assertEquals("There are no pair of numbers in a sequence that add
up to 10", sumTheNumbers.toString());
}
@Test(priority = 5)
public void testWithLargeValues() {
SumTheNumbers sumTheNumbers = new SumTheNumbers();
list = new ArrayList<Integer>(Arrays.asList(1, 5, 60, 34, 11, 5, 4, 6,
10, 2, 8, 9, 1));
sumTheNumbers.readingTheInput(list);
sumTheNumbers.returnPairs();
Assert.assertEquals("(1,9),(5,5),(4,6),(2,8),(9,1)",
sumTheNumbers.toString());
}
}
_________________________
2.a) Write a short function to determine if a string is a substring of a longer one. (Note: Don't use a system or
library built-in function like variable.substr() or variable.contains(). Instead, write the code that would
implement the .substr() or .contains() method.) Example:
Answer:
_________________________
2.b) Write 5 sample test inputs and corresponding output for your function.
Answer:
_________________________
import org.testng.annotations.Test;
import junit.framework.Assert;
import junit.framework.TestCase;
@SuppressWarnings("deprecation")
public class TestCases extends TestCase {
@Test(priority = 2)
public void testSubStrWithCaseSensitive() {
Assert.assertEquals("No", DetermineSubString.isSubString("This is a
String", "Is a"));
}
@Test(priority = 3)
public void testSubStrWithMorelength() {
Assert.assertEquals("No", DetermineSubString.isSubString("Problem
Solved", "Problem Solved but"));
}
@Test(priority = 4)
public void testSubStrWithSpecialChars() {
Assert.assertEquals("Yes", DetermineSubString.isSubString("&$$Synopsys",
"&$$"));
}
@Test(priority = 5)
public void testSubStrIsInvalid() {
Assert.assertEquals("No", DetermineSubString.isSubString("Synopsys Smart
Secure Everything", "software"));
}
}
_________________________
Answer: