* into justified text paragraphs.
*/
class StringJustifier {
+ /**
+ * Process the given text into a list of left-justified lines of a given
+ * max-width.
+ *
+ * @param data
+ * the text to justify
+ * @param width
+ * the maximum width of a line
+ *
+ * @return the list of justified lines
+ */
+ static List<String> left2(final String data, final int width) {
+ List<String> result = new LinkedList<String>();
+
+ return result;
+ }
/**
* Left-justify a string into a list of lines.
inWord = true;
}
}
- } // for (int j = 0; j < rawLines[i].length(); j++)
+ } // next j
if (word.length() + line.length() > n) {
// This word will exceed the line length. Wrap at it
line.append(word);
}
result.add(line.toString());
- } // for (int i = 0; i < rawLines.length; i++) {
+ } // next i
return result;
}
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
addTest(new TestCase("Justifying") {
@Override
public void test() throws Exception {
- for (String data : new String[] {}) {
- // TODO: test it!
- // String result = StringUtils.justifyText(data, 5,
- // StringUtils.Alignment.LEFT);
+ for (String data : new String[] { "test",
+ "let's test some words", "" }) {
+ int total = 0;
+ for (String word : data.split((" "))) {
+ total += word.replace("-", "").replace(" ", "")
+ .length();
+ }
+ List<String> result = StringUtils.justifyText(data, 5,
+ StringUtils.Alignment.LEFT);
+
+ System.out.println("["+data+"] -> [");
+
+ int totalResult = 0;
+ for (String resultLine : result) {
+ System.out.println(resultLine);
+ for (String word : resultLine.split((" "))) {
+ totalResult += word.replace("-", "")
+ .replace(" ", "").length();
+ }
+ }
+ System.out.println("]");
+
+ assertEquals(
+ "The number of letters ('-' not included) should be identical before and after",
+ total, totalResult);
}
}
});
public Test(String[] args) {
super("Nikiroo-utils", args);
+ /*
addSeries(new ProgressTest(args));
addSeries(new BundleTest(args));
addSeries(new IOUtilsTest(args));
addSeries(new VersionTest(args));
addSeries(new SerialTest(args));
addSeries(new SerialServerTest(args));
- addSeries(new StringUtilsTest(args));
- addSeries(new TempFilesTest(args));
+ */addSeries(new StringUtilsTest(args));
+ //addSeries(new TempFilesTest(args));
// TODO: test cache and downloader
Cache cache = null;