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

这篇具有很好参考价值的文章主要介绍了2023全国大学生软件测试大赛开发者测试练习题99分答案(ScapegoatTree2023)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。


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

题目详情

2023全国大学生软件测试大赛开发者测试练习题99分答案(ScapegoatTree2023),Java基础,测试,java,单元测试

2023全国大学生软件测试大赛开发者测试练习题99分答案(ScapegoatTree2023),Java基础,测试,java,单元测试文章来源地址https://www.toymoban.com/news/detail-726285.html




题解代码(直接全部复制到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;

	@Test
	public 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);*/
	}
	
	@Test
	public 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);
	}

	@Test
	public 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));
	}
	
	@Test
	public 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节点有左子树和右子树但值为null
		AbstractBinarySearchTree.Node Node4 = new AbstractBinarySearchTree.Node(null,null,Node0,Node0);
		//Node5节点有左子树和右子树但值为null且左右子树节点为null
		AbstractBinarySearchTree.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);
		
	}
	
	@Test
	public 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());
		
	}
	
	@Test
	public 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));
	}
	
	@Test
	public 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));
	}
	
	@Test
	public 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));*/
	}
	
	@Test
	public 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节点有左子树和右子树但值为null
		AbstractBinarySearchTree.Node Node4 = new AbstractBinarySearchTree.Node(null,null,Node0,Node0);
		//Node5节点有左子树和右子树但值为null且左右子树节点为null
		AbstractBinarySearchTree.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();
		
		
	}
	
	@Test
	public 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() {
            @Override
            protected 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);
        
        //情况1
        assertEquals(null,transplant.invoke(a,Node0,null));
        
        //情况2
        assertEquals(Node00,transplant.invoke(a, Node0,Node00));
        
        //情况3
        AbstractBinarySearchTree.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));
        
        
	}
	
	@Test
	public 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() {
            @Override
            protected 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));
       
        
	}
	@Test
	public 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() {
            @Override
            protected 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));
        
        
	}
	@Test
	public 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() {
            @Override
            protected 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));
            
	}
	
	@Test
	public 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() {
            @Override
            protected 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));
	}
	
	@Test
	public 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() {
            @Override
            protected Node createNode(int value, Node parent, Node left, Node right) {
                return null;
            }
        };
        a.root=null;
        assertEquals(null,a.insert(125));
	}
	@Test
	public 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() {
            @Override
            protected 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));
	}
	@Test
	public 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() {
            @Override
            protected 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));
	}
	
	@Test
	public 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() {
            @Override
            protected 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));
	}
	
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	
	@Test
	public 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() {
        	@Override
            protected 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));
	}
	
	@Test
	public void testMathUtils1() {
		MathUtils a=new MathUtils();
		assertEquals(2,a.getMax(1, 2));
		assertEquals(2,a.getMax(2, 1));
	}
	
	@Test
	public 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));
	}
	@Test
	public 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));
	}
	@Test
	public 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));
	}
	
	@Test
	public 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);
	}
	@Test
	public 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);
	}
}

到了这里,关于2023全国大学生软件测试大赛开发者测试练习题99分答案(ScapegoatTree2023)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 2023全国大学生数学建模竞赛C题思路+模型+代码+论文

    目录 一.思路模型见文末名片,比赛开始第一时间更新 二.国赛常用算法之主成分分析法(PCA) 三.MATLAB代码 代码相对简单,是从司守奎大神的《数学建模算法与应用》一书中学习到的,笔者只不过添加了一点注释,拾人牙慧,惭愧惭愧。将代码文件和txt文件放在一个文件夹中就

    2024年02月09日
    浏览(105)
  • 2023年高教社杯全国大学生数学建模竞赛参赛事项注意

    一年一度的数学建模国赛要来啦!!!小编仔细阅读了比赛官方网站上的规则和要求,以及比赛的题型和时间安排,现总结分享给大家。 小编将会在开赛后第一时间发布选题建议、所有题目的思路解析、相关代码、参考文献、参考成品论文等多项资料,帮助大家取得好成绩哦

    2024年02月09日
    浏览(100)
  • 2023年度第四届全国大学生算法设计与编程挑战赛(春季赛)

     A 题目描述        有一个长为 n (1le n le 1000)n (1≤n≤1000) 的序列,序列上的元素两两不同。你需要用最少的操作步数翻转这个序列。        每次操作你需要给出三个数 i,j,k(1le ile j k le n)i,j,k(1≤i≤jk≤n),交换序列中下标属于 [i,j][i,j] 的元素与下标属于 [j+1,k][j+

    2024年02月08日
    浏览(138)
  • 2023高教社杯全国大学生数学建模竞赛B题代码解析

    2023高教社杯全国大学生数学建模竞赛B题 多波束测线问题 代码解析 因为一些不可抗力,下面仅展示部分matlab代码(第一问的部分),其余代码看文末 节选了部分: 有关思路、相关代码、讲解视频、参考文献等相关内容可以点击下方群名片哦!

    2024年02月09日
    浏览(59)
  • 【电子设计大赛】2023 年全国大学生电子设计竞赛 仪器和主要元器件清单

    1. 仪器设备清单 直流稳压电源(具有恒流/恒压模式自动切换功能,0~30V/3A,双路) 数字示波器(100MHz, 双通道) 函数发生器(50 MHz,双通道) 射频信号源(500MHz,-100dBm~0dBm,具有射频输出开关功能) 矢量网络分析仪(1GHz) 频谱分析仪(1GHz) 频率计(500MHz) 功率分析仪

    2024年02月15日
    浏览(101)
  • 2023全国大学生数学建模竞赛E题详解+Python代码源码(三)SARIMA模型

    简单介绍一下我自己:博主专注建模四年,参与过大大小小数十来次数学建模,理解各类模型原理以及每种模型的建模流程和各类题目分析方法。参与过十余次数学建模大赛,三次美赛获得过二次M奖一次H奖,国赛二等奖。 希望各位以后遇到建模比赛可以艾特一下我,我可以

    2024年02月09日
    浏览(54)
  • 2023全国大学生数学建模ABCDE选题建议,思路模型,小白要怎么选?难度怎么样

    大家可以查看我们的视频讲解,在这里: 【2023全国大学生数学建模竞赛选题建议,难度分析,小白应该怎么选】 https://b23.tv/S6O26uc 选题建议视频播放​b23.tv/S6O26uc https://link.zhihu.com/?target=https%3A//b23.tv/S6O26uc A题:定日镜场的优化设计 A题是数模类赛事很常见的物理类赛题,需

    2024年02月09日
    浏览(49)
  • 2019年全国大学生电子设计大学(D 题)简易电路特性测试仪(2)基础部分电路与代码

    先看基础部分第一问,首先经过测试,我的共射放大电路的放大倍数是280左右(分立元件每个人都不一样),选择放大倍数越小的三极管越好做(1)中有作解释。 输入电阻 DDS输出的正弦波幅值为1.1v,经过分压后,串联一个电阻,根据公式计算即可得出。电路图如下:    

    2024年02月14日
    浏览(55)
  • 2023 年高教社杯全国大学生数学建模竞赛题目 B 题 多波束测线问题

    单波束测深是利用声波在水中的传播特性来测量水体深度的技术。声波在均匀介质中作匀速直线传播,在不同界面上产生反射,利用这一原理,从测量船换能器垂直向海底发射声波信号,并记录从声波发射到信号接收的传播时间,通过声波在海水中的传播速度和传播时间计算

    2024年02月09日
    浏览(65)
  • 2023年高教社杯全国大学生数学建模竞赛-【比赛规则篇】比赛规则及比赛指导

    目录 前言 前辈分享的国赛获奖经验  多看历年的竞赛题 集训时长 模拟题量

    2024年02月07日
    浏览(46)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包