def test_smallest_factor():
    """test finding smallest prime factor of a number"""
    assert specs.smallest_factor(1) == 1, "Failed on n=1"
    assert specs.smallest_factor(2) == 2, "Failed on n=2"
    assert specs.smallest_factor(3) == 3, "Failed on n=3"
    assert specs.smallest_factor(4) == 2, "Failed on smallest square"
    assert specs.smallest_factor(10) == 2, "Failed on even number"
    assert specs.smallest_factor(
        81
    ) == 3, "Failed on non-prime square"  #tests square where root isn't prime
    assert specs.smallest_factor(49) == 7, "Failed on prime square"
    assert specs.smallest_factor(23) == 23, "Failed on large prime"
    assert specs.smallest_factor(63) == 3, "Failed on odd"
    assert specs.smallest_factor(323) == 17, "Failed on close primes"
Exemple #2
0
def test_smallest_factor():
    """
    cases:
        n = 15, return 3                            a composite number
        n = 23, return 23 (since it's prime)        a prime numbers, square root of 23 is less than 5.
        n = 7, return 7                             square root of 7 is 3
        n = 16, return 2 (NOT 4), since 2|16 = 8.
        n = 221, return 13 (since 13*17 is 221)
    """
    assert specs.smallest_factor(23) == 23, "failed on prime number case"
    assert specs.smallest_factor(16) == 2, "failed third case"
    assert specs.smallest_factor(7) == 7, "failed last case"
    assert specs.smallest_factor(
        221) == 13, "failed composite of prime numbers case"
    assert specs.smallest_factor(15) == 3, "failed composite number case"
def test_smallest_factor():
    #test cases for all conditions
    assert specs.smallest_factor(1) == 1, "failed on 1"
    assert specs.smallest_factor(2) == 2, "failed on 2"
    assert specs.smallest_factor(3) == 3, "failed on 3"
    assert specs.smallest_factor(5) == 5, "failed on 5"
    assert specs.smallest_factor(6) == 2, "failed on 6"
    assert specs.smallest_factor(7) == 7, "failed on 7"
    assert specs.smallest_factor(4) == 2, "failed on 4"
    assert specs.smallest_factor(9) == 3, "failed on 9"
    assert specs.smallest_factor(10) == 2, "failed on 10"
    assert specs.smallest_factor(11) == 11, "failed on 11"
    assert specs.smallest_factor(12) == 2, "failed on 12"
def test_smallest_factor():
    assert specs.smallest_factor(1) == 1, "failed on base case n = 1"
    assert specs.smallest_factor(2) == 2, "failed on base case n = 2"
    assert specs.smallest_factor(3) == 3, "failed on base case n = 3"
    assert specs.smallest_factor(4) == 2, "failed on composition n = 4 = 2*2"
    assert specs.smallest_factor(5) == 5, "failed on base case n = 5"
    assert specs.smallest_factor(6) == 2, "failed on composition n = 6 = 3*2"
    assert specs.smallest_factor(10) == 2, "failed on composition n = 10 = 5*2"
    assert specs.smallest_factor(15) == 3, "failed on composition n = 15 = 5*3"
    assert specs.smallest_factor(99) == 3, "failed on large number n = 99"
    assert specs.smallest_factor(169) == 13, "failed on perfect square n = 169 = 13**2"
    assert specs.smallest_factor(1073) == 29, "failed on prime composition n = 1073 = 29*37"
Exemple #5
0
def test_smallest_factor():
    assert specs.smallest_factor(25) == 5
    assert specs.smallest_factor(1) == 1
    assert specs.smallest_factor(17) == 17
    assert specs.smallest_factor(34) == 2
Exemple #6
0
def test_smallest_factor():
    assert specs.smallest_factor(1) == 1, "failed on 1"
    assert specs.smallest_factor(5) == 5, "failed on small prime number"
    assert specs.smallest_factor(20) == 2, "failed on even number"
    assert specs.smallest_factor(37) == 37, "failed on large prime number"
    assert specs.smallest_factor(49) == 7, "failed on 49"
def test_smallest_factor():
    assert specs.smallest_factor(1) == 1, "Smallest_factor failed for 1"
    assert specs.smallest_factor(
        5) == 5, "Smallest_factor failed for prime number"
    assert specs.smallest_factor(
        6) == 2, "Smallest_factor failed for composite number"