Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ I will try to break it into
* Programming theory 'theory'
* Programming examples 'examples'

I will try to also break the folders down in some logical way, but I reserver the right to change it at any time.
I will try to also break the folders down in some logical way, but I reserve the right to change it at any time.
4 changes: 3 additions & 1 deletion src/attributes/builtins/abs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from src.lp_utilities.random_gen import random_signed_integer, random_signed_float, random_signed_complex
from src.lp_utilities.random_gen import random_signed_complex
from src.lp_utilities.random_gen import random_signed_float
from src.lp_utilities.random_gen import random_signed_integer
from src.lp_utilities.separator import separator

"""
Expand Down
26 changes: 24 additions & 2 deletions src/attributes/builtins/any.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from lp_utilities.separator import separator

from decimal import Decimal
from fractions import Fraction
from src.lp_utilities.separator import separator

"""
The any() function is a simple tests to see if any of the items in an iterable
Expand All @@ -13,3 +14,24 @@
For more information on what evaluates to True in Python see:
* Truth Testing Procedure Explained - https://docs.python.org/3/library/stdtypes.html#truth
"""


def any_list_with_a_single_non_falsy_value():
separator("any(iterable) - with any iterable items - Returns True")
print(any(
[None, False, 0, 0.0, 0j, Decimal(0), Fraction(0, 1), '', (), [], {}, set(), range(0), "I am not iterable."]))


def any_list_with_all_falsy_values():
separator("any(iterable) - with NO iterable items - Returns False")
print(any([None, False, 0, 0.0, 0j, Decimal(0), Fraction(0, 1), '', (), [], {}, set(), range(0)]))


def main():
any_list_with_a_single_non_falsy_value()
any_list_with_all_falsy_values()


if __name__ == '__main__': # pragma: no cover
# execute only if run as a script
main()
2 changes: 1 addition & 1 deletion src/attributes/for_loops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from lp_utilities.separator import separator
from src.lp_utilities.separator import separator

"""
For loops depend on the items they loop through being iterable.
Expand Down
2 changes: 1 addition & 1 deletion src/examples/iterable_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

The object at minimum requires the '__iter__' method and the '__next__' method ('next' in python 2)

The '__iter__' methed should return the object it self
The '__iter__' method should return the object it self
The '__next__' method should return the next item in the iteration and should raise a stop iteration exception when done

For more information about The Iteration Protocol
Expand Down
13 changes: 11 additions & 2 deletions src/theory/patterns/abstract_factory/abstract_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MotorCycleInterface(object):
"""
Abstract Motorcycle Class
"""

def __init__(self):
self.wheels = 2
self.vehicle_type = "Motor Cycle"
Expand All @@ -25,6 +26,7 @@ class CarInterface(object):
"""
Abstract Car Class
"""

def __init__(self):
self.wheels = 4
self.vehicle_type = "Automobile"
Expand All @@ -38,6 +40,7 @@ class HarleyDavidson(MotorCycleInterface):
"""
Concrete MotorCycle Class
"""

def __init__(self):
super(HarleyDavidson, self).__init__()
self.mfg = "Harley Davidson"
Expand All @@ -55,6 +58,7 @@ class Honda(MotorCycleInterface):
"""
Concrete MotorCycle Class
"""

def __init__(self):
super(Honda, self).__init__()
self.mfg = "Honda"
Expand All @@ -72,6 +76,7 @@ class MercedezBenz(CarInterface):
"""
Concrete Car Class
"""

def __init__(self):
super(MercedezBenz, self).__init__()
self.mfg = "Mercedez-Benz"
Expand All @@ -89,6 +94,7 @@ class Lexus(CarInterface):
"""
Concrete Car Class
"""

def __init__(self):
super(Lexus, self).__init__()
self.mfg = "Lexus"
Expand All @@ -106,13 +112,15 @@ class VehicleFactoryInterface(object):
"""
Abstract Factory Interface
"""

def get_vehicle(self, brand): pass


class MotorCycleFactory(VehicleFactoryInterface):
"""
Concrete Vehicle Factory
"""

def get_vehicle(self, brand):
if brand == "Harley Davidson":
return HarleyDavidson()
Expand All @@ -125,6 +133,7 @@ class CarFactory(VehicleFactoryInterface):
"""
Concrete Vehicle Factory
"""

def get_vehicle(self, brand):
if brand == "Mercedez-Benz":
return MercedezBenz()
Expand Down Expand Up @@ -154,9 +163,9 @@ def set_vehicle_properties(type_, make, model, speed):
once it has been returned from the factory.
:param type_: STR Type of vehicle
:param make: STR Manufacturer Name
:param model: STR Vechile model Name
:param model: STR Vehicle model Name
:param speed: INT An integer indicating relative speed
:return: vechile_class
:return: vehicle_class
"""
if type_ == "Motorcycle":
vehicle_factory = MotorCycleFactory()
Expand Down
5 changes: 3 additions & 2 deletions tests/test_builtins_abs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
import unittest.mock
from unittest.mock import patch, call

from src.attributes.builtins.abs import print_abs, abs_integer, abs_float, abs_complex, abs_string, main as abs_main


Expand All @@ -18,7 +18,8 @@ def tearDown(self):
def test_print_abs_no_input(self):
with self.assertRaises(TypeError) as context:
print_abs()
self.assertTrue("print_abs() missing 2 required positional arguments: 'input_value' and 'output_value'" in context.exception.args[0])
self.assertTrue("print_abs() missing 2 required positional arguments: 'input_value' and 'output_value'" in
context.exception.args[0])

def test_print_abs_no_output_value(self):
with self.assertRaises(Exception) as context:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_builtins_all.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest.mock
import unittest
from unittest.mock import Mock, patch, call
from src.attributes.builtins.all import print_all, all_list_with_all_good_elements, all_list_with_empty_element, main as all_main

from src.attributes.builtins.all import print_all, all_list_with_all_good_elements, all_list_with_empty_element, \
main as all_main


class TestAll(unittest.TestCase):
Expand Down
35 changes: 35 additions & 0 deletions tests/test_builtins_any.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from unittest.mock import Mock, patch, call
from src.attributes.builtins.any import any_list_with_a_single_non_falsy_value
from src.attributes.builtins.any import any_list_with_all_falsy_values
from src.attributes.builtins.any import main as any_main


class TestAny(unittest.TestCase):

@patch('sys.stdout')
def test_any_list_with_a_single_non_falsy_value(self, mock_print):
any_list_with_a_single_non_falsy_value()
expected_call = [call.write("True")]
mock_print.assert_has_calls(expected_call, any_order=True)

@patch('sys.stdout')
def test_any_list_with_all_falsy_values(self, mock_print):
any_list_with_all_falsy_values()
expected_call = [call.write("False")]
mock_print.assert_has_calls(expected_call, any_order=True)

@patch('src.attributes.builtins.all.separator', Mock())
@patch('src.attributes.builtins.any.any_list_with_a_single_non_falsy_value')
@patch('src.attributes.builtins.any.any_list_with_all_falsy_values')
def test_main(self, mock_all_false, mock_mostly_false):
any_main()
mock_all_false.assert_called_once()
mock_mostly_false.assert_called_once()


if __name__ == "__main__":
# execute only if run as a script
unittest.main()
2 changes: 1 addition & 1 deletion tests/test_theory_patterns_abstract_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,4 @@ def test_main(self, mock_print, mock_vehicle):

if __name__ == "__main__":
# execute only if run as a script
unittest.main()
unittest.main()
5 changes: 3 additions & 2 deletions tests/test_theory_patterns_factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from unittest.mock import Mock, patch, call
from unittest.mock import patch, call

from src.theory.patterns.factories.factory_pattern import ShapeInterface, Circle, Square, ShapeFactory, main as fp_main


Expand Down Expand Up @@ -78,7 +79,7 @@ def return_type_error(self):

@patch('sys.stdout')
@patch('src.theory.patterns.factories.factory_pattern.ShapeFactory.get_shape')
def test_main_with_excpetion(self, mock_factory, mock_print):
def test_main_with_exception(self, mock_factory, mock_print):
mock_factory.side_effect = [Square(), Circle(), TypeError('test')]
fp_main()
expected = [call.write('test')]
Expand Down