From 66963819d6669a62bfa263b3c501f3b719a20a0a Mon Sep 17 00:00:00 2001 From: Becky Wilson Date: Tue, 1 Oct 2019 22:56:06 +0100 Subject: [PATCH] added find max value algorithm --- allalgorithms/numeric/__init__.py | 1 + allalgorithms/numeric/max_numbers.py | 16 ++++++++++++++++ tests/test_numeric.py | 13 +++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 allalgorithms/numeric/__init__.py create mode 100644 allalgorithms/numeric/max_numbers.py create mode 100644 tests/test_numeric.py diff --git a/allalgorithms/numeric/__init__.py b/allalgorithms/numeric/__init__.py new file mode 100644 index 0000000..cd1f5cc --- /dev/null +++ b/allalgorithms/numeric/__init__.py @@ -0,0 +1 @@ +from .max_numbers import find_max \ No newline at end of file diff --git a/allalgorithms/numeric/max_numbers.py b/allalgorithms/numeric/max_numbers.py new file mode 100644 index 0000000..122734a --- /dev/null +++ b/allalgorithms/numeric/max_numbers.py @@ -0,0 +1,16 @@ +# -*- coding: UTF-8 -*- +# +# Numeric Algorithms +# The All â–²lgorithms library for python +# +# Contributed by: Becky +# Github: @beckyw5 +# + + +def find_max (L): + max = 0 + for x in L: + if x > max: + max = x + return max diff --git a/tests/test_numeric.py b/tests/test_numeric.py new file mode 100644 index 0000000..2be532d --- /dev/null +++ b/tests/test_numeric.py @@ -0,0 +1,13 @@ +import unittest + +from allalgorithms.numeric import find_max + + +class TestMax(unittest.TestCase): + + def test_find_max_value(self): + test_list = [3, 1, 8, 7, 4] + self.assertEqual(8, find_max(test_list)) + +if __name__ == "__main__": + unittest.main()