// Path: java_sentence_completion/src/utils/StringTools.java
// public class StringTools {
// 
// 	/**
// 	 * Fold the line up to <em>max_chars</em> characters + the line feed,
// 	 * splitting on spaces when possible
// 	 * 
// 	 * @param max_chars
// 	 *            > 0
// 	 * @param s
// 	 *            non null
// 	 * @return the folded line
// 	 */
// 	public static String fold(int max_chars, String s) {
// 		String ret = "";
// 		int last_split = 0;
// 		int last_space = -1;
// 
// 		for (int i = 0; i < s.length(); i++) {
// 
// 			if (s.charAt(i) == ' ' || s.charAt(i) == '\n') {
// 				last_space = i;
// 			}
// 
// 			if (i - last_split == max_chars) {
// 				if (last_space < last_split) { // no space in the line.
// 												// Split the long word
// 					ret += s.substring(last_split, i) + '\n';
// 					last_split = i;
// 				} else {
// 					ret += s.substring(last_split, last_space) + '\n';
// 					i = last_space; // go back just after the space
// 					last_split = i + 1;
// 				}
// 			}
// 		}
// 		if (last_split != s.length()) {
// 			ret += s.substring(last_split);
// 		}
// 		return ret;
// 	}
// }


import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Random;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import utils.StringTools;
package utils.test;





public class StringToolsTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void fold_test_ntimes() {
		for (int i = 0; i < 100; i++) {
			fold();
		}
	}

	public void fold() {
		String data, ret;
		int max_chars = 4;

		// * if splitting on space always succeeds and no '\n' is present
		// ` then s.equals(re.replaceAll("\n", " "))
		// Whitespace test
		int n = 22;
		data = new String(new char[n]).replaceAll("\0", " "); // repeat str
// Path: java_sentence_completion/src/utils/StringTools.java
// public class StringTools {
// 
// 	/**
// 	 * Fold the line up to <em>max_chars</em> characters + the line feed,
// 	 * splitting on spaces when possible
// 	 * 
// 	 * @param max_chars
// 	 *            > 0
// 	 * @param s
// 	 *            non null
// 	 * @return the folded line
// 	 */
// 	public static String fold(int max_chars, String s) {
// 		String ret = "";
// 		int last_split = 0;
// 		int last_space = -1;
// 
// 		for (int i = 0; i < s.length(); i++) {
// 
// 			if (s.charAt(i) == ' ' || s.charAt(i) == '\n') {
// 				last_space = i;
// 			}
// 
// 			if (i - last_split == max_chars) {
// 				if (last_space < last_split) { // no space in the line.
// 												// Split the long word
// 					ret += s.substring(last_split, i) + '\n';
// 					last_split = i;
// 				} else {
// 					ret += s.substring(last_split, last_space) + '\n';
// 					i = last_space; // go back just after the space
// 					last_split = i + 1;
// 				}
// 			}
// 		}
// 		if (last_split != s.length()) {
// 			ret += s.substring(last_split);
// 		}
// 		return ret;
// 	}
// }


// Path: java_sentence_completion/src/utils/test/StringToolsTest.java
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Random;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import utils.StringTools;

package utils.test;





public class StringToolsTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void fold_test_ntimes() {
		for (int i = 0; i < 100; i++) {
			fold();
		}
	}

	public void fold() {
		String data, ret;
		int max_chars = 4;

		// * if splitting on space always succeeds and no '\n' is present
		// ` then s.equals(re.replaceAll("\n", " "))
		// Whitespace test
		int n = 22;
		data = new String(new char[n]).replaceAll("\0", " "); // repeat str
		ret = StringTools.fold(max_chars, data);