Advertisement
JeffGrigg

StrongTest

Sep 16th, 2019
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.02 KB | None | 0 0
  1. package p20190916;
  2.  
  3. import junit.framework.TestCase;
  4.  
  5. import java.util.TreeSet;
  6.  
  7. public class StrongTest extends TestCase {
  8.  
  9.     public void testKnownStrongNumbersBetween0and999() {
  10.         final TreeSet<Integer> strongNumbers = new TreeSet<>();
  11.         assertIsStrongNumber(strongNumbers, 0);
  12.         assertIsStrongNumber(strongNumbers, 1);
  13.         assertIsStrongNumber(strongNumbers, 2);
  14.         assertIsStrongNumber(strongNumbers, 145);
  15.         assertIsStrongNumber(strongNumbers, 40585);
  16.  
  17.         for (int otherNumber = 0; otherNumber <= 99999; ++otherNumber) {
  18.             if (!strongNumbers.contains(otherNumber)) {
  19.                 assertFalse(otherNumber + " should *NOT* be an Strong number", NumberFinder.isStrong(otherNumber));
  20.             }
  21.         }
  22.     }
  23.  
  24.     private static void assertIsStrongNumber(TreeSet<Integer> strongNumbers, int strongNumber) {
  25.         assertTrue(strongNumber + " should be Strong number", NumberFinder.isStrong(strongNumber));
  26.         strongNumbers.add(strongNumber);
  27.     }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement