Skip to content

Commit b407afe

Browse files
Merge pull request #1 from bcrawford39GT/initial_setup
initial setup
2 parents 28ec3a8 + f979bf4 commit b407afe

File tree

15 files changed

+592
-339
lines changed

15 files changed

+592
-339
lines changed

.gitignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
test-output.xml
2+
*.py[cod]
3+
*.ipynb_checkpoints
4+
5+
# C extensions
6+
*.so
7+
8+
# github
9+
**/.DS_Store
10+
11+
# Packages
12+
*.egg
13+
*.egg-info
14+
dist
15+
build
16+
eggs
17+
parts
18+
bin
19+
var
20+
sdist
21+
develop-eggs
22+
.installed.cfg
23+
.pypirc
24+
25+
# Installer logs
26+
pip-log.txt
27+
28+
# Unit test / coverage reports
29+
.coverage
30+
.tox
31+
nosetests.xml
32+
htmlcov
33+
.cache
34+
.pytest_cache/
35+
36+
# Translations
37+
*.mo
38+
39+
# Complexity
40+
output/*.html
41+
output/*/index.html
42+
43+
# Sphinx
44+
docs/_build
45+
46+
# PyCharm
47+
.idea
48+
.idea/*
49+
50+
# VSCode
51+
.vscode
52+
.vscode/*
53+
54+
# Vagrant
55+
.vagrant
56+
Vagrantfile
57+
58+
# rope project settings
59+
.ropeproject
60+
61+
#conda version
62+
__conda_version__.txt
63+
github_tutorial/version.py
64+
65+
#virtual env
66+
.env/
67+
68+

LICENSE

Lines changed: 0 additions & 339 deletions
This file was deleted.

environment.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: github_tutorial
2+
channels:
3+
- conda-forge
4+
- defaults
5+
dependencies:
6+
- numpy
7+
- pytest
8+
- pip

examples_to_run/examples.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from github_tutorial.main_functions.main_functions import math_function_class
2+
3+
# enter the two (2) values to use
4+
entered_value_0 = 100
5+
entered_value_1 = 2
6+
7+
# set the math_function_class
8+
math_variable = math_function_class(entered_value_0, entered_value_1)
9+
10+
# print the math_variable (i.e., math_function_class) and list its type
11+
print(f"\n")
12+
print(f"math_variable = {math_variable}")
13+
print(f"type(math_variable) = {type(math_variable)}\n")
14+
15+
# print the math_variable attribute added_number and list its type
16+
print(f"math_variable.added_numbers = {math_variable.added_numbers}")
17+
print(f"type(math_variable.added_numbers) = {type(math_variable.added_numbers)}\n")
18+
19+
# print the math_variable attribute multiplied_numbers and list its type
20+
print(
21+
f"math_variable.multiplied_numbers = "
22+
f"{math_variable.multiplied_numbers}"
23+
)
24+
print(
25+
f"type(math_variable.multiplied_numbers) = "
26+
f"{type(math_variable.multiplied_numbers)}\n"
27+
)
28+
29+
# print the math_variable running a function within the class (add_1_to_both_numbers_and_multiply()) and list its type
30+
print(
31+
f"math_variable.add_1_to_both_numbers_and_multiply() = "
32+
f"{math_variable.add_1_to_both_numbers_and_multiply()}"
33+
)
34+
print(
35+
f"type(math_variableadd_1_to_both_numbers_and_multiply()) = "
36+
f"{type(math_variable.add_1_to_both_numbers_and_multiply())}\n")

github_tutorial/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""The main math functions from this tutorial"""
2+
from github_tutorial.main_functions import main_functions
3+
from github_tutorial.main_functions.main_functions import math_function_class
4+
from github_tutorial.utils.math import (add_2_numbers, multiple_of_2_numbers)
5+
6+
__version__ = "0.0.0"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""main math functions"""
2+
from github_tutorial.utils.math import (add_2_numbers, multiple_of_2_numbers)
3+
from github_tutorial.main_functions.main_functions import math_function_class
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import numpy as np
2+
from github_tutorial.utils.math import (add_2_numbers, multiple_of_2_numbers)
3+
from warnings import warn
4+
5+
def _add_1_to_value(initial_value):
6+
"""Add 1 to to any value.
7+
8+
This function adds 1 to the entered value.
9+
10+
Parameters
11+
----------
12+
initial_value: int or float
13+
The first integer or float that 1 will be added to.
14+
15+
Returns
16+
-------
17+
final_value: int or float
18+
The initial value plus 1.
19+
"""
20+
if not isinstance(initial_value, (int, float)):
21+
raise TypeError(
22+
f"ERROR: In the '_add_1_to_value' function, the {'initial_value'} "
23+
f"is a {type(initial_value)} and not a int or float."
24+
)
25+
26+
if initial_value >= 100:
27+
warn(
28+
f"WARNING: In the '_add_1_to_value' function, the {'initial_value'} >= 100 "
29+
f"({'initial_value'} = {initial_value}). Are you sure you want to use a large number?"
30+
)
31+
32+
33+
final_value = initial_value + 1
34+
35+
return final_value
36+
37+
# This is the main math Class
38+
class math_function_class:
39+
"""Add 1 to to any value.
40+
41+
This function adds 1 to the entered value.
42+
43+
Parameters
44+
----------
45+
initial_value: int or float
46+
The first integer or float that 1 will be added to.
47+
48+
Returns
49+
-------
50+
final_value: int or float
51+
The initial value plus 1.
52+
"""
53+
def __init__(
54+
self,
55+
value_0,
56+
value_1
57+
):
58+
59+
if not isinstance(value_0, (int, float)):
60+
raise TypeError(
61+
f"ERROR: In the 'math_function_class' class, the {'value_0'} "
62+
f"is a {type(value_0)} and not a int or float."
63+
)
64+
65+
if not isinstance(value_1, (int, float)):
66+
raise TypeError(
67+
f"ERROR: In the 'math_function_class' class, the {'value_1'} "
68+
f"is a {type(value_1)} and not a int or float."
69+
)
70+
71+
self.value_0 = value_0
72+
self.value_1 = value_1
73+
74+
self.added_numbers = add_2_numbers(self.value_0, self.value_1)
75+
self.multiplied_numbers = multiple_of_2_numbers(self.value_0, self.value_1)
76+
77+
def add_1_to_both_numbers_and_multiply(self):
78+
"""Add 1 to both value_0 and value_1 and multiply them together.
79+
80+
This function adds 1 to each of value_0 and value_1 and multiplies them together.
81+
82+
Returns
83+
-------
84+
add_1_to_both_numbers_and_multiply: int or float
85+
This function adds 1 to each of value_0 and value_1 and multiplies them together.
86+
"""
87+
88+
add_1_to_to_each_value_and_mulitipy = _add_1_to_value(self.value_0) * _add_1_to_value(self.value_1)
89+
90+
return add_1_to_to_each_value_and_mulitipy

github_tutorial/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""test functions for github_tutorial"""

github_tutorial/tests/base_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""test functions for github_tutorial"""
2+
import pytest
3+
4+
class BaseTest:
5+
@pytest.fixture(autouse=True)
6+
def initdir(self, tmpdir):
7+
tmpdir.chdir()
8+
9+
@pytest.fixture
10+
def get_10_plus_5(self):
11+
get_10_plus_5 = 10 + 5
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import numpy as np
2+
import pytest
3+
from github_tutorial.tests.base_test import BaseTest
4+
#from github_tutorial.utils.math import (add_2_numbers, multiple_of_2_numbers)
5+
from github_tutorial.main_functions.main_functions import (math_function_class, _add_1_to_value)
6+
7+
class TestMainFunction(BaseTest):
8+
def test__add_1_to_value_int(self):
9+
val_0 = 1
10+
11+
value = _add_1_to_value(val_0)
12+
13+
assert value == 2
14+
assert isinstance(value, (int, float))
15+
16+
def test__add_1_to_value_float(self):
17+
val_0 = 2.5
18+
19+
value = _add_1_to_value(val_0)
20+
21+
assert np.isclose(value, 3.5)
22+
assert isinstance(value, (int, float))
23+
24+
def test__add_1_to_value_val_0_str(self):
25+
with pytest.raises(
26+
TypeError,
27+
match=f"ERROR: In the '_add_1_to_value' function, the initial_value is a {type('initial_value')} "
28+
f"and not a int or float",
29+
):
30+
val_0 = '1.5'
31+
32+
value = _add_1_to_value(val_0)
33+
34+
def test__add_1_to_value_val_0_equal_99_99(self):
35+
val_0 = 99.999
36+
37+
value = _add_1_to_value(val_0)
38+
39+
assert np.isclose(value, 100.999)
40+
assert isinstance(value, (int, float))
41+
42+
def test__add_1_to_value_val_0_equal_negative_99999_99(self):
43+
val_0 = -99999.99
44+
45+
value = _add_1_to_value(val_0)
46+
47+
assert np.isclose(value, -99998.99)
48+
assert isinstance(value, (int, float))
49+
50+
def test__add_1_to_value_val_0_value_greater_equal_100(self):
51+
with pytest.warns(
52+
UserWarning,
53+
match=f"WARNING: In the '_add_1_to_value' function, the {'initial_value'} >= 100 "
54+
f"\(initial_value = {101}\). Are you sure you want to use a large number?",
55+
):
56+
val_0 = 101
57+
58+
value = _add_1_to_value(val_0)
59+
60+
def test__add_1_to_value_val_0_value_greater_equal_100000(self):
61+
with pytest.warns(
62+
UserWarning,
63+
match=f"WARNING: In the '_add_1_to_value' function, the {'initial_value'} >= 100 "
64+
f"\(initial_value = {100000}\). Are you sure you want to use a large number?",
65+
):
66+
val_0 = 100000
67+
68+
value = _add_1_to_value(val_0)
69+
70+
def test_math_function_class(self):
71+
val_0 = 1
72+
val_1 = 2
73+
74+
math_variable = math_function_class(val_0, val_1)
75+
76+
assert np.isclose(math_variable.added_numbers, 3)
77+
assert isinstance(math_variable.added_numbers, (int, float))
78+
assert np.isclose(math_variable.multiplied_numbers, 2)
79+
assert isinstance(math_variable.multiplied_numbers, (int, float))
80+
assert np.isclose(math_variable.add_1_to_both_numbers_and_multiply(), 6)
81+
assert isinstance(math_variable.add_1_to_both_numbers_and_multiply(), (int, float))
82+
83+
def test_math_function_class_val_0_str(self):
84+
with pytest.raises(
85+
TypeError,
86+
match=f"ERROR: In the 'math_function_class' class, the value_0 is a {type('value_0')} "
87+
f"and not a int or float",
88+
):
89+
val_0 = '1.5'
90+
val_1 = 2.0
91+
92+
math_variable = math_function_class(val_0, val_1)
93+
94+
def test_math_function_class_val_1_str(self):
95+
with pytest.raises(
96+
TypeError,
97+
match=f"ERROR: In the 'math_function_class' class, the value_1 is a {type('value_1')} "
98+
f"and not a int or float",
99+
):
100+
val_0 = 1.5
101+
val_1 = '2.0'
102+
103+
math_variable = math_function_class(val_0, val_1)

0 commit comments

Comments
 (0)