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

📄 form1.java

📁 C程序自动测试程序系统,主要是测试数据结构中的几个经典算法:关于排序,树的遍历等.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.html.*;
import java.util.Properties;
import java.io.*;
import java.util.Vector;

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'Form1' is
 * created in the main() method.
 */
public class Form1 extends Form
{
    private String appPath=new String();
	private String tcPath=new String();
	private String tmpPath=new String();
	private int selected=1;
	public Form1()
	{
		// Required for Visual J++ Form Designer support
		initForm();		

		Properties prop = new Properties(System.getProperties()); 
        appPath=prop.getProperty("user.dir")+"\\";
		tcPath=appPath;
		tmpPath=appPath;
	}

	/**
	 * Form1 overrides dispose so it can clean up the
	 * component list.
	 */
	public void dispose()
	{
		super.dispose();
		components.dispose();
	}

	private void Form1_click(Object source, Event e)
	{
		
	}

	private void button1_click(Object source, Event e)
	{
		PCFileCreator cf=new PCFileCreator (appPath+"/template/"+"tree.c","d:\\tested.c");
		//cf.createSrcFile(1,tcPath+"test.c","abcdefg");
		//cf.compileSrcFile ("test.c",tcPath);
		String p=new String();
		p=cf.displayTempFile ();
		edit1.setText(p);
		
	}

