20202302 2021-2022-1 《資料結構與面向物件程式設計》實驗七報告
課程:《程式設計與資料結構》
班級:2023
姓名: 吉相融
學號:20202302
實驗教師:王志強
實驗日期:2021年11月6日
必修/選修: 必修
一、實驗內容
1.定義一個Searching和Sorting類,並在類中實現linearSearch,SelectionSort方法,最後完成測試。要求不少於10個測試用例,提交測試用例設計情況(正常,異常,邊界,正序,逆序),用例資料中要包含自己學號的後四位提交執行結果圖。
2.重構你的程式碼把Sorting.java Searching.java放入 cn.edu.besti.cs2023.(姓名首字母+四位學號) 包中(例如:cn.edu.besti.cs1823.G2301)把測試程式碼放test包中重新編譯,執行程式碼,提交編譯,執行的截圖(IDEA,命令列兩種)
3.參考http://www.cnblogs.com/maybe2030/p/4715035.html ,學習各種查詢演算法並在Searching中補充查詢演算法並測試提交執行結果截圖
4.實現排序方法等(至少3個)測試實現的演算法(正常,異常,邊界)提交執行結果截圖(如果編寫多個排序演算法,即使其中三個排序程式有瑕疵,也可以酌情得滿分)
5.編寫Android程式對實現各種查詢與排序演算法進行測試提交執行結果截圖推送程式碼到碼雲(選做,額外加分)
二、實驗過程及結果
1.定義一個Searching和Sorting類,並在類中實現linearSearch,SelectionSort方法,最後完成測試。要求不少於10個測試用例,提交測試用例設計情況(正常,異常,邊界,正序,逆序),用例資料中要包含自己學號的後四位提交執行結果圖。
碼雲地址:https://gitee.com/jixiangrong/jxr20202302/blob/master/%E5%AE%9E%E9%AA%8C%E4%B8%83/Searching.java
https://gitee.com/jixiangrong/jxr20202302/blob/master/%E5%AE%9E%E9%AA%8C%E4%B8%83/SearchingTest.java
程式碼:
public class Searching { public static <T> boolean linearSearch(T[] date,T target){ int index; date[0] = target; for(index = date.length-1; !date[index].equals(target); --index){ } return index == 0 ? false : true; }import junit.framework.TestCase;
import org.junit.Test; public class SearchingTest extends TestCase { @Test public void test1(){ String[] t1 = {" ", "1", "2", "2302", "3", "4"}; assertEquals(true, Searching.linearSearch(t1, "2")); //正常 assertEquals(false, Searching.linearSearch(t1, "0")); //異常 assertEquals(true, Searching.linearSearch(t1, "1")); //邊界 } @Test public void test2(){ String[] t1 = {"", "nice", "02", "2302", "20", "20"}; assertEquals(true, Searching.linearSearch(t1, "2302")); //正常 assertEquals(false, Searching.linearSearch(t1, "111")); //異常 assertEquals(true, Searching.linearSearch(t1, "nice")); //邊界 } @Test public void test3(){ String[] t1 = {"", "2302", "2323", "2020", "456", "654"}; assertEquals(true, Searching.linearSearch(t1, "2020")); //正常 assertEquals(false, Searching.linearSearch(t1, "222")); //異常 assertEquals(true, Searching.linearSearch(t1, "2302")); //邊界 } @Test public void test4(){ String[] t1 = {"", "11", "22", "33", "44", "2302"}; assertEquals(true, Searching.linearSearch(t1, "2302")); //正常 assertEquals(false, Searching.linearSearch(t1, "333")); //異常 assertEquals(true, Searching.linearSearch(t1, "11")); //邊界 } @Test public void test5(){ String[] t1 = {"", "9", "8", "7", "2302", "6"}; assertEquals(true, Searching.linearSearch(t1, "7")); //正常 assertEquals(false, Searching.linearSearch(t1, "444")); //異常 assertEquals(true, Searching.linearSearch(t1, "9")); //邊界 } @Test public void test6(){ String[] t1 = {"", "44", "789", "26", "2302", "321"}; assertEquals(true, Searching.linearSearch(t1, "26")); //正常 assertEquals(false, Searching.linearSearch(t1, "555")); //異常 assertEquals(true, Searching.linearSearch(t1, "44")); //邊界 } @Test public void test7(){ String[] t1 = {"", "23", "66", "2302", "22", "9"}; assertEquals(true, Searching.linearSearch(t1, "66")); //正常 assertEquals(false, Searching.linearSearch(t1, "666")); //異常 assertEquals(true, Searching.linearSearch(t1, "23")); //邊界 } @Test public void test8(){ String[] t1 = {"", "2323", "16", "2302", "20", "19"}; assertEquals(true, Searching.linearSearch(t1, "2302")); //正常 assertEquals(false, Searching.linearSearch(t1, "777")); //異常 assertEquals(true, Searching.linearSearch(t1, "2323")); //邊界 } @Test public void test9(){ String[] t1 = {"", "566", "665", "1", "2", "2302"}; assertEquals(true, Searching.linearSearch(t1, "2")); //正常 assertEquals(false, Searching.linearSearch(t1, "888")); //異常 assertEquals(true, Searching.linearSearch(t1, "566")); //邊界 } @Test public void test10(){ String[] t1 = {"", "33", "3", "abc", "0", "2302"}; assertEquals(true, Searching.linearSearch(t1, "2302")); //正常 assertEquals(false, Searching.linearSearch(t1, "999")); //異常 assertEquals(true, Searching.linearSearch(t1, "33")); //邊界 } }