Question: Please create JUnit Testing Classes for each of the methods in Link.java public class Link implements Comparable { public City city1; public City city2; public
Please create JUnit Testing Classes for each of the methods in Link.java
public class Link implements Comparable { public City city1; public City city2; public int length; public boolean used = false; public Link(City c1, City c2, int len) { if (c1.compareTo(c2) < 0) { city1 = c1; city2 = c2; } else { city1 = c2; city2 = c1; } length = len; c1.addLink(this); c2.addLink(this); used = true; } public int getLength() { return length; } public City getAdj(City c) { return c == city1 ? city2 : city1; } public boolean isUsed() { return used; } public void setUsed(boolean u) { used = u; } public String toString() { return city1.toString() + " " + city2.toString(); } public int compareTo(Link l) { int diff = city1.compareTo(l.city1); if (diff == 0) { diff = city1.compareTo(l.city1); } return diff; } } 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
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
