Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need to pass all tests in this Tester.cs:using System; using System.Collections.Generic; namespace _ 8 . _ 1 C _ Heaps { class Tester {
I need to pass all tests in this Tester.cs:using System;
using System.Collections.Generic;
namespace CHeaps
class Tester
private class IntAscendingComparer : IComparer
public int Compareint A int B
return Math.SignA B;
private class IntDescendingComparer : IComparer
public int Compareint A int B
return Math.SignA B;
static void Mainstring args
test instance begin
string names new string "Kelly", "Cindy", "John", "Andrew", "Richard", "Michael", "Guy", "Elicia", "Tom", "Iman", "Simon", "Vicky", "Kevin", "David" ;
int IDs new int;
int certificateAdd new int;
int certificateDelete new int;
int certificateMinHeapBuild new int;
int certificateMaxHeapBuild new int;
test instance end
Heap minHeap null;
Heap maxHeap null;
IHeapifyable nodes null;
string result ;
test
try
Console.WriteLine
Test A: Create a minheap by calling 'minHeap new Heapnew IntAscendingComparer;;
minHeap new Heapnew IntAscendingComparer;
Console.WriteLine :: SUCCESS: minheap's state minHeap.ToString;
result result A;
catch Exception exception
try Console.WriteLine :: FAIL: minheap's state minHeap.ToString; catch ;
Console.WriteLineexceptionToString;
result result ;
test
try
Console.WriteLine
Test B: Run a sequence of operations: ;
for int i ; i Math.MinnamesLength, IDs.Length; i
Console.WriteLine
Insert a node with name data and ID key namesi IDsi;
IHeapifyable node minHeap.InsertIDsi namesi;
if nodePosition certificateAddi && minHeap.Count i throw new ExceptionThe minheap has a wrong structure";
Console.WriteLine :: SUCCESS: minheap's state minHeap.ToString;
result result B;
catch Exception exception
try Console.WriteLine :: FAIL: minheap's state minHeap.ToString; catch ;
Console.WriteLineexceptionToString;
result result ;
test
try
Console.WriteLine
Test C: Run a sequence of operations: ;
for int i ; i certificateDelete.Length; i
Console.WriteLine
Delete the minimum element from the minheap.";
IHeapifyable node minHeap.Delete;
if nodeKey certificateDeletei throw new ExceptionThe extracted node has a wrong key";
if minHeapCount certificateDelete.Length i throw new ExceptionThe heap has a wrong number of elements";
if certificateDeleteLength i
if minHeapMinKey certificateDeletei && minHeapMinPosition throw new ExceptionThe minheap has a wrong structure";
Console.WriteLine :: SUCCESS: minheap's state minHeap.ToString;
result result C;
catch Exception exception
try Console.WriteLine :: FAIL: minheap's state minHeap.ToString; catch ;
Console.WriteLineexceptionToString;
result result ;
test
try
Console.WriteLine
Test D: Delete the minimum element from the minheap.";
IHeapifyable node minHeap.Delete;
Console.WriteLineLast operation is invalid and must throw
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started