2023全国大学生软件测试大赛开发者测试练习题99分答案(ScapegoatTree2023)
提示:该题只需要分支覆盖得分即可,不需要变异得分
题目详情
题解代码(直接全部复制到test类中即可)
java
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);
}
}