Skip to content

Commit

Permalink
update exos StringUtils to match String.split spec
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreDubray committed Sep 16, 2020
1 parent 85c829c commit 3b59d8a
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 79 deletions.
46 changes: 34 additions & 12 deletions StringUtils/public/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
public class StringUtils {


/*
* Split the input string 'str' w.r.t the character 'marker' in an array of String
* for example split("test-test", '-') => {"test", "test"}
* Must return null if there is no occurrence of 'marker' in 'str'
/**
* Split a strin according to a delimiter
*
* @param str The string to split
* @param delimiter The delimiter
* @return An array containing the substring which fall
* between two consecutive occurence of the delimiter.
* If there is no occurence of the delimiter, it should
* return an array of size 1 with the string at element 0
*/
public static String [] split(String str, char marker){
public static String [] split(String str, char delimiter){

}


/*
* Returns the index of the first occurrence of sub in str
* or -1 if there is no occurrence of sub in str at all.
* Be careful, we ask you to make CASE SENSITIVE comparison between str and sub.
/**
* Find the first occurence of a substring in a string
*
* @param str The string to look in
* @param sub The string to look for
* @return The index of the start of the first appearance of
* the substring in str or -1 if sub does not appear
* in str
*/
public static int indexOf(String str, String sub){

}


/**
* Convert a string to lowercase
*
* @param str The string to convert
* @return A new string, same as str but with every
* character put to lower case.
*/
public static String toLowerCase(String str){

}


/*
* Returns true if the string 'str' is a palindrome (a string that reads the same from
* left to right AND from right to left).
/**
* Check if a string is a palyndrome
*
* A palyndrome is a sequence of character that is the
* same when read from left to right and from right to
* left.
*
* @param str The string to check
* @return true if str is a palyndrome, false otherwise
*/
public static boolean palindrome(String str){

Expand Down
12 changes: 2 additions & 10 deletions StringUtils/src/InginiousTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,13 @@ public void testPalindrome(){
@Grade
@Test
public void testSplit() {

String[][] seeds = Stream.generate(rsg_split).limit(10).toArray(String[][]::new);

for (String[] seed : seeds) {
String[] splitJDK = seed[0].split(seed[1]);
String[] splitStd = StringUtils.split(seed[0], seed[1].charAt(0));
for (int i = 0; i < splitJDK.length; i++) {
assertEquals(splitJDK[i], splitStd[i]);
// ignore the NPE warning, it will never happen AS LONG AS you use "rsg_split" to generate
// input strings
}
assertArrayEquals(splitJDK, splitStd);
}

assertNull(StringUtils.split("Hello world", '=')); // no occurrence of marker, should return null

}


Expand All @@ -139,4 +131,4 @@ public void testIndexOf(){



}
}
66 changes: 43 additions & 23 deletions StringUtils/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,64 @@ context: |-
public class StringUtils {
/*
* Split the input string 'str' w.r.t the character 'marker' in an array of String
* for example split("test-test", '-') => {"test", "test"}
* Must return null if there is no occurrence of 'marker' in 'str'
*/
public static String [] split(String str, char marker){
// YOUR CODE HERE
/**
* Split a string according to a delimiter
*
* @param str The string to split
* @param delimiter The delimiter
* @return An array containing the substring which fall
* between two consecutive occurence of the delimiter.
* If there is no occurence of the delimiter, it should
* return an array of size 1 with the string at element 0
*/
public static String [] split(String str, char delimiter){
}
/*
* Returns the index of the first occurrence of sub in str
* or -1 if there is no occurrence of sub in str at all.
* Be careful, we ask you to make CASE SENSITIVE comparison between str and sub.
*/
/**
* Find the first occurence of a substring in a string
*
* @param str The string to look in
* @param sub The string to look for
* @return The index of the start of the first appearance of
* the substring in str or -1 if sub does not appear
* in str
*/
public static int indexOf(String str, String sub){
// YOUR CODE HERE
}
/*
* Returns a String with the same characters as 'str' except that
* all upper case characters have been replaced by their lower case equivalent.
*/
/**
* Convert a string to lowercase
*
* @param str The string to convert
* @return A new string, same as str but with every
* character put to lower case.
*/
public static String toLowerCase(String str){
// YOUR CODE HERE
}
/*
* Returns true if the string 'str' is a palindrome (a string that reads the same from
* left to right AND from right to left).
*/
/**
* Check if a string is a palyndrome
*
* A palyndrome is a sequence of character that is the
* same when read from left to right and from right to
* left.
*
* @param str The string to check
* @return true if str is a palyndrome, false otherwise
*/
public static boolean palindrome(String str){
// YOUR CODE HERE
}
}
environment: java8scala
evaluate: best
file: ''
Expand Down
26 changes: 1 addition & 25 deletions StringUtils/templates/StringUtils.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
package src;


public class StringUtils {


/*
* Split the input string 'str' w.r.t the character 'marker' in an array of String
* for example split("test-test", '-') => {"test", "test"}
* Must return null if there is no occurrence of 'marker' in 'str'
*/
public static String [] split(String str, char marker){

public static String [] split(String str, char delimiter){
@ @student_split@@

}


/*
* Returns the index of the first occurrence of sub in str
* or -1 if there is no occurrence of sub in str at all.
* Be careful, we ask you to make CASE SENSITIVE comparison between str and sub.
*/
public static int indexOf(String str, String sub){
@ @student_indexof@@
}


public static String toLowerCase(String str){
@ @student_tolowercase@@
}


/*
* Returns true if the string 'str' is a palindrome (a string that reads the same from
* left to right AND from right to left).
*/
public static boolean palindrome(String str){
@ @student_palindrome@@
}


}
11 changes: 2 additions & 9 deletions StringUtils/unit_test/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,14 @@ public void testPalindrome(){

@Test
public void testSplit() {

String[][] seeds = Stream.generate(rsg_split).limit(10).toArray(String[][]::new);

for (String[] seed : seeds) {
String[] splitJDK = seed[0].split(seed[1]);
String[] splitStd = StringUtils.split(seed[0], seed[1].charAt(0));
for (int i = 0; i < splitJDK.length; i++) {
assertEquals(splitJDK[i], splitStd[i]);
// ignore the NPE warning, it will never happen AS LONG AS you use "rsg_split" to generate
// input strings
}
assertArrayEquals(splitJDK, splitStd);
}

assertNull(StringUtils.split("Hello world", '=')); // no occurrence of marker, should return null

}


Expand All @@ -131,4 +124,4 @@ public void testIndexOf(){



}
}

0 comments on commit 3b59d8a

Please sign in to comment.