|
| 1 | +# pylint: disable=C0301 |
| 2 | +""" |
| 3 | +Armstrong Numbers Test Suite Documentation |
| 4 | +
|
| 5 | +## Overview |
| 6 | +
|
| 7 | +This test suite validates the `is_armstrong_number` function, |
| 8 | +ensuring its correct behavior for various types of numbers: |
| 9 | +
|
| 10 | +- Single-digit and multi-digit numbers |
| 11 | +- Known Armstrong numbers and non-Armstrong numbers |
| 12 | +
|
| 13 | +Tests are auto-generated based on canonical data from |
| 14 | +[Exercism problem specifications](https://github.com/exercism/problem-specifications/tree/main/exercises/armstrong-numbers/canonical-data.json). |
| 15 | +
|
| 16 | +## Structure |
| 17 | +
|
| 18 | +- **Framework:** Uses Python's built-in `unittest`. |
| 19 | +- **Target Function:** `is_armstrong_number` (imported from `armstrong_numbers` module). |
| 20 | +
|
| 21 | +## Test Cases |
| 22 | +
|
| 23 | +| Test Description | Input | Expected Output | |
| 24 | +|---------------------------------------------------------|----------|-----------------| |
| 25 | +| Zero is an Armstrong number | 0 | `True` | |
| 26 | +| Single-digit numbers are Armstrong numbers | 5 | `True` | |
| 27 | +| No two-digit numbers (e.g. 10) are Armstrong numbers | 10 | `False` | |
| 28 | +| 153 is an Armstrong number | 153 | `True` | |
| 29 | +| 100 is not an Armstrong number | 100 | `False` | |
| 30 | +| 9474 is an Armstrong number | 9474 | `True` | |
| 31 | +| 9475 is not an Armstrong number | 9475 | `False` | |
| 32 | +| 9926315 is an Armstrong number | 9926315 | `True` | |
| 33 | +| 9926314 is not an Armstrong number | 9926314 | `False` | |
| 34 | +
|
| 35 | +## Usage |
| 36 | +
|
| 37 | +To run the tests, ensure `is_armstrong_number` is implemented and run: |
| 38 | +
|
| 39 | +```bash |
| 40 | +python -m unittest armstrong_numbers_test.py |
| 41 | +
|
| 42 | +""" |
| 43 | + |
1 | 44 | # These tests are auto-generated with test data from: |
2 | 45 | # https://github.com/exercism/problem-specifications/tree/main/exercises/armstrong-numbers/canonical-data.json |
3 | 46 | # File last updated on 2023-07-20 |
|
10 | 53 |
|
11 | 54 |
|
12 | 55 | class ArmstrongNumbersTest(unittest.TestCase): |
| 56 | + """Armstrong Numbers Test.""" |
| 57 | + |
13 | 58 | def test_zero_is_an_armstrong_number(self): |
| 59 | + """ |
| 60 | + Test that zero is correctly identified as an Armstrong number. |
| 61 | +
|
| 62 | + This test verifies that the function correctly determines that 0 |
| 63 | + is an Armstrong number, as 0^1 == 0. |
| 64 | +
|
| 65 | + :returns: None |
| 66 | + :rtype: NoneType |
| 67 | + """ |
14 | 68 | self.assertIs(is_armstrong_number(0), True) |
15 | 69 |
|
16 | 70 | def test_single_digit_numbers_are_armstrong_numbers(self): |
| 71 | + """ |
| 72 | + Test that all single digit numbers are Armstrong numbers. |
| 73 | +
|
| 74 | + :returns: None. Asserts that a single digit number (e.g., 5) is an Armstrong number. |
| 75 | + :rtype: NoneType |
| 76 | + """ |
17 | 77 | self.assertIs(is_armstrong_number(5), True) |
18 | 78 |
|
19 | 79 | def test_there_are_no_two_digit_armstrong_numbers(self): |
| 80 | + """ |
| 81 | + Test that no two-digit numbers are Armstrong numbers. |
| 82 | +
|
| 83 | + :returns: None. Asserts that a two-digit number (e.g., 10) is not an Armstrong number. |
| 84 | + :rtype: NoneType |
| 85 | + """ |
20 | 86 | self.assertIs(is_armstrong_number(10), False) |
21 | 87 |
|
22 | 88 | def test_three_digit_number_that_is_an_armstrong_number(self): |
| 89 | + """ |
| 90 | + Test that 153 is correctly identified as an Armstrong number. |
| 91 | +
|
| 92 | + :returns: None. Asserts that 153 is an Armstrong number. |
| 93 | + :rtype: NoneType |
| 94 | + """ |
23 | 95 | self.assertIs(is_armstrong_number(153), True) |
24 | 96 |
|
25 | 97 | def test_three_digit_number_that_is_not_an_armstrong_number(self): |
| 98 | + """ |
| 99 | + Test that 100 is not identified as an Armstrong number. |
| 100 | +
|
| 101 | + :returns: None. Asserts that 100 is not an Armstrong number. |
| 102 | + :rtype: NoneType |
| 103 | + """ |
26 | 104 | self.assertIs(is_armstrong_number(100), False) |
27 | 105 |
|
28 | 106 | def test_four_digit_number_that_is_an_armstrong_number(self): |
| 107 | + """ |
| 108 | + Test that 9474 is correctly identified as an Armstrong number. |
| 109 | +
|
| 110 | + :returns: None. Asserts that 9474 is an Armstrong number. |
| 111 | + :rtype: NoneType |
| 112 | + """ |
29 | 113 | self.assertIs(is_armstrong_number(9474), True) |
30 | 114 |
|
31 | 115 | def test_four_digit_number_that_is_not_an_armstrong_number(self): |
| 116 | + """ |
| 117 | + Test that 9475 is not identified as an Armstrong number. |
| 118 | +
|
| 119 | + :returns: None. Asserts that 9475 is not an Armstrong number. |
| 120 | + :rtype: NoneType |
| 121 | + """ |
32 | 122 | self.assertIs(is_armstrong_number(9475), False) |
33 | 123 |
|
34 | 124 | def test_seven_digit_number_that_is_an_armstrong_number(self): |
| 125 | + """ |
| 126 | + Test that 9926315 is correctly identified as an Armstrong number. |
| 127 | +
|
| 128 | + :returns: None. Asserts that 9926315 is an Armstrong number. |
| 129 | + :rtype: NoneType |
| 130 | + """ |
35 | 131 | self.assertIs(is_armstrong_number(9926315), True) |
36 | 132 |
|
37 | 133 | def test_seven_digit_number_that_is_not_an_armstrong_number(self): |
| 134 | + """ |
| 135 | + Test that 9926314 is not identified as an Armstrong number. |
| 136 | +
|
| 137 | + :returns: None. Asserts that 9926314 is not an Armstrong number. |
| 138 | + :rtype: NoneType |
| 139 | + """ |
38 | 140 | self.assertIs(is_armstrong_number(9926314), False) |
0 commit comments