	private void button2_click(Object source, Event e)
	{
		 PTester tester=new PTester();   //生成一个标准程序测试器
		 PBlackTester blackTester=new PBlackTester();//生成一个黑盒测试器 
		 PBlackTesterWG blackTesterWG=new PBlackTesterWG();//若为黑盒带规范器的用 PBlackTesterWG定义
		 PBlackTesterWF blackTesterWF=new PBlackTesterWF();//若为黑盒带过滤器的用 PBlackTesterWF定义
		 Vector key=new Vector();
		 
		 String str,str1,str2,str3=new String();
		 str=str1=str2=null;
		 String testFilename=new String();
		 if (selected==6)
			 openFileDialog1.setFilter("*.c|*.c");
		 else
			 openFileDialog1.setFilter("*.exe|*.exe");
		 openFileDialog1.showDialog();
		 if (openFileDialog1.getFileName().toString().equals ("")) return;
		 else testFilename=openFileDialog1.getFileName();
		 
		 int i;
		 /////////////////////函数段测试和填空题程序////////////////////////////////////////
		 
		 if (selected==1)   //第六个组员
		 { PCFileCreator fileCreator=new PCFileCreator(appPath+"template\\depth.c",testFilename);//读取模板和源程序
		     fileCreator.createSrcFile(1,appPath+"tested.c");     //替换第1个函出生成一个被测程序并编译
		     fileCreator.compileSrcFile("tested.c",appPath);
			 //fileCreator.createSrcFile(1,"tested.c","m-1");
		 }                                               //若为填空则调用createSrcFile(1,"testojb.c","i=1");
		 
		 //////////////////////下接黑盒试题程序////////////////////////////////////////////
		 
		 //////////////////////以下为黑盒试题程序//////////////////////////////////////////
		 
		 ////////////////////////////////////////////////向测试器送入你设计的测试数据//////
		 if (selected==2)//第二个组员 
		 {
		    tester.clearInputData();
			//第一组数据
			tester.addInputData("xiaojun");
			tester.addInputData ("is");
			//tester.addInputData ("35");
			//第二组数据
			tester.addInputData("xiaojun");
			tester.addInputData ("xiaojun");
			//tester.addInputData ("6");
			//第三组数据
			tester.addInputData("ttt");
			tester.addInputData ("ttt");
			//tester.addInputData ("56");
			
		    tester.inputLines=2;
		    tester.outputLines=1;
		    blackTesterWG.inputLines =2;
		    blackTesterWG.outputLines =1; 
		 }
		 else if(selected==3)//第三个组员
		 {
			 tester.clearInputData();
			 //第一组数据
			 tester.addInputData ("1 2 3 4 5");
			 tester.addInputData("5");
			// tester.addInputData ("1 2 3 4 5 6 7 8 9 0");
			// tester.addInputData ("ab");
			 //第二组数据
			 tester.addInputData ("2 1 3 4 3");
			 tester.addInputData("6");
			 //tester.addInputData ("1 2 3 4 5 6 7 8 9 0");
			// tester.addInputData ("a");
			 //第三组数据
			 tester.addInputData ("3 5 9 10 7");
			 tester.addInputData ("3");
			 //tester.addInputData ("2 2 2 2 2 2 2 2 2 2 0");
			// tester.addInputData ("abcdefg");
			 
			 tester.inputLines=2;
		     tester.outputLines=1;
		     blackTester.inputLines =2;
		     blackTester.outputLines =1;  
		 }
		 else if(selected==4)//第四个组员
		 {
			 tester.clearInputData();
			 //第一组数据
			 tester.addInputData ("9876543210");
			 //第二组数据
			 tester.addInputData ("0123456789");
			 //第三组数据
			 tester.addInputData ("9817564320");
			 str1="mid";str2="pre";
			 key.addElement(str1.toString());
			 key.addElement(str2.toString());
			 tester.inputLines=1;
		     tester.outputLines=2;
		     blackTesterWF.inputLines =1;
		     blackTesterWF.outputLines =2;  
		 }
		 else if(selected==5)//第五个组员
		 {
			 tester.clearInputData ();
			  //第一组数据
			 tester.addInputData ("9 8 7 6 5 4 3 2 1 0");
			 //第二组数据
			 tester.addInputData ("3 2 4 8 6 1 0 7 5 9");
			 //第三组数据
			 tester.addInputData ("1 2 3 4 5 6 7 8 9 0");			 
			 tester.inputLines=1;
		     tester.outputLines=3;
		     blackTesterWF.inputLines =1;
		     blackTesterWF.outputLines =3;
			 str1="bub";str2="qck";str3="sel";
			 key.addElement (str1.toString());
			 key.addElement (str2.toString());
			 key.addElement (str3.toString());
			 
		 }
		 
		 /////////////////////////////////////////////////
		 
		 ///////////////////////////////////////////////
		 
		 if (selected==1)
		     tester.test(appPath+"template\\depth.exe");      //对标准程序进行测试为了得到标准答案
		 else if (selected==2)
		     tester.test(appPath+"template\\xiaojun.exe"); 
		 else if (selected==3)
			 tester.test (appPath+"template\\zoro.exe");
		 else if (selected==4)
			 tester.test(appPath+"template\\xj.exe");
		 else if (selected==5)
			 tester.test(appPath+"template\\peanuts.exe");
		 
		 if (selected==3)
		 {
			blackTester.inData=tester.inData;    //黑盒测试的数据与标准测试器中的数据一样
		    blackTester.stdData=tester.outData;  //将标准程序输出结果送入盒黑,为了进行比较
		    blackTester.test(testFilename);    //对被测程序进行测试        
		 }
		 else if(selected==2)
		 {
		    blackTesterWG.inData=tester.inData;    //规范测试的数据与标准测试器中的数据一样
		    blackTesterWG.stdData=tester.outData;  //将标准程序输出结果送入规范,为了进行比较
		    blackTesterWG.test(testFilename);
		 }
		 else if(selected==4||selected==5)
		 {
			 blackTesterWF.inData=tester.inData;    //黑盒测试的数据与标准测试器中的数据一样
	    	 blackTesterWF.stdData=tester.outData;  //将标准程序输出结果送入盒黑,为了进行比较
		     blackTesterWF.test(testFilename);    //对被测程序进行测试
		 }
		 else 
		 {
			 blackTester.inData=tester.inData;    //黑盒测试的数据与标准测试器中的数据一样+

			 blackTester.stdData=tester.outData;  //将标准程序输出结果送入盒黑,为了进行比较
	    	    //对被测程序进行测试
		     if (selected==6) blackTester.test(appPath+"tested.exe");
			 else blackTester.test(testFilename); 
		 }
		 
		
		 ////////////////////////////////////////////////
		 
		 ///////////////////////////////////////////////	
		 if (selected==3)
		     blackTester.compare ();   //进行输出结果比对
		 else if(selected==2) 
			 blackTesterWG.compare();
		 else if(selected==4||selected==5)
			 blackTesterWF.compare (key,1);
		 else 
			 blackTester.compare ();
		 //////////////////////////////////////////////
		 
		 //////////////////////////////////////////////////// 显示每个输出的比对结果相同为yes否则为no
           int intGroup,intRight;
		   str="";
		   for (intGroup=0;intGroup<tester.inData.size()/tester.inputLines;intGroup++)
		   {   
			   intRight=0;
			   str=str+"第"+Integer.toString(intGroup+1)+"组测试数据:\r\n";
			   for (i=0;i<tester.inputLines;i++)
				   str=str+tester.inData.elementAt(intGroup*tester.inputLines+i)+"\r\n";
			   str=str+"输出:\r\n";
			   for (i=0;i<tester.outputLines;i++)
				  if (selected==3)
				  {
					  str=str+blackTester.outData.elementAt (intGroup*tester.outputLines+i)+"\r\n";
				      //str=str+"   与标准答案一致:"+blackTesterWF.cmpResult.elementAt (intGroup*tester.outputLines+i)+"\r\n";
				      if (blackTester.cmpResult.elementAt (intGroup*tester.outputLines+i).toString().equals("yes")) intRight++;
				  }
				  else if(selected==2)
				  { str=str+blackTesterWG.outData.elementAt (intGroup*tester.outputLines+i)+"\r\n";
				    //str=str+"   与标准答案一致:"+blackTesterWG.cmpResult.elementAt (intGroup*tester.outputLines+i)+"\r\n";
    			      if (blackTesterWG.cmpResult.elementAt (intGroup*tester.outputLines+i).toString().equals("yes")) intRight++;

				  }
				  else if(selected==4||selected==5)
					  { str=str+blackTesterWF.outData.elementAt (intGroup*tester.outputLines+i)+"\r\n";
				    //str=str+"   与标准答案一致:"+blackTesterWG.cmpResult.elementAt (intGroup*tester.outputLines+i)+"\r\n";
    			      if (blackTesterWF.cmpResult.elementAt (intGroup*tester.outputLines+i).toString().equals("yes")) intRight++;

				  }
				  else 
				  {

⌨️ 快捷键说明

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