📄 stringutiltest.java
字号:
/*
Jacson
Copyright (C) 2003 Patrick Carl, patrick.carl@web.de
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: $
*/
package de.spieleck.util;
import java.util.Set;
import java.util.HashSet;
import junit.framework.*;
/**
* jUnits Tests for de.spieleck.util.StringUtil
* @author Patrick Carl
*/
public class StringUtilTest extends TestCase {
public StringUtilTest(String testName) {
super(testName);
}
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
public static Test suite() {
TestSuite suite = new TestSuite(StringUtilTest.class);
return suite;
}
public void testSingle1()
{
HashSet set1 = new HashSet();
set1.add("hallo");
set1.add("wie");
set1.add("geht");
set1.add("es");
testSingleTriple("hallo wie geht es", ' ', set1);
}
public void testSingle2()
{
HashSet set2 = new HashSet();
set2.add("ein");
set2.add("tag");
set2.add("wie");
set2.add("jeder");
set2.add("andere");
testSingleTriple("ein,tag,wie,jeder,andere", ',', set2);
}
public void testSingle3()
{
HashSet set3 = new HashSet();
set3.add("Jacson");
set3.add("gibt");
set3.add("es");
set3.add("jetzt");
set3.add("auch");
set3.add("bei");
set3.add("uns");
testSingleTriple("Jacson/gibt/es/jetzt/auch/bei/uns", '/', set3);
}
protected void testSingleTriple(String in, char delim, Set correct)
{
Set res = StringUtil.getTokensAsSet(in, delim);
assertEquals("Test: "+in, res, correct);
}
public void testMulti()
{
HashSet setm1 = new HashSet();
setm1.add("A");
setm1.add("H");
setm1.add("from");
setm1.add("M");
setm1.add("ss");
setm1.add("s");
setm1.add("pp");
setm1.add("catched");
setm1.add("the");
setm1.add("lly");
setm1.add("ll");
setm1.add("b");
setm1.add("tra");
setm1.add("t");
setm1.add("n");
setm1.add("w");
setm1.add("th");
setm1.add("a");
setm1.add("e");
testMultiTriple("A Hippie from Missisippi catched the Hillibilly train with a tippie", " i", setm1);
}
protected void testMultiTriple(String in, String delims, Set correct)
{
Set res = StringUtil.getTokensAsSet(in, delims);
assertEquals("Test: "+in, res, correct);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -