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

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

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


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

题目详情

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

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




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

你可能感兴趣的:(Java基础,测试,java,单元测试)