Skip to content

Commit

Permalink
keon#256 change strip_url_params3 to use OrderedDict to prevent faili…
Browse files Browse the repository at this point in the history
…ng test on non deterministic retrieval of dict keys for query string (keon#367)
  • Loading branch information
programatt authored and Hai Hoang Dang committed Jun 28, 2018
1 parent 7520795 commit 81e7853
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion algorithms/strings/strip_url_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import urllib
import urllib.parse

from collections import OrderedDict

# Here is a very non-pythonic grotesque solution
def strip_url_params1(url, params_to_strip=None):

Expand Down Expand Up @@ -37,7 +39,7 @@ def strip_url_params1(url, params_to_strip=None):
string = ''
else:
string += char
dict = defaultdict(int)
dict = OrderedDict()
# logic for checking whether we should add the string to our result
for i in key_value_string:
_token = i.split('=')
Expand Down
34 changes: 17 additions & 17 deletions tests/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,23 +339,23 @@ def test_roman_to_int(self):
self.assertEqual(3999, roman_to_int("MMMCMXCIX"))


# class TestStripUrlParams(unittest.TestCase):
# """[summary]
# Test for the file strip_urls_params.py

# Arguments:
# unittest {[type]} -- [description]
# """

# def test_strip_url_params1(self):
# self.assertEqual(strip_url_params1("www.saadbenn.com?a=1&b=2&a=2"), "www.saadbenn.com?a=1&b=2")
# self.assertEqual(strip_url_params1("www.saadbenn.com?a=1&b=2", ['b']), "www.saadbenn.com?a=1")
# def test_strip_url_params2(self):
# self.assertEqual(strip_url_params2("www.saadbenn.com?a=1&b=2&a=2"), "www.saadbenn.com?a=1&b=2")
# self.assertEqual(strip_url_params2("www.saadbenn.com?a=1&b=2", ['b']), "www.saadbenn.com?a=1")
# def test_strip_url_params3(self):
# self.assertEqual(strip_url_params3("www.saadbenn.com?a=1&b=2&a=2"), "www.saadbenn.com?a=1&b=2")
# self.assertEqual(strip_url_params3("www.saadbenn.com?a=1&b=2", ['b']), "www.saadbenn.com?a=1")
class TestStripUrlParams(unittest.TestCase):
"""[summary]
Test for the file strip_urls_params.py
Arguments:
unittest {[type]} -- [description]
"""

def test_strip_url_params1(self):
self.assertEqual(strip_url_params1("www.saadbenn.com?a=1&b=2&a=2"), "www.saadbenn.com?a=1&b=2")
self.assertEqual(strip_url_params1("www.saadbenn.com?a=1&b=2", ['b']), "www.saadbenn.com?a=1")
def test_strip_url_params2(self):
self.assertEqual(strip_url_params2("www.saadbenn.com?a=1&b=2&a=2"), "www.saadbenn.com?a=1&b=2")
self.assertEqual(strip_url_params2("www.saadbenn.com?a=1&b=2", ['b']), "www.saadbenn.com?a=1")
def test_strip_url_params3(self):
self.assertEqual(strip_url_params3("www.saadbenn.com?a=1&b=2&a=2"), "www.saadbenn.com?a=1&b=2")
self.assertEqual(strip_url_params3("www.saadbenn.com?a=1&b=2", ['b']), "www.saadbenn.com?a=1")


class TestValidateCoordinates(unittest.TestCase):
Expand Down

0 comments on commit 81e7853

Please sign in to comment.