Repository: keon/algorithms
Pull request #340 (2018-06-08 14:21:59)

Fixed all noted camelcase in function/variable/file names and made minor spelling edits
(Put an `X` inside the `[ ]` to denote check mark `[X]`.)


- [ ] **If creating a new file :**
  - [ ] added links to it in the README files ?
  - [ ] included tests with it ?
  - [ ] added description (overview of algorithm, time and space compleixty, and possible edge case) in docstrings ?

- [ ] **if done some changes :**
  - [X] wrote short description in the PR explaining what the changes do ?
  - [X] Fixes #[issue number] if related to any issue

- [ ] **other**

I basically just looked over all files in the algorithms folder and changed all relevant camelcase to lowercase and underscore. It's important to note that I can't guarantee I removed every instance of camelcase, just the ones that I saw. I also made minor spelling changes here and there (i.e., occurance -> occurrence). These edits are in response to Issue #12. 

coveralls: ## Pull Request Test Coverage Report for [Build 572](https://coveralls.io/builds/17393232)

* **26** of **33**   **(78.79%)**  changed or added relevant lines in **7** files are covered.
* **3** unchanged lines in **2** files lost coverage.
* Overall coverage decreased (**-0.04%**) to **69.408%**

---

|  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
| :-----|--------------|--------|---: |
| [algorithms/stack/longest_abs_path.py](https://coveralls.io/builds/17393232/source?filename=algorithms%2Fstack%2Flongest_abs_path.py#L41) | 0 | 7 | 0.0%
<!-- | **Total:** | **26** | **33** | **78.79%** | -->

|  Files with Coverage Reduction | New Missed Lines | % |
| :-----|--------------|--: |
| [algorithms/linkedlist/is_palindrome.py](https://coveralls.io/builds/17393232/source?filename=algorithms%2Flinkedlist%2Fis_palindrome.py#L88) | 1 | 93.33% |
| [algorithms/sort/top_sort.py](https://coveralls.io/builds/17393232/source?filename=algorithms%2Fsort%2Ftop_sort.py#L41) | 2 | 90.38% |
<!-- | **Total:** | **3** |  | -->

|  Totals | [![Coverage Status](https://coveralls.io/builds/17393232/badge)](https://coveralls.io/builds/17393232) |
| :-- | --: |
| Change from base [Build 569](https://coveralls.io/builds/17386125): |  -0.04% |
| Covered Lines: | 3249 |
| Relevant Lines: | 4681 |

---
##### 💛  - [Coveralls](https://coveralls.io)

herinckc: @goswami-rahul thanks for the quick response! I've added a couple new commits to address the concerns you've raised. Please let me know if I've missed anything else

Patch:
diff --git a/algorithms/arrays/max_ones_index.py b/algorithms/arrays/max_ones_index.py
index bee1f76..40abdf5 100644
--- a/algorithms/arrays/max_ones_index.py
+++ b/algorithms/arrays/max_ones_index.py
@@ -40,4 +40,4 @@ def max_ones_index(arr):
     if n - prev_prev_zero > max_count:
         max_index = prev_zero
 
-    return max_index
\ No newline at end of file
+    return max_index
diff --git a/algorithms/calculator/math_parser.py b/algorithms/calculator/math_parser.py
index 830d717..a1d0e0b 100644
--- a/algorithms/calculator/math_parser.py
+++ b/algorithms/calculator/math_parser.py
@@ -144,4 +144,4 @@ def main():
         
 
 if __name__ == "__main__":
-    main()
\ No newline at end of file
+    main()
diff --git a/algorithms/dfs/sudoku_solver.py b/algorithms/dfs/sudoku_solver.py
index 4f3c275..387cdca 100644
--- a/algorithms/dfs/sudoku_solver.py
+++ b/algorithms/dfs/sudoku_solver.py
@@ -107,4 +107,4 @@ class TestSudoku(unittest.TestCase):
 
 
 if __name__ == "__main__":
-    unittest.main()
\ No newline at end of file
+    unittest.main()
diff --git a/algorithms/dp/fib.py b/algorithms/dp/fib.py
index 3ba4c5e..765ee2f 100644
--- a/algorithms/dp/fib.py
+++ b/algorithms/dp/fib.py
@@ -70,4 +70,4 @@ def fib_iter(n):
     return sum
 
 # => 354224848179261915075
-# print(fib_iter(100))
\ No newline at end of file
+# print(fib_iter(100))
diff --git a/algorithms/graph/checkDiGraphStronglyConnected.py b/algorithms/graph/check_digraph_strongly_connected.py
similarity index 100%
rename from algorithms/graph/checkDiGraphStronglyConnected.py
rename to algorithms/graph/check_digraph_strongly_connected.py
diff --git a/algorithms/graph/pathBetweenTwoVerticesInDiGraph.py b/algorithms/graph/path_between_two_vertices_in_digraph.py
similarity index 100%
rename from algorithms/graph/pathBetweenTwoVerticesInDiGraph.py
rename to algorithms/graph/path_between_two_vertices_in_digraph.py
diff --git a/algorithms/maths/base_conversion.py b/algorithms/maths/base_conversion.py
index 1ea31e3..cc3b62c 100644
--- a/algorithms/maths/base_conversion.py
+++ b/algorithms/maths/base_conversion.py
@@ -8,7 +8,7 @@ base2int('F', 16) return 15.
 
 import string
 
-def int2base(n, base):
+def int_to_base(n, base):
     """
         :type n: int
         :type base: int
@@ -31,7 +31,7 @@ def int2base(n, base):
         return res[::-1]
 
 
-def base2int(s, base):
+def base_to_int(s, base):
     """
         Note : You can use int() built-in function instread of this.
         :type s: str
diff --git a/algorithms/search/__init__.py b/algorithms/search/__init__.py
index ec3a783..8304059 100644
--- a/algorithms/search/__init__.py
+++ b/algorithms/search/__init__.py
@@ -1,6 +1,6 @@
 from .binary_search import *
-from .first_occurance import *
-from .last_occurance import *
+from .first_occurrence import *
+from .last_occurrence import *
 from .linear_search import *
 from .search_insert import *
 from .two_sum import *
diff --git a/algorithms/search/first_occurance.py b/algorithms/search/first_occurrence.py
similarity index 92%
rename from algorithms/search/first_occurance.py
rename to algorithms/search/first_occurrence.py
index addf170..86dc89c 100644
--- a/algorithms/search/first_occurance.py
+++ b/algorithms/search/first_occurrence.py
@@ -3,7 +3,7 @@
 # Approach- Binary Search
 # T(n)- O(log n)
 #
-def first_occurance(array, query):
+def first_occurrence(array, query):
     lo, hi = 0, len(array) - 1
     while lo <= hi:
         mid = (lo + hi) // 2
diff --git a/algorithms/search/last_occurance.py b/algorithms/search/last_occurrence.py
similarity index 92%
rename from algorithms/search/last_occurance.py
rename to algorithms/search/last_occurrence.py
index b8ee4fa..345b423 100644
--- a/algorithms/search/last_occurance.py
+++ b/algorithms/search/last_occurrence.py
@@ -3,7 +3,7 @@
 # Approach- Binary Search
 # T(n)- O(log n)
 #
-def last_occurance(array, query):
+def last_occurrence(array, query):
     lo, hi = 0, len(array) - 1
     while lo <= hi:
         mid = (hi + lo) // 2
diff --git a/algorithms/stack/longest_abs_path.py b/algorithms/stack/longest_abs_path.py
index 64c7a67..67aad5a 100644
--- a/algorithms/stack/longest_abs_path.py
+++ b/algorithms/stack/longest_abs_path.py
@@ -38,7 +38,7 @@ def length_longest_path(input):
     :type input: str
     :rtype: int
     """
-    currlen, maxlen = 0, 0    # running length and max length
+    curr_len, max_len = 0, 0    # running length and max length
     stack = []    # keep track of the name length
     for s in input.split('\n'):
         print("---------")
@@ -46,16 +46,16 @@ def length_longest_path(input):
         depth = s.count('\t')    # the depth of current dir or file
         print("depth: ", depth)
         print("stack: ", stack)
-        print("curlen: ", currlen)
+        print("curlen: ", curr_len)
         while len(stack) > depth:    # go back to the correct depth
-            currlen -= stack.pop()
+            curr_len -= stack.pop()
         stack.append(len(s.strip('\t'))+1)   # 1 is the length of '/'
-        currlen += stack[-1]    # increase current length
+        curr_len += stack[-1]    # increase current length
         print("stack: ", stack)
-        print("curlen: ", currlen)
+        print("curlen: ", curr_len)
         if '.' in s:    # update maxlen only when it is a file
-            maxlen = max(maxlen, currlen-1)    # -1 is to minus one '/'
-    return maxlen
+            max_len = max(max_len, curr_len-1)    # -1 is to minus one '/'
+    return max_len
 
 st= "dir\n\tsubdir1\n\t\tfile1.ext\n\t\tsubsubdirectory1\n\tsubdir2\n\t\tsubsubdir2\n\t\t\tfile2.ext"
 st2 = "a\n\tb1\n\t\tf1.txt\n\taaaaa\n\t\tf2.txt"
diff --git a/algorithms/strings/make_sentence.py b/algorithms/strings/make_sentence.py
index 8e6cb5b..2b7bcf7 100644
--- a/algorithms/strings/make_sentence.py
+++ b/algorithms/strings/make_sentence.py
@@ -15,13 +15,13 @@ eg: for given string -> "appletablet"
 count = 0
 
 
-def make_sentence(str_piece, dictionarys):
+def make_sentence(str_piece, dictionaries):
     global count
     if len(str_piece) == 0:
         return True
     for i in range(0, len(str_piece)):
         prefix, suffix = str_piece[0:i], str_piece[i:]
-        if prefix in dictionarys:
-            if suffix in dictionarys or make_sentence(suffix, dictionarys):
+        if prefix in dictionaries:
+            if suffix in dictionaries or make_sentence(suffix, dictionaries):
                 count += 1
     return True
diff --git a/algorithms/tree/bintree2list.py b/algorithms/tree/bin_tree_to_list.py
similarity index 78%
rename from algorithms/tree/bintree2list.py
rename to algorithms/tree/bin_tree_to_list.py
index 0912954..d23834b 100644
--- a/algorithms/tree/bintree2list.py
+++ b/algorithms/tree/bin_tree_to_list.py
@@ -4,28 +4,28 @@ class Node():
         self.left = None
         self.right = None
 
-def bintree2list(root):
+def bin_tree_to_list(root):
     """
     type root: root class
     """
     if not root:
         return root
-    root = bintree2list_util(root)
+    root = bin_tree_to_list_util(root)
     while root.left:
         root = root.left
     return root
 
-def bintree2list_util(root):
+def bin_tree_to_list_util(root):
     if not root:
         return root
     if root.left:
-        left = bintree2list_util(root.left)
+        left = bin_tree_to_list_util(root.left)
         while left.right:
             left = left.right
         left.right = root
         root.left = left
     if root.right:
-        right = bintree2list_util(root.right)
+        right = bin_tree_to_list_util(root.right)
         while right.left:
             right = right.left
         right.left = root
@@ -45,5 +45,5 @@ tree.left.left.right  = Node(100)
 tree.left.right = Node(30)
 tree.right.left = Node(36)
 
-head = bintree2list(tree)
+head = bin_tree_to_list(tree)
 print_tree(head)
diff --git a/algorithms/tree/bst/array2bst.py b/algorithms/tree/bst/array_to_bst.py
similarity index 75%
rename from algorithms/tree/bst/array2bst.py
rename to algorithms/tree/bst/array_to_bst.py
index 62fe5b9..7ca5cf9 100644
--- a/algorithms/tree/bst/array2bst.py
+++ b/algorithms/tree/bst/array_to_bst.py
@@ -11,11 +11,11 @@ class TreeNode(object):
         self.right = None
 
 
-def array2bst(nums):
+def array_to_bst(nums):
     if not nums:
         return None
     mid = len(nums)//2
     node = TreeNode(nums[mid])
-    node.left = array2bst(nums[:mid])
-    node.right = array2bst(nums[mid+1:])
+    node.left = array_to_bst(nums[:mid])
+    node.right = array_to_bst(nums[mid+1:])
     return node
diff --git a/algorithms/tree/longest_consecutive.py b/algorithms/tree/longest_consecutive.py
index fde962c..4fd809a 100644
--- a/algorithms/tree/longest_consecutive.py
+++ b/algorithms/tree/longest_consecutive.py
@@ -32,18 +32,18 @@ def longest_consecutive(root):
     """
     if not root:
         return 0
-    maxlen = 0
-    dfs(root, 0, root.val, maxlen)
-    return maxlen
+    max_len = 0
+    dfs(root, 0, root.val, max_len)
+    return max_len
 
 
-def dfs(root, cur, target, maxlen):
+def dfs(root, cur, target, max_len):
     if not root:
         return
     if root.val == target:
         cur += 1
     else:
         cur = 1
-    maxlen = max(cur, maxlen)
-    dfs(root.left, cur, root.val+1, maxlen)
-    dfs(root.right, cur, root.val+1, maxlen)
+    max_len = max(cur, max_len)
+    dfs(root.left, cur, root.val+1, max_len)
+    dfs(root.right, cur, root.val+1, max_len)
diff --git a/algorithms/tree/red_black_tree/red_black_tree.py b/algorithms/tree/red_black_tree/red_black_tree.py
index 15114e0..33fb6af 100644
--- a/algorithms/tree/red_black_tree/red_black_tree.py
+++ b/algorithms/tree/red_black_tree/red_black_tree.py
@@ -202,7 +202,7 @@ class RBTree:
             node_min.left = node.left
             node_min.left.parent = node_min
             node_min.color = node.color
-        # when node is black ,then need to fix it with 4 cases
+        # when node is black, then need to fix it with 4 cases
         if node_color == 0:
             self.delete_fixup(temp_node)
 
diff --git a/algorithms/tree/segment_tree/segment_tree.py b/algorithms/tree/segment_tree/segment_tree.py
index de62b6b..2bf5196 100644
--- a/algorithms/tree/segment_tree/segment_tree.py
+++ b/algorithms/tree/segment_tree/segment_tree.py
@@ -10,12 +10,12 @@ class SegmentTree:
         self.fn = function
         self.maketree(0,0,len(arr)-1)
 
-    def maketree(self,i,l,r):
+    def make_tree(self,i,l,r):
         if l==r:
             self.segment[i] = self.arr[l]
         elif l<r:
-            self.maketree(2*i+1,l,int((l+r)/2))
-            self.maketree(2*i+2,int((l+r)/2)+1,r)
+            self.make_tree(2*i+1,l,int((l+r)/2))
+            self.make_tree(2*i+2,int((l+r)/2)+1,r)
             self.segment[i] = self.fn(self.segment[2*i+1],self.segment[2*i+2])
 
     def __query(self,i,L,R,l,r):


Test patch:
diff --git a/tests/test_maths.py b/tests/test_maths.py
index a5ca21f..ece9ab7 100644
--- a/tests/test_maths.py
+++ b/tests/test_maths.py
@@ -1,5 +1,5 @@
 from algorithms.maths import (
-    int2base, base2int,
+    int_to_base, base_to_int,
     extended_gcd,
     factorial, factorial_recur,
     gcd, lcm,
@@ -26,14 +26,14 @@ class TestBaseConversion(unittest.TestCase):
     """
 
     def test_int2base(self):
-        self.assertEqual("101", int2base(5, 2))
-        self.assertEqual("0", int2base(0, 2))
-        self.assertEqual("FF", int2base(255, 16))
+        self.assertEqual("101", int_to_base(5, 2))
+        self.assertEqual("0", int_to_base(0, 2))
+        self.assertEqual("FF", int_to_base(255, 16))
 
     def test_base2int(self):
-        self.assertEqual(5, base2int("101", 2))
-        self.assertEqual(0, base2int("0", 2))
-        self.assertEqual(255, base2int("FF", 16))
+        self.assertEqual(5, base_to_int("101", 2))
+        self.assertEqual(0, base_to_int("0", 2))
+        self.assertEqual(255, base_to_int("FF", 16))
 
 
 class TestExtendedGcd(unittest.TestCase):
diff --git a/tests/test_search.py b/tests/test_search.py
index c9f18ee..4f869fe 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -1,7 +1,7 @@
 from algorithms.search import (
     binary_search, binary_search_recur,
-    first_occurance,
-    last_occurance,
+    first_occurrence,
+    last_occurrence,
     linear_search,
     search_insert,
     two_sum, two_sum1, two_sum2,
@@ -15,17 +15,17 @@ import unittest
 
 class TestSuite(unittest.TestCase):
 
-    def test_first_occurance(self):
+    def test_first_occurrence(self):
         def helper(array, query):
             idx = array.index(query) if query in array else None
             return idx
         array = [1, 1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6, 6, 6]
-        self.assertEqual(first_occurance(array, 1), helper(array, 1))
-        self.assertEqual(first_occurance(array, 3), helper(array, 3))
-        self.assertEqual(first_occurance(array, 5), helper(array, 5))
-        self.assertEqual(first_occurance(array, 6), helper(array, 6))
-        self.assertEqual(first_occurance(array, 7), helper(array, 7))
-        self.assertEqual(first_occurance(array, -1), helper(array, -1))
+        self.assertEqual(first_occurrence(array, 1), helper(array, 1))
+        self.assertEqual(first_occurrence(array, 3), helper(array, 3))
+        self.assertEqual(first_occurrence(array, 5), helper(array, 5))
+        self.assertEqual(first_occurrence(array, 6), helper(array, 6))
+        self.assertEqual(first_occurrence(array, 7), helper(array, 7))
+        self.assertEqual(first_occurrence(array, -1), helper(array, -1))
 
     def test_binary_search(self):
         array = [1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6]
@@ -39,13 +39,13 @@ class TestSuite(unittest.TestCase):
         self.assertEqual(-1, binary_search_recur(array, 0, 11, 7))
         self.assertEqual(-1, binary_search_recur(array, 0, 11, -1))
 
-    def test_last_occurance(self):
+    def test_last_occurrence(self):
         array = [1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6, 6, 6]
-        self.assertEqual(5, last_occurance(array, 3))
-        self.assertEqual(10, last_occurance(array, 5))
-        self.assertEqual(None, last_occurance(array, 7))
-        self.assertEqual(0, last_occurance(array, 1))
-        self.assertEqual(13, last_occurance(array, 6))
+        self.assertEqual(5, last_occurrence(array, 3))
+        self.assertEqual(10, last_occurrence(array, 5))
+        self.assertEqual(None, last_occurrence(array, 7))
+        self.assertEqual(0, last_occurrence(array, 1))
+        self.assertEqual(13, last_occurrence(array, 6))
         
     def test_linear_search(self):
         array = [1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6, 6, 6]