Skip to content

Commit

Permalink
Closes #66
Browse files Browse the repository at this point in the history
This commit should make Travis fail the build (On purpose making it
fail to see if it spots when a test fails). Before, it was not failing
even though a test was failing.
  • Loading branch information
nbro committed Apr 2, 2018
1 parent 4879b89 commit e7c128f
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@ ands/algorithms/greedy/huffman.py
ands/algorithms/graphs/
/ands/algorithms/math/combinatorics/
/ands/algorithms/math/
/ands/algorithms/cg/

*.eggx
*.py[cod]
Expand Down
13 changes: 0 additions & 13 deletions .travis.yml
Expand Up @@ -8,22 +8,9 @@ python:
- 3.5
- 3.6

# command to install dependencies
install:
#- pip install matplotlib
- pip install coveralls
- pip install -e .

# For plots when testing.
# See: https://stackoverflow.com/a/35403128/3924118
#before_script: # configure a headless display to test plot generation
#- "export DISPLAY=:99.0"
#- "sh -e /etc/init.d/xvfb start"
#- sleep 3 # give xvfb some time to start

# command to run tests
script: scripts/travis.sh

after_success:
- coveralls

4 changes: 3 additions & 1 deletion ands/algorithms/README.md
Expand Up @@ -16,7 +16,9 @@ A few interesting algorithms which may be implemented in the future.

## Geometry

- [Line segment intersection](https://en.wikipedia.org/wiki/Line_segment_intersection)
### [Line-Segment Intersection](https://en.wikipedia.org/wiki/Line_segment_intersection)

- [Bentley–Ottmann algorithm](https://en.wikipedia.org/wiki/Bentley%E2%80%93Ottmann_algorithm)

### Convex Hull

Expand Down
6 changes: 3 additions & 3 deletions ands/algorithms/numerical/gradient_descent.py
Expand Up @@ -27,7 +27,7 @@
def gradient_descent(x0: float,
df: callable,
step_size: float = 0.01,
max_iter: int = 50,
max_iter: int = 100,
tol: float = 1e-6):
"""Finds a local minimum of a function whose derivative is df starting from
an initial guess x0 using a step size = step_size."""
Expand All @@ -36,8 +36,8 @@ def gradient_descent(x0: float,

x = x0

for _ in range(max_iter):
x_next = x + -step_size * df(x) # Gradient descent step.
for i in range(max_iter):
x_next = x - step_size * df(x) # Gradient descent step.

if abs(x_next - x) < tol * abs(x_next):
x = x_next
Expand Down
13 changes: 9 additions & 4 deletions ands/ds/LinearProbingHashTable.py
Expand Up @@ -8,7 +8,7 @@
Created: 01/06/2015
Updated: 28/09/2017
Updated: 02/04/2018
# Description
Expand Down Expand Up @@ -55,9 +55,9 @@
# References
- http://interactivepython.org/runestone/static/pythonds/SortSearch/Hashing.html
- http://stackoverflow.com/questions/279539/best-way-to-remove-an-entry-from-a-hash-table
- http://stackoverflow.com/questions/9835762/find-and-list-duplicates-in-a-list
- http://stackoverflow.com/questions/1541797/check-for-duplicates-in-a-flat-list
- https://stackoverflow.com/q/279539/3924118
- https://stackoverflow.com/q/9835762/3924118
- https://stackoverflow.com/q/1541797/3924118
- https://en.wikipedia.org/wiki/Associative_array
- https://en.wikipedia.org/wiki/Hash_table
- https://en.wikipedia.org/wiki/Hash_function
Expand Down Expand Up @@ -137,6 +137,8 @@ def put(self, key: object, value: object) -> None:

if key is None:
raise TypeError("key cannot be None.")
if not isinstance(key, Hashable):
raise TypeError("key must be an instance of a hashable type")

self._put(key, value, self._n)

Expand Down Expand Up @@ -213,6 +215,9 @@ def get(self, key: object) -> object:

if key is None:
raise TypeError("key cannot be None.")
if not isinstance(key, Hashable):
raise TypeError("key must be an instance of a hashable type")

value = LinearProbingHashTable._get(key, self._keys, self._values,
self._n)

Expand Down
3 changes: 2 additions & 1 deletion ands/ds/README.md
Expand Up @@ -19,7 +19,8 @@ A few interesting data structures which may be implemented in the future.

### Lists

- Skip list
- [Skip list](https://brilliant.org/wiki/skip-lists/)
- [Doubly connected edge list](https://en.wikipedia.org/wiki/Doubly_connected_edge_list)

## Trees

Expand Down
2 changes: 1 addition & 1 deletion scripts/run_tests.sh
Expand Up @@ -111,7 +111,7 @@ then

switch_to_virtual_environment

install_dependencies_in_virtual_environment coveralls pdoc "-e ."
install_dependencies_in_virtual_environment coveralls "-e ."

# If we have 3 parameters, then probably the user wants to execute a specific test.
if [ "$#" = "3" ]
Expand Down
1 change: 1 addition & 0 deletions scripts/travis.sh
Expand Up @@ -6,3 +6,4 @@ cd tests/
coverage run -m unittest discover . -v
mv .coverage ../.coverage
cd ../
coveralls
2 changes: 1 addition & 1 deletion tests/algorithms/numerical/test_gradient_descent.py
Expand Up @@ -36,4 +36,4 @@ def test_type_error_when_df_not_callable(self):
self.assertRaises(TypeError, gradient_descent, 0.3, 5)

def test_find_local_min_of_f(self):
self.assertAlmostEqual(gradient_descent(6, df), 9 / 4, 5)
self.assertAlmostEqual(gradient_descent(3, df), 9 / 4, 5)
36 changes: 18 additions & 18 deletions tests/ds/test_LinearProbingHashTable.py
Expand Up @@ -17,7 +17,7 @@
# Reference
- http://stackoverflow.com/questions/9755538/how-do-i-create-a-list-of-unique-random-numbers
- https://stackoverflow.com/q/9755538/3924118
"""

Expand Down Expand Up @@ -92,6 +92,13 @@ def test_get_key_None(self):
t = LinearProbingHashTable()
self.assertRaises(TypeError, t.get, None)

def test_get_non_hashable_type(self):
t = LinearProbingHashTable()
t.put(23, 31)
t.put(11, 13)
self.assertRaises(TypeError, t.get, [])
self.assertRaises(TypeError, t.get, {})

def test_get_empty_table(self):
t = LinearProbingHashTable()
self.assertIsNone(t.get(3))
Expand All @@ -107,13 +114,6 @@ def test_get_no_key_found(self):
t["four"] = 4
self.assertIsNone(t.get("five"))

def test_get_non_hashable_type(self):
t = LinearProbingHashTable()
t.put(23, 31)
t.put(11, 13)
self.assertRaises(TypeError, t.get, [])
self.assertRaises(TypeError, t.get, {})

def test_get_all(self):
t = LinearProbingHashTable()

Expand All @@ -129,6 +129,11 @@ def test_put_key_None(self):
t = LinearProbingHashTable()
self.assertRaises(TypeError, t.put, None, 5)

def test_put_non_hashable_type(self):
t = LinearProbingHashTable()
self.assertRaises(TypeError, t.put, [], 12)
self.assertRaises(TypeError, t.put, {}, None)

def test_put_key_not_None_value_None(self):
t = LinearProbingHashTable()
t.put(3, None)
Expand All @@ -141,11 +146,6 @@ def test_put_key_not_None_value_not_None(self):
self.assertTrue(t.size, 1)
self.assertEqual(t.get(5), 19)

def test_put_non_hashable_type(self):
t = LinearProbingHashTable()
self.assertRaises(TypeError, t.put, [], 12)
self.assertRaises(TypeError, t.put, {}, None)

def test_put_same_key_multiple_times(self):
t = LinearProbingHashTable()
t.put(3, "three")
Expand Down Expand Up @@ -189,6 +189,11 @@ def test_delete_key_None(self):
t = LinearProbingHashTable()
self.assertRaises(TypeError, t.delete, None)

def test_delete_non_hashable_type(self):
t = LinearProbingHashTable()
self.assertRaises(TypeError, t.delete, [])
self.assertRaises(TypeError, t.delete, {})

def test_delete_empty_table(self):
t = LinearProbingHashTable()
self.assertIsNone(t.delete(3))
Expand All @@ -198,11 +203,6 @@ def test_delete_key_not_present(self):
t.put(-10, "testing deletion when key not in the table")
self.assertIsNone(t.delete(7))

def test_delete_non_hashable_type(self):
t = LinearProbingHashTable()
self.assertRaises(TypeError, t.delete, [])
self.assertRaises(TypeError, t.delete, {})

def test_delete_some(self):
t = LinearProbingHashTable()
ls = [(1, 3), (5, "two"), (2.72, 10), ("one", 3.14), (1, "seven")]
Expand Down

0 comments on commit e7c128f

Please sign in to comment.