Skip to content

Commit

Permalink
g
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomlogo committed Mar 14, 2024
1 parent 64fcafb commit 25f6c00
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
12 changes: 6 additions & 6 deletions flax/funcs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""funcs: holds the functions used by atoms"""

import functools
import urllib.request
import itertools
import more_itertools
import copy
Expand Down Expand Up @@ -279,11 +280,10 @@ def flatten(x):

def get_req(x):
"""get_req: GET request for url x"""
url = "".join(map(chr, x))
url = (
re.match(r"[A-Za-z][A-Za-z0-9+.-]*://", url) is None and "http://" or ""
) + url
response = urllib_request.request.urlopen(url).read()
re.match(r"[A-Za-z][A-Za-z0-9+.-]*://", x) is None and "http://" or ""
) + x
response = urllib.request.urlopen(url).read()
try:
return response.decode("utf-8")
except:
Expand All @@ -294,7 +294,7 @@ def grade_down(x):
"""grade_down: grade x in descending order"""
x = iterable(x, digits_=True)
grades = []
for i in reversed(sorted(x)):
for i in more_itertools.unique_everseen(reversed(sorted(x))):
grades.append(find_all(i, x))
return flatten(grades)

Expand All @@ -303,7 +303,7 @@ def grade_up(x):
"""grade_up: grade x in ascending order"""
x = iterable(x, digits_=True)
grades = []
for i in sorted(x):
for i in more_itertools.unique_everseen(sorted(x)):
grades.append(find_all(i, x))
return flatten(grades)

Expand Down
32 changes: 27 additions & 5 deletions test/test_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,33 @@ def test_flatten():
assert flatten(1) == [1]


"test_get_req"
"test_grade_down"
"test_grade_up"
"test_group_equal"
"test_group_indicies"
def test_get_req():
assert "google" in get_req("google.com")

def test_grade_down():
assert grade_down([]) == []
assert grade_down([2, 3, 1]) == [1,0,2]
assert grade_down([7,0,9,3,8,0,9,5,4,1]) == [2,6,4,0,7,8,3,9,1,5]
assert grade_down(grade_down([7,0,9,3,8,0,9,5,4,1])) == [7,5,4,1,9,2,6,0,8,3]

def test_grade_up():
assert grade_up([]) == []
assert grade_up([2, 3, 1]) == [2,0,1]
assert grade_up([7,0,9,3,8,0,9,5,4,1]) == [1,5,9,3,8,7,0,4,2,6]
assert grade_up(grade_up([7,0,9,3,8,0,9,5,4,1])) == [6,0,8,3,7,1,9,5,4,2]

def test_group_equal():
assert group_equal([]) == []
assert group_equal([1, 2, 3]) == [[1], [2], [3]]
assert group_equal([2, 3, 1]) == [[2], [3], [1]]
assert group_equal([1, 2, 2, 3, 4, 4, 3]) == [[1],[2,2],[3],[4,4],[3]]

def test_group_indicies():
assert group_indicies([]) == []
assert group_indicies([1, 2, 3]) == [[0], [1], [2]]
assert group_indicies([3, 2, 1]) == [[2], [1], [0]]
assert group_indicies([1, 2, 2, 3, 4, 4, 3]) == [[0],[1,2],[3,6],[4,5]]

"test_index_into"
"test_index_into_md"
"test_iota"
Expand Down

0 comments on commit 25f6c00

Please sign in to comment.