营销型网站建设供货商,网站建设公司大全,ui设计30岁后的出路,对网站建设起到计划和指导的作用2023全国大学生软件测试大赛开发者测试练习题满分答案#xff08;PairingHeap2023#xff09; 题目详情题解代码#xff08;直接全部复制到test类中即可#xff09; 提示#xff1a;该题只需要分支覆盖得分即可#xff0c;不需要变异得分
题目详情 题解代码#xff08;… 2023全国大学生软件测试大赛开发者测试练习题满分答案PairingHeap2023 题目详情题解代码直接全部复制到test类中即可 提示该题只需要分支覆盖得分即可不需要变异得分
题目详情 题解代码直接全部复制到test类中即可
package net.mooctest;import static org.junit.Assert.*;import java.lang.reflect.Method;import java.lang.reflect.InvocationTargetException;import org.junit.Before;import org.junit.Test;public class Heap_ItemTest {Testpublic void test() {Heap_ItemString heap_Item0 new Heap_ItemString(,);Heap_ItemString heap_Item1 new Heap_ItemString(,);heap_Item1.setLeftSon(heap_Item0);heap_Item0.setLeftSon(heap_Item1);heap_Item0.setRightSon(heap_Item1);heap_Item1.replaceChild($, heap_Item0);heap_Item0.getSonByData(,);heap_Item0.getSonByData();assertTrue(heap_Item0.hasLeftSon());}Testpublic void test1() {Heap_ItemString heap_Item0 new Heap_ItemString(,);Heap_ItemString heap_Item1 new Heap_ItemString(,);heap_Item1.setLeftSon(heap_Item0);heap_Item0.setLeftSon(heap_Item1);heap_Item0.setRightSon(heap_Item1);heap_Item1.replaceChild(,, heap_Item0);heap_Item0.getSonByData(,);heap_Item0.getSonByData();assertTrue(heap_Item0.hasLeftSon());}Testpublic void test2() {Heap_ItemString heap_Itemanew Heap_ItemString(a);Heap_ItemString heap_Itembnew Heap_ItemString(b);Heap_ItemString heap_Itemcnew Heap_ItemString(c);Heap_ItemString heap_Itemdnew Heap_ItemString(d);Heap_ItemString heap_Itemenew Heap_ItemString(e);Heap_ItemString heap_Itemknew Heap_ItemString(k);Heap_ItemString heap_Itempnew Heap_ItemString(p);Heap_ItemString heap_Itemqnew Heap_ItemString(q);heap_Itema.setLeftSon(heap_Itemb);heap_Itema.setRightSon(heap_Itemc);heap_Itemb.setRightSon(heap_Itemd);heap_Itemb.setLeftSon(heap_Iteme);heap_Itemb.replaceChild(e, heap_Itemk);heap_Itemb.replaceChild(d, heap_Itemk);heap_Itemb.itIsLeftSon(heap_Itemk);heap_Iteme.setLeftSon(heap_Itemp);heap_Itemq.setLeftSon(heap_Itemq);heap_Iteme.removeLeftSon();heap_Iteme.removeRightSon();heap_Itemb.removeChild(k);heap_Itemb.removeChild(k);heap_Itemb.removeChild(a);Heap_Item String heap_Itema1 heap_Itema.getLeftSon();assertSame(heap_Itema1,heap_Itemb);heap_Itemb.setAncestor(heap_Itema);Heap_Item String heap_Itemn heap_Itemb.getAncestor();assertSame(heap_Itema,heap_Itemb.getAncestor());assertEquals(heap_Itema,heap_Itemn);//设置节点c的祖先为aheap_Itemc.setAncestor(heap_Itema);//节点a无祖先于是返回nullHeap_Item String heap_Itemanullheap_Itema.getMultiWayAncestor();assertNull(heap_Itemanull);//节点b有祖先a,同时又是它的左孩子于是返回他的祖先aHeap_Item String heap_Itembnullheap_Itemb.getMultiWayAncestor();assertNotNull(heap_Itembnull);assertSame(heap_Itema,heap_Itembnull);}Testpublic void testMul() {Heap_ItemString heap_Itemanew Heap_ItemString(a);Heap_ItemString heap_Itembnew Heap_ItemString(b);Heap_ItemString heap_Itemcnew Heap_ItemString(c);Heap_ItemString heap_Itemdnew Heap_ItemString(d);Heap_ItemString heap_Itemenew Heap_ItemString(e);Heap_ItemString heap_Itemknew Heap_ItemString(k);Heap_ItemString heap_Itempnew Heap_ItemString(p);Heap_ItemString heap_Itemqnew Heap_ItemString(q);heap_Itema.setLeftSon(heap_Itemb);heap_Itema.setRightSon(heap_Itemc);heap_Itemb.setRightSon(heap_Itemd);heap_Itemb.setLeftSon(heap_Iteme);heap_Itemb.replaceChild(e, heap_Itemk);heap_Itemb.replaceChild(d, heap_Itemk);heap_Itemb.itIsLeftSon(heap_Itemk);heap_Iteme.setLeftSon(heap_Itemp);heap_Itemq.setLeftSon(heap_Itemq);heap_Iteme.removeLeftSon();heap_Iteme.removeRightSon();heap_Itemb.removeChild(k);heap_Itemb.removeChild(k);heap_Itemb.removeChild(a);Heap_Item String heap_Itema1 heap_Itema.getLeftSon();assertSame(heap_Itema1,heap_Itemb);heap_Itemb.setAncestor(heap_Itema);Heap_Item String heap_Itemn heap_Itemb.getAncestor();assertSame(heap_Itema,heap_Itemb.getAncestor());assertEquals(heap_Itema,heap_Itemn);//设置节点c的祖先为aheap_Itemc.setAncestor(heap_Itema);//节点a无祖先于是返回nullHeap_Item String heap_Itemanullheap_Itema.getMultiWayAncestor();assertNull(heap_Itemanull);//节点b有祖先a,同时又是它的左孩子于是返回他的祖先aHeap_Item String heap_Itembnullheap_Itemb.getMultiWayAncestor();assertNotNull(heap_Itembnull);assertSame(heap_Itema,heap_Itembnull);//先给a设置右祖先Heap_Item String heap_Items1 new Heap_ItemString(s1);heap_Itema.setAncestor(heap_Items1);heap_Items1.setLeftSon(heap_Itema);//检查a的祖先是否为s1assertSame(heap_Items1,heap_Itema.getAncestor());//检查c的祖先是否为aassertSame(heap_Itema,heap_Itemc.getAncestor());//给s1复制左孩子为s2Heap_Item String heap_Items2 new Heap_ItemString(s2);heap_Items2.setAncestor(heap_Items1);heap_Items1.setRightSon(heap_Items2);//节点c有祖先a,但是a的右孩子于是返回a的最近的以a作为左子孙的祖先,即s1Heap_Item String heap_Itemcnullheap_Itemc.getMultiWayAncestor();assertSame(heap_Itemcnull,heap_Items1);}Testpublic void testpair() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{ClassPairing_Heap c Pairing_Heap.class;Heap_ItemString a1new Heap_Item(a1);Heap_ItemString a2new Heap_Item(a2);Heap_ItemString b1new Heap_Item(b1);a1.setLeftSon(b1);b1.setAncestor(a1);Pairing_HeapString p1new Pairing_Heap(a1);Pairing_HeapString p2new Pairing_Heap(a2);Method pair c.getDeclaredMethod(pair, Pairing_Heap.class, Pairing_Heap.class);pair.setAccessible(true);//情况3Pairing_HeapString knew Pairing_Heap();Object invoke pair.invoke(k, p1, p2);//情况1Pairing_HeapString null1new Pairing_Heap();Object invoke1 pair.invoke(k, null1,p2);//情况2pair.invoke(k, p1,null1);//情况4Heap_ItemString d1new Heap_Item(d1);Heap_ItemString d2new Heap_Item(d2);Pairing_HeapString pd1new Pairing_Heap(d1);Pairing_HeapString pd2new Pairing_Heap(d2);pair.invoke(k, pd1,pd2);//情况5Heap_ItemString e1new Heap_Item(e1);Heap_ItemString e2new Heap_Item(e2);Heap_ItemString be1new Heap_Item(be1);e1.setLeftSon(be1);be1.setAncestor(e1);Pairing_HeapString pe1new Pairing_Heap(e2);Pairing_HeapString pe2new Pairing_Heap(e1);pair.invoke(k, pe1,pe2);//情况6Heap_ItemString f1new Heap_Item(e1);Heap_ItemString f2new Heap_Item(e2);Pairing_HeapString pf1new Pairing_Heap(f2);Pairing_HeapString pf2new Pairing_Heap(f1);pair.invoke(k, pf1,pf2);}Testpublic void testpop_heap_item() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {ClassPairing_Heap fun Pairing_Heap.class;//情况1Pairing_HeapString null1new Pairing_Heap();Method pair fun.getDeclaredMethod(pop_heap_item);pair.setAccessible(true);pair.invoke(null1);//情况2Heap_ItemString bnew Heap_Item(b);Pairing_HeapString pbnew Pairing_Heap(b);pair.invoke(pb);//情况3Heap_ItemString cnew Heap_Item(c);Heap_ItemString cbnew Heap_Item(cb);c.setLeftSon(cb);cb.setAncestor(c);Pairing_HeapString pcnew Pairing_Heap(c);pair.invoke(pc);//情况四Heap_ItemString dnew Heap_Item(d);Heap_ItemString dbnew Heap_Item(db);Heap_ItemString dbcnew Heap_Item(dbc);Heap_ItemString dbc0new Heap_Item(dbc0);d.setLeftSon(db);db.setAncestor(d);db.setRightSon(dbc);db.setLeftSon(dbc0);dbc0.setAncestor(db);dbc.setAncestor(dbc);Pairing_HeapString pdnew Pairing_Heap(d);pair.invoke(pd);}Testpublic void testpush() {//根为空的情况Pairing_HeapString null1new Pairing_Heap();Heap_ItemString dnew Heap_Item(d);null1.push(d);//根不为空的情况Heap_ItemString cnew Heap_Item(c);Pairing_HeapString pcnew Pairing_Heap(c);Heap_Item kpc.push(d);}Testpublic void testcheckPriority1_2() {//情况1,2Heap_ItemString anew Heap_Item(a);Heap_ItemString bnew Heap_Item(b);Heap_ItemString cnew Heap_Item(c);Heap_ItemString knew Heap_Item(k);Pairing_HeapString pnew Pairing_Heap();c.setLeftSon(a);a.setAncestor(c);a.setRightSon(b);b.setAncestor(a);b.setRightSon(k);k.setAncestor(b);p.checkPriority(b);}Testpublic void testcheckPriority3() {//情况3Heap_ItemString knew Heap_Item(k);Heap_ItemString b1new Heap_Item(b1);Heap_ItemString b2new Heap_Item(b2);Pairing_HeapString pnew Pairing_Heap();k.setLeftSon(b1);k.setRightSon(b2);b1.setAncestor(k);b2.setAncestor(k);p.checkPriority(k);}Testpublic void testcheckPriority4() {//情况4Heap_ItemString anew Heap_Item(a);Heap_ItemString knew Heap_Item(k);Heap_ItemString b1new Heap_Item(b1);Heap_ItemString b2new Heap_Item(b2);Pairing_HeapString pnew Pairing_Heap();a.setLeftSon(k);k.setAncestor(a);k.setLeftSon(b1);k.setRightSon(b2);b1.setAncestor(k);b2.setAncestor(k);p.checkPriority(k);}Testpublic void testcheckPriority5() {//情况5Heap_ItemString knew Heap_Item(k);Heap_ItemString znew Heap_Item(z);k.setLeftSon(z);z.setAncestor(k);Pairing_HeapString pnew Pairing_Heap();p.checkPriority(k);}Testpublic void testcheckPriority6() {//情况6Heap_ItemString knew Heap_Item(k);Heap_ItemString znew Heap_Item(z);z.setLeftSon(k);k.setAncestor(z);Pairing_HeapString pnew Pairing_Heap();p.checkPriority(k);}Testpublic void testcheckPriority7() {//情况7Heap_ItemString knew Heap_Item(k);Heap_ItemString znew Heap_Item(z);k.setLeftSon(z);z.setAncestor(k);Pairing_HeapString pnew Pairing_Heap();p.checkPriority(z);}Testpublic void testcheckPriority8() {//情况8Heap_ItemString anew Heap_Item(a);Heap_ItemString znew Heap_Item(z);Heap_ItemString bnew Heap_Item(b);a.setLeftSon(z);z.setAncestor(a);z.setLeftSon(b);b.setAncestor(z);Pairing_HeapString pnew Pairing_Heap();p.checkPriority(z);}Testpublic void testcheckPriority9() {//情况9Heap_ItemString anew Heap_Item(a);Heap_ItemString bnew Heap_Item(b);Heap_ItemString cnew Heap_Item(c);Heap_ItemString dnew Heap_Item(d);a.setLeftSon(b);b.setAncestor(a);b.setLeftSon(c);c.setAncestor(b);c.setRightSon(d);d.setAncestor(c);Pairing_HeapString pnew Pairing_Heap();p.checkPriority(b);}Testpublic void testgetData() {Heap_ItemString null2new Heap_Item();null2.getData();}Testpublic void testgetSonByData() {Heap_ItemString knew Heap_Item(k);Heap_ItemString znew Heap_Item(z);Heap_ItemString z2new Heap_Item(z2);Heap_ItemString z1new Heap_Item(z1);k.setLeftSon(z);k.setRightSon(z2);z2.setAncestor(k);z.setAncestor(k);k.removeChild(z1);}Testpublic void testgetSonByData1() {Heap_ItemString knew Heap_Item(k);k.getSonByData(null);Heap_ItemString z2new Heap_Item(z2);k.setRightSon(z2);z2.setAncestor(k);k.getSonByData(z2);}Testpublic void testreplaceChild1() {Heap_ItemString knew Heap_Item(k);Heap_ItemString z2new Heap_Item(z2);k.setRightSon(z2);z2.setAncestor(k);k.replaceChild(z1, z2);}Testpublic void testgetMultiWayAncestor2() {Heap_ItemString knew Heap_Item(k);Heap_ItemString cnew Heap_Item(c);Heap_ItemString anew Heap_Item(a);Heap_ItemString bnew Heap_Item(b);c.setLeftSon(k);k.setAncestor(c);k.setRightSon(a);a.setAncestor(k);a.setRightSon(b);b.setAncestor(a);b.getMultiWayAncestor();}Testpublic void testpop() {Heap_ItemString knew Heap_Item(k);Heap_ItemString znew Heap_Item(z);k.setLeftSon(z);z.setAncestor(k);Pairing_HeapString pnew Pairing_Heap();Pairing_HeapString p1new Pairing_Heap(k);p.pop();p1.pop();}
}