package org.olat.modules.fo;
import java.util.Locale;
import junit.framework.TestCase;
import org.olat.core.commons.services.text.TextService;
import org.olat.core.commons.services.text.impl.TextServiceImpl;
import org.olat.core.util.filter.Filter;
public class WordCountTest extends TestCase {
public void testCleanMessage() {
Filter filter = new QuoteAndTagFilter();
String text = "<p> </p><div class=\"b_quote_wrapper\"><div class=\"b_quote_author mceNonEditable\">Am 23.11.09 12:29 hat OLAT Administrator geschrieben:</div><blockquote class=\"b_quote\"><p>Quelques mots que je voulais écrire. Et encore un ou deux.</p></blockquote></div><p>Et une réponse avec citation incorporée</p>";
String output = filter.filter(text);
assertTrue("mismatch, got: "+output," Et une réponse avec citation incorporée".equals(output));
}
/**
* Test pass if the detection is better as 80%
*/
public void testDetectLanguage() {
double count = 0;
TextService languageService = new TextServiceImpl();
for(TestTextCase.Text text:TestTextCase.getCases()) {
Locale locale = languageService.detectLocale(text.getText());
if(locale != null && locale.getLanguage().equals(text.getLanguage())) {
count++;
}
}
double ratio = count / TestTextCase.getCases().length;
assertTrue(ratio > 0.8d);
}
public void testWordCount() {
TextService languageService = new TextServiceImpl();
for(TestTextCase.Text text:TestTextCase.getCases()) {
Locale locale = new Locale(text.getLanguage());
int words = languageService.wordCount(text.getText(), locale);
assertTrue(words == text.getWords());
}
}
public void testCharacterCount() {
TextService languageService = new TextServiceImpl();
for(TestTextCase.Text text:TestTextCase.getCases()) {
Locale locale = new Locale(text.getLanguage());
int characters = languageService.characterCount(text.getText(), locale);
assertTrue(characters == text.getCharacters());
}
}
}