Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package p20190916;
- import junit.framework.TestCase;
- import java.util.TreeSet;
- public class ArmstrongTest extends TestCase {
- public void testKnownArmstrongNumbersBetween0and999() {
- final TreeSet<Integer> armstrongNumbers = new TreeSet<>();
- assertIsArmstrongNumber(armstrongNumbers, 0);
- assertIsArmstrongNumber(armstrongNumbers, 1);
- assertIsArmstrongNumber(armstrongNumbers, 153);
- assertIsArmstrongNumber(armstrongNumbers, 370);
- assertIsArmstrongNumber(armstrongNumbers, 371);
- assertIsArmstrongNumber(armstrongNumbers, 407);
- for (int otherNumber = 0; otherNumber <= 999; ++otherNumber) {
- if (!armstrongNumbers.contains(otherNumber)) {
- assertFalse(otherNumber + " should *NOT* be an Armstrong number", NumberFinder.isArmstrong(otherNumber));
- }
- }
- }
- private static void assertIsArmstrongNumber(TreeSet<Integer> armstrongNumbers, int armstrongNumber) {
- assertTrue(armstrongNumber + " should be Armstrong number", NumberFinder.isArmstrong(armstrongNumber));
- armstrongNumbers.add(armstrongNumber);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement