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

Creating IsPrime function #16

Merged
merged 19 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/help_wanted.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
name: help wanted
about: >
about: >
A template issue for when you're blocked on certain lines of code.
This template has many sections to get you thinking about your problem, you don't need to fill all of them.
This template has many sections to get you thinking about your problem,
you don't need to fill all of them.
labels: "help wanted"

---

<!--
Expand Down
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/meeting_agenda.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
---
name: meeting agenda
about: A template issue for planning meetings
title: "Agenda: __"
title: "Agenda: \_\_"
labels: agenda
---


<!-- Make your issue easy to find:

- milestone: any milestones you will be addressing
Expand Down
5 changes: 2 additions & 3 deletions .github/ISSUE_TEMPLATE/new_challenge.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
---
name: new challenge
about: >
A template issue for describing a new challenge on the project board.
about: >
A template issue for describing a new challenge on the project board.
Place this issue in the TODO column of your group's project board.
title: ''
---

<!--
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: question
about: >
about: >
A template issue for topics you'd like to discuss or learn more about.
specific topics, general knowledge, it does not even need to be about code.
There are no bad questions!
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: python version
run: python --version
shell: bash

- name: Check for test files
id: check_tests
run: |
if find . -type f -name "test_*.py" | grep -q .; then
echo "has_tests=true" >> $GITHUB_OUTPUT
else
echo "has_tests=false" >> $GITHUB_OUTPUT
fi
shell: bash

- name: Python - Run Tests
if: steps.check_tests.outputs.has_tests == 'true'
run: python -m unittest
shell: bash
10 changes: 4 additions & 6 deletions collaboration/guide/0_repository_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ take the time to do this correctly at the beginning.

## Setup and Share a Repository

As a team you will choose the name for your team and select
someone from your team to be the repo owner. This person will fork this
repository and configure it for collaboration:
As a team you will choose the name for your team and select someone from your
team to be the repo owner. This person will fork this repository and configure
it for collaboration:

- Public face of your repository
- Change your
[repository description](https://stackoverflow.com/questions/7757751/how-do-you-change-a-repository-description-on-github)
- Add or remove topics from your repository
- Update your main README with your group name and an initial overview of your

project. (You can change this as much as you want.)

project. (You can change this as much as you want.)
- Under settings in your repository select:
- _Issues_
- _Projects_
Expand Down
41 changes: 41 additions & 0 deletions solutions/IsPrime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
A module for finding if an integer is prime.

Module contents:
- IsPrime: finds if an integer is prime.

Created on XX XX XX
@author: Mohammed Elfadil
"""


def IsPrime(a: int) -> str:
"""Checks if an integer is prime.
Parameter:
a: int
Return -> str: whether a is prime or not
Raises:
AssertionError: if the argument is not an integer
>>> IsPrime(0)
not prime
>>> IsPrime(1)
not prime
>>> IsPrime(2)
prime
>>> IsPrime(4)
not prime
>>> IsPrime(7)
prime
>>> IsPrime(2.5)
invalid input
"""
if not isinstance(a, int):
return "invalid input"
if a < 2:
return "not prime"
for i in range(2, a):
if a % i == 0:
return "not prime"
return "prime"
73 changes: 73 additions & 0 deletions solutions/tests/test_IsPrime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on XX XX XX

@author: Mohammed Elfadil
"""
import unittest

from solutions.IsPrime import IsPrime


class TestIsPrime(unittest.TestCase):
"""test the IsPrime function"""

def test_0(self):
"""It should evaluate not prime"""
actual = IsPrime(0)
expected = "not prime"
self.assertEqual(actual, expected)

def test_1(self):
"""It should evaluate not prime"""
actual = IsPrime(1)
expected = "not prime"
self.assertEqual(actual, expected)

def test_2(self):
actual = IsPrime(2)
expected = "prime"
self.assertEqual(actual, expected)

def test_4(self):
"""its should evaluate not prime"""
actual = IsPrime(4)
expected = "not prime"
self.assertEqual(actual, expected)

def test_7(self):
"""It should evaluate prime"""
actual = IsPrime(7)
expected = "prime"
self.assertEqual(actual, expected)

def test_9(self):
"""It should evaluate not prime"""
actual = IsPrime(9)
expected = "not prime"
self.assertEqual(actual, expected)

def test_11(self):
"""It should evaluate prime"""
actual = IsPrime(11)
expected = "prime"
self.assertEqual(actual, expected)

def test_13(self):
"""It should evaluate prime"""
actual = IsPrime(13)
expected = "prime"
self.assertEqual(actual, expected)

def test_negative(self):
"""It should evaluate not prime"""
actual = IsPrime(-1)
expected = "not prime"
self.assertEqual(actual, expected)

def test_not_integer(self):
"""It should evaluate not prime"""
actual = IsPrime(1.5)
expected = "invalid input"
self.assertEqual(actual, expected)
Loading