Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please create JUnit testing class for each of the following methods in CityComparator public class CityComparator implements Comparator { public int compare(City x, City y)

Please create JUnit testing class for each of the following methods in CityComparator

public class CityComparator implements Comparator { public int compare(City x, City y) { return x.compare(y,x); } Assume City.java is following: 
public class City { public static HashMap cities = new HashMap(); public String name; public final HashSet links = new HashSet(); public int distance; public Link parent; public City(String nm) { name = nm; cities.put(name, this); } public static City find(String nm) { City p = cities.get(nm); if (p == null) { p = new City(nm); return null; } return p; } public void addLink(Link lnk) { links.add(lnk); } public int compareTo(City p) { return p.name.compareTo(p.name); } public String toString() { return name; } public int compare(City c1, City c2) { return c1.distance - c2.distance; } public boolean getLinksTo(City dest, Set routeLinks) { for (Link l : links) { if (l.isUsed() && (l != parent)) { City child = l.getAdj(this); if ((dest == child) || child.getLinksTo(dest, routeLinks)) { routeLinks.add(l); } } } return false; } }
 }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions