2023全国大学生软件测试大赛开发者测试练习题99分答案(ScapegoatTree2023)

2023全国大学生软件测试大赛开发者测试练习题99分答案(ScapegoatTree2023)

  • 题目详情
  • 题解代码(直接全部复制到test类中即可)


提示:该题只需要分支覆盖得分即可,不需要变异得分

题目详情

在这里插入图片描述

在这里插入图片描述




题解代码(直接全部复制到test类中即可)

package net.mooctest;import static org.junit.Assert.*;import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;import org.junit.Test;import net.mooctest.AbstractBinarySearchTree.Node;public class AbstractSelfBalancingBinarySearchTreeTest {private Method declaredMethod;@Testpublic void test() {/*ScapegoatTree scapegoatTree0 = new ScapegoatTree();AbstractBinarySearchTree.Node abstractBinarySearchTree_Node0 = scapegoatTree0.createNode((-3252),(AbstractBinarySearchTree.Node) null, (AbstractBinarySearchTree.Node) null,(AbstractBinarySearchTree.Node) null);AbstractBinarySearchTree.Node abstractBinarySearchTree_Node1 = new AbstractBinarySearchTree.Node(abstractBinarySearchTree_Node0.value, abstractBinarySearchTree_Node0, abstractBinarySearchTree_Node0,abstractBinarySearchTree_Node0);AbstractBinarySearchTree.Node abstractBinarySearchTree_Node2 = scapegoatTree0.rotateRight(abstractBinarySearchTree_Node1);scapegoatTree0.rotateLeft(abstractBinarySearchTree_Node1);AbstractBinarySearchTree.Node abstractBinarySearchTree_Node3 = scapegoatTree0.rotateRight(abstractBinarySearchTree_Node2);assertTrue(abstractBinarySearchTree_Node1.isLeaf());assertSame(abstractBinarySearchTree_Node0, abstractBinarySearchTree_Node3);*/}@Testpublic void testNode() {ScapegoatTree scapegoatTree0 = new ScapegoatTree();AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(null,null,Node0,Node0);assertTrue(Node0.isLeaf());assertTrue(Node0.isLeaf());assertNotEquals(Node0.hashCode(),31);assertEquals(Node1.hashCode(),31);}@Testpublic void testequals() {AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(null,null,Node0,Node0);AbstractBinarySearchTree.Node Node3 = new AbstractBinarySearchTree.Node(null,null,Node0,Node0);AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node Node4 = new AbstractBinarySearchTree.Node(2,null,null,null);assertTrue(Node1.equals(Node1));assertFalse(Node1.equals(null));assertFalse(Node1.equals("z1"));assertFalse(Node1.equals(Node0));assertTrue(Node1.equals(Node3));assertTrue(Node2.equals(Node4));assertFalse(Node0.equals(Node1));assertFalse(Node0.equals(Node2));}@Testpublic void testsubtree() {ScapegoatTree st1= new ScapegoatTree();AbstractBinarySearchTree.Node Node00 = new AbstractBinarySearchTree.Node(null,null,null,null);AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(1,null,Node0,Node0);//Node2节点只有右子树AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(1,null,null,Node0);//Node3节点只有左子树AbstractBinarySearchTree.Node Node3 = new AbstractBinarySearchTree.Node(1,null,Node0,null);//Node4节点有左子树和右子树但值为nullAbstractBinarySearchTree.Node Node4 = new AbstractBinarySearchTree.Node(null,null,Node0,Node0);//Node5节点有左子树和右子树但值为null且左右子树节点为nullAbstractBinarySearchTree.Node Node5 = new AbstractBinarySearchTree.Node(null,null,Node00,Node00);//Node6节点有左子树和右子树但值为null且左右子树节点为null,右子树节点有右子树与左子树AbstractBinarySearchTree.Node Node6 = new AbstractBinarySearchTree.Node(null,null,Node4,Node4);st1.printSubtree(Node1);st1.printSubtree(Node2);st1.printSubtree(Node3);st1.printSubtree(Node4);st1.printSubtree(Node5);st1.printSubtree(Node6);}@Testpublic void testisLeaf() {ScapegoatTree st1= new ScapegoatTree();AbstractBinarySearchTree.Node Node00 = new AbstractBinarySearchTree.Node(null,null,null,null);AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(1,null,Node0,Node0);AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(1,null,Node0,null);AbstractBinarySearchTree.Node Node3 = new AbstractBinarySearchTree.Node(1,null,null,Node0);assertFalse(Node1.isLeaf());assertTrue(Node00.isLeaf());assertFalse(Node2.isLeaf());assertFalse(Node3.isLeaf());}@Testpublic void testgetmaxinum() {ScapegoatTree st1= new ScapegoatTree();AbstractBinarySearchTree.Node Node00 = new AbstractBinarySearchTree.Node(null,null,null,null);AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(1,null,Node0,Node0);AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(1,null,Node0,null);AbstractBinarySearchTree.Node Node3 = new AbstractBinarySearchTree.Node(1,null,null,Node0);assertEquals(Node0,st1.getMaximum(Node1));assertEquals(Node0,st1.getMinimum(Node1));}@Testpublic void testSuccessor() {ScapegoatTree st1= new ScapegoatTree();AbstractBinarySearchTree.Node Node00 = new AbstractBinarySearchTree.Node(null,null,null,null);AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(1,null,Node0,Node0);AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(1,null,Node0,null);AbstractBinarySearchTree.Node Node3 = new AbstractBinarySearchTree.Node(1,null,null,Node0);assertEquals(Node0,st1.getSuccessor(Node1));}@Testpublic void testSuccessor2() {ScapegoatTree st1= new ScapegoatTree();AbstractBinarySearchTree.Node Node00 = new AbstractBinarySearchTree.Node(null,null,null,null);AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(0,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(2,null,null,Node2);Node2.parent=Node1;AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,Node1,null);Node1.parent=Node0;st1.getSuccessor(Node2);/*assertEquals(Node0,st1.getSuccessor(Node2));*/}@Testpublic void testorder() {ScapegoatTree st1= new ScapegoatTree();ScapegoatTree st2= new ScapegoatTree();ScapegoatTree st3= new ScapegoatTree();
AbstractBinarySearchTree.Node Node00 = new AbstractBinarySearchTree.Node(null,null,null,null);AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(1,null,Node0,Node0);//Node2节点只有右子树AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(1,null,null,Node0);//Node3节点只有左子树AbstractBinarySearchTree.Node Node3 = new AbstractBinarySearchTree.Node(1,null,Node0,null);//Node4节点有左子树和右子树但值为nullAbstractBinarySearchTree.Node Node4 = new AbstractBinarySearchTree.Node(null,null,Node0,Node0);//Node5节点有左子树和右子树但值为null且左右子树节点为nullAbstractBinarySearchTree.Node Node5 = new AbstractBinarySearchTree.Node(null,null,Node00,Node00);//Node6节点有左子树和右子树但值为null且左右子树节点为null,右子树节点有右子树与左子树AbstractBinarySearchTree.Node Node6 = new AbstractBinarySearchTree.Node(1,null,Node4,Node4);st1.root=Node4;st1.printTreeInOrder();st1.printTreePostOrder();st1.printTreePreOrder();st2.root=null;st2.printTreePostOrder();st2.printTreePreOrder();st3.root=Node6;st3.printTreePostOrder();st3.printTreePreOrder();}@Testpublic void testtransplant() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {ScapegoatTree st1= new ScapegoatTree();ScapegoatTree st2= new ScapegoatTree();ScapegoatTree st3= new ScapegoatTree();AbstractBinarySearchTree.Node Node00 = new AbstractBinarySearchTree.Node(null,null,null,null);AbstractBinarySearchTree.Node Node0 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node Node1 = new AbstractBinarySearchTree.Node(1,null,Node0,Node0);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return null;}};Class c=AbstractBinarySearchTree.class;Method transplant = c.getDeclaredMethod("transplant", AbstractBinarySearchTree.Node.class, AbstractBinarySearchTree.Node.class);transplant.setAccessible(true);//情况1assertEquals(null,transplant.invoke(a,Node0,null));//情况2assertEquals(Node00,transplant.invoke(a, Node0,Node00));//情况3AbstractBinarySearchTree.Node Node2 = new AbstractBinarySearchTree.Node(2,null,Node0,null);Node0.parent=Node2;assertEquals(Node00,transplant.invoke(a, Node0,Node00));//情况4,参数1有父亲且为它的左孩子AbstractBinarySearchTree.Node Node3 = new AbstractBinarySearchTree.Node(3,null,null,Node0);Node0.parent=Node3;assertEquals(Node00,transplant.invoke(a, Node0,Node00));}@Testpublic void testdelete() {ScapegoatTree st1= new ScapegoatTree();ScapegoatTree st2= new ScapegoatTree();ScapegoatTree st3= new ScapegoatTree();AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return null;}};assertEquals(null,a.delete(null));//情况2		A1无孩子assertEquals(null,a.delete(A1));//情况3  A1只有左孩子A1.left=A2;A2.parent=A1;assertEquals(A2,a.delete(A1));}@Testpublic void testdelete4() {ScapegoatTree st1= new ScapegoatTree();ScapegoatTree st2= new ScapegoatTree();ScapegoatTree st3= new ScapegoatTree();AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return null;}};A1.left=A2;A2.parent=A1;//情况4,A1既有左孩子又有右孩子A1.right=A3;A3.parent=A1;assertEquals(A3,a.delete(A1));}@Testpublic void testdelete5() {ScapegoatTree st1= new ScapegoatTree();ScapegoatTree st2= new ScapegoatTree();ScapegoatTree st3= new ScapegoatTree();AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return null;}};A1.left=A2;A2.parent=A1;A1.right=A3;A3.parent=A1;A3.left=A4;A4.parent=A3;//情况5,A1既有左孩子又有右孩子,且A1的右孩子有一个左孩子assertEquals(A4,a.delete(A1));}@Testpublic void testsearch1() {AbstractBinarySearchTree.Node A150 = new AbstractBinarySearchTree.Node(150,null,null,null);AbstractBinarySearchTree.Node A100 = new AbstractBinarySearchTree.Node(100,A150,null,null);AbstractBinarySearchTree.Node A130 = new AbstractBinarySearchTree.Node(130,A100,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return null;}};A150.left=A100;A100.right=A130;a.root=A150;assertEquals(null,a.search(125));}@Testpublic void testinsert1() {AbstractBinarySearchTree.Node A150 = new AbstractBinarySearchTree.Node(150,null,null,null);AbstractBinarySearchTree.Node A100 = new AbstractBinarySearchTree.Node(100,A150,null,null);AbstractBinarySearchTree.Node A130 = new AbstractBinarySearchTree.Node(130,A100,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return null;}};a.root=null;assertEquals(null,a.insert(125));}@Testpublic void testinsert135() {AbstractBinarySearchTree.Node A150 = new AbstractBinarySearchTree.Node(150,null,null,null);AbstractBinarySearchTree.Node A100 = new AbstractBinarySearchTree.Node(100,A150,null,null);AbstractBinarySearchTree.Node A130 = new AbstractBinarySearchTree.Node(130,A100,null,null);/*AbstractBinarySearchTree.Node A125 = new AbstractBinarySearchTree.Node(125,A130,null,null);*/AbstractBinarySearchTree.Node A135 = new AbstractBinarySearchTree.Node(135,A130,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A150.left=A100;A100.right=A130;a.root=A150;assertEquals(A135, a.insert(135));}@Testpublic void testinsert125() {AbstractBinarySearchTree.Node A150 = new AbstractBinarySearchTree.Node(150,null,null,null);AbstractBinarySearchTree.Node A100 = new AbstractBinarySearchTree.Node(100,A150,null,null);AbstractBinarySearchTree.Node A130 = new AbstractBinarySearchTree.Node(130,A100,null,null);/*AbstractBinarySearchTree.Node A125 = new AbstractBinarySearchTree.Node(125,A130,null,null);*/AbstractBinarySearchTree.Node A125 = new AbstractBinarySearchTree.Node(125,A130,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A150.left=A100;A100.right=A130;a.root=A150;assertEquals(A125, a.insert(125));}@Testpublic void delete1() {AbstractBinarySearchTree.Node A150 = new AbstractBinarySearchTree.Node(150,null,null,null);AbstractBinarySearchTree.Node A100 = new AbstractBinarySearchTree.Node(100,A150,null,null);AbstractBinarySearchTree.Node A130 = new AbstractBinarySearchTree.Node(130,A100,null,null);/*AbstractBinarySearchTree.Node A125 = new AbstractBinarySearchTree.Node(125,A130,null,null);*/AbstractBinarySearchTree.Node A125 = new AbstractBinarySearchTree.Node(125,A130,null,null);AbstractBinarySearchTree a=new AbstractBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A150.left=A100;A100.right=A130;a.root=A150;assertNull(a.delete(125));assertNull(a.delete(130));}@Testpublic void testselfrotateLeft() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A2.right=A3;A3.parent=A2;assertEquals(A3,a.rotateLeft(A2));}@Testpublic void testselfrotateLeft1() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A1.right=A2;A2.parent=A1;A2.right=A3;A3.parent=A2;assertEquals( A3,a.rotateLeft(A2));}@Testpublic void testselfrotateLeft2() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A1.right=A2;A2.parent=A1;A2.right=A3;A3.parent=A2;A4.parent=A3;A3.left=A4;assertEquals(A3,a.rotateLeft(A2));}@Testpublic void testselfrotateLeft3() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A1.right=A2;A1.left=A2;A2.parent=A1;A2.right=A3;A3.parent=A2;A4.parent=A3;A3.left=A4;assertEquals(A3,a.rotateLeft(A2));}@Testpublic void testselfrotateRight() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A2.left=A3;A3.parent=A2;assertEquals(A3,a.rotateRight(A2));}@Testpublic void testselfrotateRight1() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A1.left=A2;A2.parent=A1;A2.left=A3;A3.parent=A2;assertEquals( A3,a.rotateRight(A2));}@Testpublic void testselfrotateRight2() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A1.left=A2;A2.parent=A1;A2.left=A3;A3.parent=A2;A4.parent=A3;A3.right=A4;assertEquals(A3,a.rotateRight(A2));}@Testpublic void testselfrotateRight3() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);AbstractSelfBalancingBinarySearchTree a=new AbstractSelfBalancingBinarySearchTree() {@Overrideprotected Node createNode(int value, Node parent, Node left, Node right) {return new Node(value, parent, left, right);}};A1.right=A2;A1.left=A5;A2.parent=A1;A2.left=A3;A3.parent=A2;A4.parent=A3;A3.right=A4;assertEquals(A3,a.rotateRight(A2));}@Testpublic void testMathUtils1() {MathUtils a=new MathUtils();assertEquals(2,a.getMax(1, 2));assertEquals(2,a.getMax(2, 1));}@Testpublic void testScapegoatgetNodeHeight() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);ScapegoatTree a=new ScapegoatTree();assertEquals(-1,a.getNodeHeight(null));A2.parent=A1;assertEquals(1,a.getNodeHeight(A2));}@Testpublic void testScapegoatgetSubtreeSize() {AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);ScapegoatTree a=new ScapegoatTree();assertEquals(0,a.getSubtreeSize(null));A2.parent=A1;A2.left=A3;assertEquals(1,a.getSubtreeSize(A1));assertEquals(2,a.getSubtreeSize(A2));}@Testpublic void testScapegoatgetSibling() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {AbstractBinarySearchTree.Node A0 = null;AbstractBinarySearchTree.Node A1 = new AbstractBinarySearchTree.Node(1,null,null,null);AbstractBinarySearchTree.Node A2 = new AbstractBinarySearchTree.Node(2,null,null,null);AbstractBinarySearchTree.Node A3 = new AbstractBinarySearchTree.Node(3,null,null,null);AbstractBinarySearchTree.Node A4 = new AbstractBinarySearchTree.Node(4,null,null,null);AbstractBinarySearchTree.Node A5 = new AbstractBinarySearchTree.Node(5,null,null,null);ScapegoatTree a=new ScapegoatTree();assertEquals(0,a.getSubtreeSize(null));A2.parent=A1;A1.left=A2;A3.parent=A1;A1.right=A3;Class c=ScapegoatTree.class;Method su=c.getDeclaredMethod("getSibling", AbstractBinarySearchTree.Node.class);su.setAccessible(true);assertEquals(null,su.invoke(a,A1));assertEquals(A2,su.invoke(a,A3));assertEquals(A3,su.invoke(a,A2));}@Testpublic void testScapegoatinsert() {ScapegoatTree a=new ScapegoatTree();AbstractBinarySearchTree.Node A150 = new AbstractBinarySearchTree.Node(150,null,null,null);a.insert(150);a.insert(100);a.insert(130);a.findScapegoatNode(A150);a.delete(150);a.delete(100);}@Testpublic void testScapegoatinsert1() {ScapegoatTree a=new ScapegoatTree();AbstractBinarySearchTree.Node A150 = new AbstractBinarySearchTree.Node(150,null,null,null);a.insert(100);a.insert(110);a.insert(120);a.insert(130);a.insert(140);a.insert(150);a.insert(160);a.insert(170);a.insert(180);a.insert(0);a.insert(150);a.insert(110);a.insert(110);a.insert(78);}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/132897.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++——string

目录 STL STL六大组件 标准库中的string类 string类 string类常用接口 构造函数 下标遍历[] 迭代器 范围for push_back() append() insert() operator pop_back() erase() reserve resize clear c_str() substr() find() rfind() find_first_of getline str…

腾讯云优惠券种类、领取方法及使用教程分享

腾讯云是国内领先的云计算服务提供商,为用户提供丰富的云计算产品和服务。为了吸引更多用户使用腾讯云的产品和服务,腾讯云会定期推出各种优惠券活动。本文将为大家介绍腾讯云优惠券的种类、领取方法及使用教程。 一、腾讯云优惠券种类介绍 腾讯云优惠券…

STM32 CubeMX ADC采集 单通道,多通道,内部温度(轮询,DMA,中断)(HAL库)

STM32 CubeMX ADC采集(HAL库) STM32 CubeMX STM32 CubeMX ADC采集(HAL库)ADC介绍ADC主要特征Vref的电压(2.4~3.6)就是ADC参考电压2.4V(相当于秤砣) 最小识别电压值:2.4/4…

goland 旧版本使用1.19环境

C:\Go\src\runtime\internal\sys\zversion.go // Code generated by go tool dist; DO NOT EDIT.package sysconst StackGuardMultiplierDefault 1const TheVersion go1.19引入其他包的标识符 package mainimport ("fmt""gotest/test")func main() {f…

Stm32_标准库_8_ADC_光敏传感器_测量具体光照强度

ADC简介 测量方式 采用二分法比较数据 IO通道 ADC基本结构及配置路线 获取数字变量需要用到用到光敏电阻的AO口,AO端口接在PA0引脚即可 测得的模拟数据与实际光照强度之间的关系为 光照强度 100 - 模拟量 / 40;代码: 完整朴素代码: #in…

leetcode-电话号码组合(C CODE)

1. 题目 给定一个仅包含数字 2-9 的字符串,返回所有它能表示的字母组合。答案可以按 任意顺序 返回。 给出数字到字母的映射如下(与电话按键相同)。注意 1 不对应任何字母。 示例 1: 输入:digits “23” 输出&#…

超美!ChatGPT DALL-E 3已可用,另外GPT-4可上传图片进行问答

今天,在ChatGPT里使用DALL-E 3的功能终于上线了。以下是截图: 在GPT-4下加了一个菜单入口,名为 DALL-E 3,这也意味着ChatGPT免费账户暂时不能使用这个功能。 我们体验一下这个功能。 技术交流 建了技术交流群!想要进…

mysql面试题44:MySQL数据库cpu飙升的话,要怎么处理?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:MySQL数据库cpu飙升的话,要怎么处理呢? 当MySQL数据库的CPU使用率飙升时,可能表示数据库负载过重或存在性能问题。以下是处理MySQL数据库CPU飙…

记一次生产大对象及GC时长优化经验

最近在做一次系统整体优化,发现系统存在GC时长过长及JVM内存溢出的问题,记录一下优化的过程 面试的时候我们都被问过如何处理生产问题,尤其是线上oom或者GC调优的问题更是必问,所以到底应该如何发现解决这些问题呢,用真实的场景实操&#xff…

基于Dockerfile搭建LNMP环境

准备工作 #关闭防火墙和防护机制 systemctl stop firewalld systemctl disable firewalld setenforce 0 docker network create --subnet172.18.0.0/16 --opt "com.docker.network.bridge.name""docker1" mynetwork#设置自定义网络模式,模…

【多线程案例】设计模式-单例模式

1.单例模式 什么是单例模式? 所谓单例,即单个实例。通过编码技巧约定某个类只能有唯一一个实例对象,并且提前在类里面创建好一个实例对象,把构造方法私有化,再对外提供获取这个实例对象的方法,&#xff0…

CSS 之 table 表格布局

一、简介 ​ 除了使用HTML的<table>元素外&#xff0c;我们还可以通过display: table/inline-table; 设置元素内部的布局类型为表格布局。并结合table-cell、table-row等相关CSS属性值可以实现HTML中<table>系列元素的效果&#xff0c;具有表头、表尾、行、单元格…