diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java index d32ffb01b9..51f0e3fa6a 100644 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java @@ -15,7 +15,7 @@ public class GreedyAlgorithm { this.fp = new FollowersPath(); } - public long findMostFollowersPath(String account) throws Exception { + public long findMostFollowersPath(String account) { long max = 0; SocialUser toFollow = null; @@ -31,12 +31,8 @@ public class GreedyAlgorithm { if (currentLevel < maxLevel - 1) { currentLevel++; max += findMostFollowersPath(toFollow.getUsername()); - //fp.addFollower(toFollow.getUsername(), max); - //fp.addCount(max); return max; } else { - //fp.addFollower(toFollow.getUsername(), max); - //fp.addCount(max); return max; } } diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java index cb3d69a18e..af274a385e 100644 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java @@ -13,9 +13,8 @@ public class NonGreedyAlgorithm { this.tc = tc; this.currentLevel = level; } - - - public long findMostFollowersPath(String account) throws Exception { + + public long findMostFollowersPath(String account) { List followers = tc.getFollowers(account); long total = currentLevel > 0 ? followers.size() : 0; diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java index b8bbbdcfff..508e18c105 100644 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java @@ -20,9 +20,9 @@ public class SocialConnector { return this.isCounterEnabled; } - public List getFollowers(String account) throws Exception { + public List getFollowers(String account) { if (counter < 0) - throw new Exception ("API limit reached"); + throw new IllegalStateException ("API limit reached"); else { if(this.isCounterEnabled) counter--; for(SocialUser user : users) { diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java index 173e3f8de5..a503b006de 100644 --- a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java @@ -35,21 +35,21 @@ public class GreedyAlgorithmUnitTest { } @Test - public void greedyAlgorithmTest() throws Exception { + public void greedyAlgorithmTest() { GreedyAlgorithm ga = new GreedyAlgorithm(prepareNetwork()); assertEquals(ga.findMostFollowersPath("root"), 5); } @Test - public void nongreedyAlgorithmTest() throws Exception { + public void nongreedyAlgorithmTest() { NonGreedyAlgorithm nga = new NonGreedyAlgorithm(prepareNetwork(), 0); - Assertions.assertThrows(Exception.class, () -> { + Assertions.assertThrows(IllegalStateException.class, () -> { nga.findMostFollowersPath("root"); }); } @Test - public void nongreedyAlgorithmUnboundedTest() throws Exception { + public void nongreedyAlgorithmUnboundedTest() { SocialConnector sc = prepareNetwork(); sc.switchCounter(); NonGreedyAlgorithm nga = new NonGreedyAlgorithm(sc, 0);