⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bigstringtest.java

📁 简易模拟电梯系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import java.util.*;

import junit.framework.*;
import junit.framework.TestCase;
import junit.framework.AssertionFailedError;

import ulang.*;
import myException.*;



public class BigStringTest extends TestCase {

	//implement the construct method
	public BigStringTest(String name) {
		super(name);
	}

	////////////////////////////////////////////////////////////////////////////
	//
	// Test the class BigString
	//
	////////////////////////////////////////////////////////////////////////////
	
	//test the default construct method
	public void testBigString(){
		BigString bs = new BigString ();
		assertTrue (bs!=null);
	}
	
	//test the construct method initialize with the string
		public void testBigString1(){
		String str =new String ("abcdefghijklmnopqrstuvwxyz");
		BigString bs = new BigString (str);
		assertTrue (bs!=null);
	}
	
	//test the construct method initialize with the array of char
		public void testBigString2(){
		char [] ca ={'a','b','c','d','e','f','g','h','i','j','k','l'
		,'m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
		BigString bs = new BigString(ca);
		assertTrue (bs!=null);
		assertEquals (26 , bs.Length());
	}
	
	//test the construct method initialize with the stringBuffer
		public void testBigString3(){
		StringBuffer sb =new StringBuffer("abcdefghijklmnopqrstuvwxyz");
		BigString bs = new BigString (sb);
		assertTrue (bs!=null);
		assertEquals (26 , bs.Length());
	}
	
	
	//test the construct method initialize with the BigString itself
	public void testBigString4()throws m_Exception{
		BigString bsv =new BigString("abcdefghijklmnopqrstuvwxy");
		BigString bs = new BigString (bsv);
		assertTrue (bs!=null);
		assertEquals (25 , bs.Length());
	}
	
	//test the  method Length()
	public void testLength(){	
		BigString bs2 = new BigString ("abcdefghijklmnopqrstuvwxyzabcdefghijkl");
		assertEquals (38 , bs2.Length());
			
	}
	
	//test the method charAt()
	public void testcharAt()throws m_Exception{
		BigString bs = new BigString ("abcdefghijklmnopqrstuvwxyz");
		BigString bsTemp = new BigString(bs);
		assertEquals ('a' , bsTemp.charAt(0));
		assertEquals ('c' , bs.charAt(2));
		assertEquals ('z' , bsTemp.charAt(25));
	}
	
	
	//test the method CompareTo()
	public void testCompareTo()throws m_Exception{
		BigString bs1 = new BigString ("123456");
		BigString bs2 = new BigString ("abcdefghijklmnopqrstuvwxyz");
		BigString bs3 = new BigString ("abcdefghijklmnopqrstuvwxyz");
		assertEquals (0 , bs3.compareTo(bs2));
		assertEquals (-1 , bs3.compareTo(bs1));
	}
	
	//test the method concat()
	public void testconcat()throws m_Exception{
		BigString bs1 = new BigString("abcdefghijkl");
		BigString bs2 = new BigString("mnopqrstuvwxyz");
		BigString bs12 = new BigString("abcdefghijklmnopqrstuvwxyz");
		assertEquals (bs12.toString() , bs1.concat(bs2).toString());
	}
	
	//test the method ContentEquals()
	public void testContentEquals()throws m_Exception{
		BigString bs1 = new BigString ("abcdefghijklmnopqrstuvwxyz");
		BigString bs2 = new BigString ("abcdefghijklmnopqrstuvwxyz");
		assertEquals (true , bs2.contentEquals(bs1));
	}
	
	//test the method getChars()
	public void testgetChars()throws m_Exception{
		BigString bs2 = new BigString ("abcdefghijklmnopqrstuvwxyz");
		BigString bs5 = new BigString(bs2);
		assertEquals ("abc" , bs5.getChars(0,3));
		assertEquals ("def" , bs5.getChars(3,6));
		assertEquals ("xyz" , bs5.getChars(23,26));
	}
	
	//test the method subString(long beginIndex)
    public void testsubString()throws m_Exception{
    	BigString bs1 = new BigString ("abcdefghijklmnopqrstuvwxyz");
    	BigString bs2 = new BigString("xyz");
    	assertEquals ("xyz" , bs1.subString(23).toString());
    	assertEquals (bs1.toString() , bs1.subString(0).toString()); 
    	assertEquals ("lmnopqrstuvwxyz", bs1.subString(11).toString());
		
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -