aboutsummaryrefslogtreecommitdiff
path: root/challenge-192/ealvar3z/python/ch-2.py
diff options
context:
space:
mode:
authorealvar3z <55966724+ealvar3z@users.noreply.github.com>2022-11-21 18:53:47 -0800
committerealvar3z <55966724+ealvar3z@users.noreply.github.com>2022-11-21 18:53:47 -0800
commitce95e7e0863d508763fa725107de7596b9581862 (patch)
treeddbf2f7a8a302767003cb05d2df4a765066f53a3 /challenge-192/ealvar3z/python/ch-2.py
parent6b65c39e1d8776c77556b9f7c2419a8d0c5b476b (diff)
downloadperlweeklychallenge-club-ce95e7e0863d508763fa725107de7596b9581862.tar.gz
perlweeklychallenge-club-ce95e7e0863d508763fa725107de7596b9581862.tar.bz2
perlweeklychallenge-club-ce95e7e0863d508763fa725107de7596b9581862.zip
go & python solutions for week 192
Diffstat (limited to 'challenge-192/ealvar3z/python/ch-2.py')
-rw-r--r--challenge-192/ealvar3z/python/ch-2.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-192/ealvar3z/python/ch-2.py b/challenge-192/ealvar3z/python/ch-2.py
new file mode 100644
index 0000000000..a9f4b37bec
--- /dev/null
+++ b/challenge-192/ealvar3z/python/ch-2.py
@@ -0,0 +1,39 @@
+from statistics import mean
+from unittest import main, TestCase
+
+"""
+Example 1:
+ Input: @list = (1, 0, 5)
+ Output: 4
+Example 2:
+ Input: @list = (0, 2, 0)
+ Output: -1
+Example 3:
+ Input: (0, 3, 0)
+ Output: 2
+"""
+
+cases = [
+ ([1, 0, 5], 4),
+ ([0, 2, 0], -1),
+ ([0, 3, 0], 2),
+]
+
+
+class TestSolutionII(TestCase):
+
+ def equal_distro(self, _list):
+ m = int(mean(_list))
+ if m == 0:
+ return -1
+ else:
+ return m + m
+
+ def test_equal_distribution(self):
+ for input, output in cases:
+ with self.subTest(input=output):
+ self.assertEqual(self.equal_distro(input), output)
+
+
+if __name__ == "__main__":
+ main(verbosity=2)