Advertisement
Guest User

Untitled

a guest
Mar 24th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import org.junit.runner.JUnitCore;
  2. import org.junit.runner.Result;
  3. import org.junit.runner.notification.Failure;
  4.  
  5. public class TestRunnerStringMethods {
  6. public static void main(String[] args) {
  7. Result result = JUnitCore.runClasses(TestJunitMyIndexOf.class);
  8. for (Failure failure : result.getFailures()) {
  9. System.out.println(failure.toString());
  10. }
  11. System.out.println(result.wasSuccessful());
  12. }
  13. }
  14.  
  15.  
  16. String nullString = null;
  17.  
  18. public static int myIndexOf(char[] str, int ch, int index) {
  19. if (str == null) {
  20. // output NullPointerException
  21. }
  22. if (str.length <= index || index < 0) {
  23. return -1;
  24. }
  25. for (int i = index; i < str.length; i++) {
  26. if (index == str[i]) {
  27. return i;
  28. }
  29. }
  30. // if not found
  31. return -1;
  32. }
  33.  
  34. assertEquals(nullString.indexOf(3), StringMethods.myIndexOf(null, 'd',3));
  35.  
  36.  
  37. OUTPUT:
  38.  
  39. testMyIndexOf2(TestingStringMethods.TestJunitMyIndexOf): null
  40. false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement