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


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


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

    题目详情

    在这里插入图片描述
    在这里插入图片描述




    题解代码(直接全部复制到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 {
    
    
        @Test
        public void test() {
            Heap_Item<String> heap_Item0 = new Heap_Item<String>(",");
            Heap_Item<String> heap_Item1 = new Heap_Item<String>(",");
            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());
        }
    
        @Test
        public void test1() {
            Heap_Item<String> heap_Item0 = new Heap_Item<String>(",");
            Heap_Item<String> heap_Item1 = new Heap_Item<String>(",");
            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());
        }
    
        @Test
        public void test2() {
            Heap_Item<String> heap_Itema=new Heap_Item<String>("a");
            Heap_Item<String> heap_Itemb=new Heap_Item<String>("b");
            Heap_Item<String> heap_Itemc=new Heap_Item<String>("c");
            Heap_Item<String> heap_Itemd=new Heap_Item<String>("d");
            Heap_Item<String> heap_Iteme=new Heap_Item<String>("e");
            Heap_Item<String> heap_Itemk=new Heap_Item<String>("k");
            Heap_Item<String> heap_Itemp=new Heap_Item<String>("p");
            Heap_Item<String> heap_Itemq=new Heap_Item<String>("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的祖先为a
            heap_Itemc.setAncestor(heap_Itema);
    
            //节点a无祖先,于是返回null
            Heap_Item <String> heap_Itemanull=heap_Itema.getMultiWayAncestor();
            assertNull(heap_Itemanull);
    
            //节点b有祖先a,同时又是它的左孩子,于是返回他的祖先a
            Heap_Item <String> heap_Itembnull=heap_Itemb.getMultiWayAncestor();
            assertNotNull(heap_Itembnull);
            assertSame(heap_Itema,heap_Itembnull);
    
    
    
    
    
        }
    
        @Test
        public void testMul() {
            Heap_Item<String> heap_Itema=new Heap_Item<String>("a");
            Heap_Item<String> heap_Itemb=new Heap_Item<String>("b");
            Heap_Item<String> heap_Itemc=new Heap_Item<String>("c");
            Heap_Item<String> heap_Itemd=new Heap_Item<String>("d");
            Heap_Item<String> heap_Iteme=new Heap_Item<String>("e");
            Heap_Item<String> heap_Itemk=new Heap_Item<String>("k");
            Heap_Item<String> heap_Itemp=new Heap_Item<String>("p");
            Heap_Item<String> heap_Itemq=new Heap_Item<String>("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的祖先为a
            heap_Itemc.setAncestor(heap_Itema);
    
            //节点a无祖先,于是返回null
            Heap_Item <String> heap_Itemanull=heap_Itema.getMultiWayAncestor();
            assertNull(heap_Itemanull);
    
            //节点b有祖先a,同时又是它的左孩子,于是返回他的祖先a
            Heap_Item <String> heap_Itembnull=heap_Itemb.getMultiWayAncestor();
            assertNotNull(heap_Itembnull);
            assertSame(heap_Itema,heap_Itembnull);
    
    
            //先给a设置右祖先
            Heap_Item <String> heap_Items1 = new Heap_Item<String>("s1");
            heap_Itema.setAncestor(heap_Items1);
            heap_Items1.setLeftSon(heap_Itema);
    
            //检查a的祖先是否为s1
            assertSame(heap_Items1,heap_Itema.getAncestor());
    
            //检查c的祖先是否为a
            assertSame(heap_Itema,heap_Itemc.getAncestor());
    
            //给s1复制左孩子为s2
            Heap_Item <String> heap_Items2 = new Heap_Item<String>("s2");
            heap_Items2.setAncestor(heap_Items1);
            heap_Items1.setRightSon(heap_Items2);
            //节点c有祖先a,但是a的右孩子,于是返回a的最近的以a作为左子孙的祖先,即s1
    
    
            Heap_Item <String> heap_Itemcnull=heap_Itemc.getMultiWayAncestor();
            assertSame(heap_Itemcnull,heap_Items1);
    
    
        }
    
        @Test
        public void testpair() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException{
            Class<Pairing_Heap> c = Pairing_Heap.class;
            Heap_Item<String>  a1=new Heap_Item<>("a1");
            Heap_Item<String> a2=new Heap_Item<>("a2");
            Heap_Item<String> b1=new Heap_Item<>("b1");
            a1.setLeftSon(b1);
            b1.setAncestor(a1);
    
            Pairing_Heap<String> p1=new Pairing_Heap<>(a1);
            Pairing_Heap<String> p2=new Pairing_Heap<>(a2);
    
            Method pair = c.getDeclaredMethod("pair", Pairing_Heap.class, Pairing_Heap.class);
            pair.setAccessible(true);
    
    
            //情况3
            Pairing_Heap<String> k=new Pairing_Heap<>();
            Object invoke = pair.invoke(k, p1, p2);
    
            //情况1
            Pairing_Heap<String> null1=new Pairing_Heap<>();
            Object invoke1= pair.invoke(k, null1,p2);
    
    
            //情况2
            pair.invoke(k, p1,null1);
    
            //情况4
            Heap_Item<String>  d1=new Heap_Item<>("d1");
            Heap_Item<String> d2=new Heap_Item<>("d2");
    
            Pairing_Heap<String> pd1=new Pairing_Heap<>(d1);
            Pairing_Heap<String> pd2=new Pairing_Heap<>(d2);
            pair.invoke(k, pd1,pd2);
    
            //情况5
            Heap_Item<String>  e1=new Heap_Item<>("e1");
            Heap_Item<String> e2=new Heap_Item<>("e2");
            Heap_Item<String> be1=new Heap_Item<>("be1");
            e1.setLeftSon(be1);
            be1.setAncestor(e1);
    
            Pairing_Heap<String> pe1=new Pairing_Heap<>(e2);
            Pairing_Heap<String> pe2=new Pairing_Heap<>(e1);
    
            pair.invoke(k, pe1,pe2);
    
            //情况6
            Heap_Item<String>  f1=new Heap_Item<>("e1");
            Heap_Item<String> f2=new Heap_Item<>("e2");
    
            Pairing_Heap<String> pf1=new Pairing_Heap<>(f2);
            Pairing_Heap<String> pf2=new Pairing_Heap<>(f1);
    
            pair.invoke(k, pf1,pf2);
        }
    
        @Test
        public void testpop_heap_item() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
            Class<Pairing_Heap> fun = Pairing_Heap.class;
            //情况1
            Pairing_Heap<String> null1=new Pairing_Heap<>();
            Method pair =fun.getDeclaredMethod("pop_heap_item");
            pair.setAccessible(true);
    
            pair.invoke(null1);
    
            //情况2
            Heap_Item<String> b=new Heap_Item<>("b");
            Pairing_Heap<String> pb=new Pairing_Heap<>(b);
    
            pair.invoke(pb);
    
            //情况3
            Heap_Item<String> c=new Heap_Item<>("c");
            Heap_Item<String> cb=new Heap_Item<>("cb");
            c.setLeftSon(cb);
            cb.setAncestor(c);
            Pairing_Heap<String> pc=new Pairing_Heap<>(c);
            pair.invoke(pc);
    
            //情况四
            Heap_Item<String> d=new Heap_Item<>("d");
            Heap_Item<String> db=new Heap_Item<>("db");
            Heap_Item<String> dbc=new Heap_Item<>("dbc");
            Heap_Item<String> dbc0=new Heap_Item<>("dbc0");
            d.setLeftSon(db);
            db.setAncestor(d);
            db.setRightSon(dbc);
            db.setLeftSon(dbc0);
            dbc0.setAncestor(db);
            dbc.setAncestor(dbc);
    
            Pairing_Heap<String> pd=new Pairing_Heap<>(d);
            pair.invoke(pd);
    
    
        }
    
        @Test
        public void testpush() {
    
    
            //根为空的情况
    
            Pairing_Heap<String> null1=new Pairing_Heap<>();
            Heap_Item<String> d=new Heap_Item<>("d");
            null1.push(d);
    
    
            //根不为空的情况
            Heap_Item<String> c=new Heap_Item<>("c");
            Pairing_Heap<String> pc=new Pairing_Heap<>(c);
            Heap_Item k=pc.push(d);
    
    
        }
    
        @Test
        public void testcheckPriority1_2() {
            //情况1,2
            Heap_Item<String> a=new Heap_Item<>("a");
            Heap_Item<String> b=new Heap_Item<>("b");
            Heap_Item<String> c=new Heap_Item<>("c");
            Heap_Item<String> k=new Heap_Item<>("k");
    
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
            c.setLeftSon(a);
            a.setAncestor(c);
            a.setRightSon(b);
            b.setAncestor(a);
            b.setRightSon(k);
            k.setAncestor(b);
            p.checkPriority(b);
        }
    
        @Test
        public void testcheckPriority3() {
    
            //情况3
            Heap_Item<String> k=new Heap_Item<>("k");
            Heap_Item<String> b1=new Heap_Item<>("b1");
            Heap_Item<String> b2=new Heap_Item<>("b2");
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
            k.setLeftSon(b1);
            k.setRightSon(b2);
            b1.setAncestor(k);
            b2.setAncestor(k);
            p.checkPriority(k);
        }
    
        @Test
        public void testcheckPriority4() {
            //情况4
            Heap_Item<String> a=new Heap_Item<>("a");
            Heap_Item<String> k=new Heap_Item<>("k");
            Heap_Item<String> b1=new Heap_Item<>("b1");
            Heap_Item<String> b2=new Heap_Item<>("b2");
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
            a.setLeftSon(k);
            k.setAncestor(a);
            k.setLeftSon(b1);
            k.setRightSon(b2);
            b1.setAncestor(k);
            b2.setAncestor(k);
            p.checkPriority(k);
        }
    
        @Test
        public void testcheckPriority5() {
            //情况5
    
            Heap_Item<String> k=new Heap_Item<>("k");
            Heap_Item<String> z=new Heap_Item<>("z");
            k.setLeftSon(z);
            z.setAncestor(k);
    
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
    
            p.checkPriority(k);
        }
        
        @Test
        public void testcheckPriority6() {
            //情况6
    
            Heap_Item<String> k=new Heap_Item<>("k");
            Heap_Item<String> z=new Heap_Item<>("z");
            z.setLeftSon(k);
            k.setAncestor(z);
    
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
    
            p.checkPriority(k);
        }
        
        @Test
        public void testcheckPriority7() {
            //情况7
        	Heap_Item<String> k=new Heap_Item<>("k");
            Heap_Item<String> z=new Heap_Item<>("z");
            k.setLeftSon(z);
            z.setAncestor(k);
    
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
    
            p.checkPriority(z);
            
        }
        
        @Test
        public void testcheckPriority8() {
            //情况8
        	Heap_Item<String> a=new Heap_Item<>("a");
            Heap_Item<String> z=new Heap_Item<>("z");
            Heap_Item<String> b=new Heap_Item<>("b");
            a.setLeftSon(z);
            z.setAncestor(a);
            z.setLeftSon(b);
            b.setAncestor(z);
    
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
    
            p.checkPriority(z);
            
        }
        
        @Test
        public void testcheckPriority9() {
            //情况9
        	Heap_Item<String> a=new Heap_Item<>("a");
            Heap_Item<String> b=new Heap_Item<>("b");
            Heap_Item<String> c=new Heap_Item<>("c");
            Heap_Item<String> d=new Heap_Item<>("d");
            a.setLeftSon(b);
            b.setAncestor(a);
            b.setLeftSon(c);
            c.setAncestor(b);
            c.setRightSon(d);
            d.setAncestor(c);
    
            Pairing_Heap<String> p=new Pairing_Heap<>();
    
    
            p.checkPriority(b);
            
        }
        
        @Test
        public void testgetData() {
        	Heap_Item<String> null2=new Heap_Item<>();
        	null2.getData();
        	
        }
        @Test
        public void testgetSonByData() {
        	Heap_Item<String> k=new Heap_Item<>("k");
            Heap_Item<String> z=new Heap_Item<>("z");
            Heap_Item<String> z2=new Heap_Item<>("z2");
            Heap_Item<String> z1=new Heap_Item<>("z1");
            k.setLeftSon(z);
            k.setRightSon(z2);
            z2.setAncestor(k);
            z.setAncestor(k);
            k.removeChild("z1");
        }
        
        @Test
        public void testgetSonByData1() {
        	Heap_Item<String> k=new Heap_Item<>("k");
        	k.getSonByData(null);
        	Heap_Item<String> z2=new Heap_Item<>("z2");
        	k.setRightSon(z2);
            z2.setAncestor(k);
            k.getSonByData("z2");
        }
        
        
        @Test
        public void testreplaceChild1() {
        	Heap_Item<String> k=new Heap_Item<>("k");
        	Heap_Item<String> z2=new Heap_Item<>("z2");
        	k.setRightSon(z2);
            z2.setAncestor(k);
            k.replaceChild("z1", z2);
        }
        
        @Test
        public void testgetMultiWayAncestor2() {
        	Heap_Item<String> k=new Heap_Item<>("k");
        	Heap_Item<String> c=new Heap_Item<>("c");
        	Heap_Item<String> a=new Heap_Item<>("a");
        	Heap_Item<String> b=new Heap_Item<>("b");
        	c.setLeftSon(k);
        	k.setAncestor(c);
        	k.setRightSon(a);
        	a.setAncestor(k);
        	a.setRightSon(b);
        	b.setAncestor(a);
        	b.getMultiWayAncestor();
        }
        
        @Test
        public void testpop() {
        	Heap_Item<String> k=new Heap_Item<>("k");
            Heap_Item<String> z=new Heap_Item<>("z");
            k.setLeftSon(z);
            z.setAncestor(k);
    
            Pairing_Heap<String> p=new Pairing_Heap<>();
            Pairing_Heap<String> p1=new Pairing_Heap<>(k);
    
    
            p.pop();
            p1.pop();
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
  • 相关阅读:
    机器学习模型常用评价指标(Accuracy, Precision, Recall、F1-score、MSE、RMSE、MAE、R方)
    我这个代码可以通过深度优先搜索实现逆拓扑排序时检测出有回路的存在吗
    Go 语言使用 XORM 操作 MySQL 的陷阱
    java毕业设计网上商城系统源码+lw文档+mybatis+系统+mysql数据库+调试
    蓝牙耳机什么牌子音质最好?高音质蓝牙耳机盘点
    无人驾驶技术有什么优点,人工驾驶的优缺点英文
    国庆作业1
    【TA-霜狼_may-《百人计划》】图形3.7.2 command buffer简
    langchain中的LLM模型使用介绍
    【考研高数 武忠祥+880版 自用】高数第三章基础阶段思维导图
  • 原文地址:https://blog.csdn.net/haobabiu/article/details/133779673