Package org.olat.modules.fo

Source Code of org.olat.modules.fo.WordCountTest

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>&nbsp;</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 &eacute;crire. Et encore un ou deux.</p></blockquote></div><p>Et une r&eacute;ponse avec citation incorpor&eacute;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());
    }
  }
}
TOP

Related Classes of org.olat.modules.fo.WordCountTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.