Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perfect-numbers: stub implementation passes all tests #710

Open
ErikSchierboom opened this issue Feb 11, 2024 · 7 comments
Open

perfect-numbers: stub implementation passes all tests #710

ErikSchierboom opened this issue Feb 11, 2024 · 7 comments

Comments

@ErikSchierboom
Copy link
Member

If I use the following stub implementation, all tests pass:

function isperfect(n)
    n > 0 || throw(DomainError(n, "Must be positive"))
end

function isabundant(n)
    n > 0 || throw(DomainError(n, "Must be positive"))
end

function isdeficient(n)
    n > 0 || throw(DomainError(n, "Must be positive"))
end
@depial
Copy link
Contributor

depial commented Mar 25, 2024

Below, I've modified runtests.jl by adding two tests for each of isperfect, isabundant and isdeficient which should return false. I simply used one number from each of the other two kinds of numbers for each function, which is enough to invalidate implementations like the stub above.

using Test

include("perfect-numbers.jl")

@testset "Perfect numbers" begin

    @testset "Smallest perfect number is classified correctly" begin
        @test isperfect(6)
    end

    @testset "Medium perfect number is classified correctly" begin
        @test isperfect(28)
    end

    @testset "Large perfect number is classified correctly" begin
        @test isperfect(33550336)
    end

    @testset "Correctly handles non-perfect numbers" begin
        @test !isperfect(12)
        @test !isperfect(4)
    end
end

@testset "Abundant numbers" begin

    @testset "Smallest abundant number is classified correctly" begin
        @test isabundant(12)
    end

    @testset "Medium abundant number is classified correctly" begin
        @test isabundant(30)
    end

    @testset "Large abundant number is classified correctly" begin
        @test isabundant(33550335)
    end

    @testset "Correctly handles non-abundant numbers" begin
        @test !isabundant(6)
        @test !isabundant(32)
    end
end

@testset "Deficient numbers" begin

    @testset "Smallest prime deficient number is classified correctly" begin
        @test isdeficient(2)
    end

    @testset "Smallest non-prime deficient number is classified correctly" begin
        @test isdeficient(4)
    end

    @testset "Medium deficient number is classified correctly" begin
        @test isdeficient(32)
    end

    @testset "Large deficient number is classified correctly" begin
        @test isdeficient(33550337)
    end

    @testset "Edge case (no factors other than itself) is classified correctly" begin
        @test isdeficient(1)
    end

    @testset "Correctly handles non-deficient numbers" begin
        @test !isdeficient(28)
        @test !isdeficient(30)
    end
end

@testset "Invalid inputs" begin

    @testset "Zero is rejected (not a natural number)" begin
        @test_throws DomainError isdeficient(0)
        @test_throws DomainError isperfect(0)
        @test_throws DomainError isabundant(0)
    end

    @testset "Negative integer is rejected (not a natural number)" begin
        @test_throws DomainError isdeficient(-1)
        @test_throws DomainError isperfect(-1)
        @test_throws DomainError isabundant(-1)
    end
end

@ErikSchierboom
Copy link
Member Author

@depial Great. Would you be willing to submit a PR?

@depial
Copy link
Contributor

depial commented Mar 27, 2024

@ErikSchierboom The PR can be found here. Sorry I didn't open it directly, but I wasn't aware of the process of creating a branch from my fork to submit a PR with just a single commit.

A side note: the Exercise CI / Julia nightly - OS (pull_request) checks are failing due to what appears to be a problem with Circular Buffer (specifically the isfull method).

@ErikSchierboom
Copy link
Member Author

A side note: the Exercise CI / Julia nightly - OS (pull_request) checks are failing due to what appears to be a problem with Circular Buffer (specifically the isfull method).

Hmmm, interesting. Would you be willing to take a look at that too?

@depial
Copy link
Contributor

depial commented Mar 28, 2024

I've found a quick fix for the nightly check issue in this PR, and all checks pass now, but I feel like there's something deeper to it since it seems to have appeared from nowhere a couple of weeks ago (Bump Actions showing the first failure here).

@ErikSchierboom
Copy link
Member Author

I've merged that PR. Could you rebase this PR?

@depial
Copy link
Contributor

depial commented Mar 28, 2024

Everything should be synced now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants