Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0aa9122

Browse files
Merge pull request #33 from AladdinPerzon/AddTesting
Added a lot of test cases for many algorithms & cleaned up code on many algorithms
2 parents 4fc62fb + c730e8c commit 0aa9122

File tree

61 files changed

+1244
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1244
-436
lines changed

‎.travis.yml‎

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,54 @@ python: 3.7
55

66
# Install ruby to get gem command
77
before_install:
8-
- sudo apt-add-repository -y ppa:brightbox/ruby-ng
9-
- sudo apt-get -y update
10-
- sudo apt-get -y install ruby-full
11-
12-
#before_install:
13-
# - cd Algorithm_tests/sorting_tests
14-
# Install awesome_bot for README.md broken link checking
8+
- python --version
9+
- pip install -U pip
10+
- pip install -U pytest
11+
- pip install codecov
12+
- sudo apt-add-repository -y ppa:brightbox/ruby-ng
13+
- sudo apt-get -y update
14+
- sudo apt-get -y install ruby-full
1515

1616
before_script:
17-
- gem install awesome_bot
17+
- gem install awesome_bot
18+
19+
install:
20+
- pip3 install -r requirements.txt
21+
- pip3 install pytest
22+
- pip3 install pytest-cov
23+
- pip3 install codecov
24+
25+
script: pytest --cov=Algorithm_tests/
26+
# - awesome_bot README.md --allow-dupe --allow-redirect
27+
# # Dynamic Programming Tests
28+
# - python Algorithm_tests/dynamic_programming_tests/knapsack_tests/knapsack_bottomup_test.py
29+
# - python Algorithm_tests/dynamic_programming_tests/sequence_alignment/sequence_alignment_test.py
30+
# - python Algorithm_tests/dynamic_programming_tests/weighted_interval_scheduling/weighted_interval_scheduling_test.py
31+
#
32+
# # Graph Theory Tests
33+
# - python Algorithm_tests/graphtheory_tests/bellman_ford_test.py
34+
# - python Algorithm_tests/graphtheory_tests/kahn_topological_ordering_test.py
35+
# - python Algorithm_tests/graphtheory_tests/Djikstra/djikstra_heap_test.py
36+
# - python Algorithm_tests/graphtheory_tests/Djikstra/djikstra_naive_test.py
37+
# - python Algorithm_tests/graphtheory_tests/kruskal_unionfind_test.py
38+
# - python Algorithm_tests/graphtheory_tests/prims_algorithm_test.py
39+
# - python Algorithm_tests/graphtheory_tests/BFS_test.py
40+
# - python Algorithm_tests/graphtheory_tests/DFS_test.py
41+
#
42+
# # Math tests
43+
# - python Algorithm_tests/other_tests/test_binarysearch.py
44+
# - python Algorithm_tests/math_tests/intersection_test.py
45+
# - python Algorithm_tests/math_tests/union_test.py
46+
#
47+
# # Cryptography tests
48+
# - python Algorithm_tests/cryptology_tests/ceasar_test.py
49+
#
50+
# # "Other" tests
51+
# - python Algorithm_tests/other_tests/test_medianmaintenance.py
52+
# - python Algorithm_tests/other_tests/test_intervalscheduling.py
53+
#
54+
# # Sorting tests
55+
# - python Algorithm_tests/sorting_tests/test_sorting.py
1856

19-
script:
20-
- awesome_bot README.md --allow-dupe --allow-redirect
21-
- python Algorithm_tests/sorting_tests/test_sorting.py
22-
- python Algorithm_tests/graphtheory_tests/bellman_ford_test.py
23-
- python Algorithm_tests/search_tests/test_binarysearch.py
24-
- python Algorithm_tests/math_tests/intersection_test.py
25-
- python Algorithm_tests/math_tests/union_test.py
26-
- python Algorithm_tests/cryptology_tests/ceasar_test.py
57+
after_success:
58+
- codecov
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import sys
2+
import unittest
3+
4+
# For importing from different folders
5+
# OBS: This is supposed to be done with automated testing, hence relative to folder we want to import from
6+
sys.path.append('Algorithms/dynamic_programming/knapsack')
7+
8+
# If run from local:
9+
#sys.path.append('../../../Algorithms/dynamic_programming/knapsack/')
10+
from knapsack_bottomup import knapsack
11+
12+
class test_KnapSack(unittest.TestCase):
13+
def setUp(self):
14+
self.weights1, self.values1, self.capacity1 = [], [], 100
15+
self.n1 = len(self.weights1)
16+
self.correctvalue1, self.correctitems1 = 0, []
17+
18+
self.weights2, self.values2, self.capacity2 = [10], [50], 100
19+
self.n2 = len(self.weights2)
20+
self.correctvalue2, self.correctitems2 = 50, [0]
21+
22+
self.weights3, self.values3, self.capacity3 = [10, 20, 30], [-10, -20, -30], 100
23+
self.n3 = len(self.weights2)
24+
self.correctvalue3, self.correctitems3 = 0, []
25+
26+
self.weights4, self.values4, self.capacity4 = [1, 2, 4, 2, 5], [5, 3, 5, 3, 2], 5
27+
self.n4 = len(self.weights4)
28+
self.correctvalue4, self.correctitems4 = 11, [0, 1, 3]
29+
30+
self.weights5, self.values5, self.capacity5 = [10, 10, 10], [30, 30, 30], 5
31+
self.n5 = len(self.weights5)
32+
self.correctvalue5, self.correctitems5 = 0, []
33+
34+
def test_noitems(self):
35+
total_value, items = knapsack(self.n1, self.capacity1, self.weights1, self.values1)
36+
self.assertEqual(self.correctvalue1, total_value)
37+
self.assertEqual(self.correctitems1, items)
38+
39+
def test_singleitem_value(self):
40+
total_value, items = knapsack(self.n2, self.capacity2, self.weights2, self.values2)
41+
self.assertEqual(self.correctvalue2, total_value)
42+
self.assertEqual(self.correctitems2, items)
43+
44+
def test_negativevalues(self):
45+
total_value, items = knapsack(self.n3, self.capacity3, self.weights3, self.values3)
46+
self.assertEqual(self.correctvalue3, total_value)
47+
self.assertEqual(self.correctitems3, items)
48+
49+
def test_simpleexample(self):
50+
total_value, items = knapsack(self.n4, self.capacity4, self.weights4, self.values4)
51+
self.assertEqual(self.correctvalue4, total_value)
52+
self.assertEqual(self.correctitems4, items)
53+
54+
def test_weight_too_heavy(self):
55+
total_value, items = knapsack(self.n5, self.capacity5, self.weights5, self.values5)
56+
self.assertEqual(self.correctvalue5, total_value)
57+
self.assertEqual(self.correctitems5, items)
58+
59+
if __name__ == '__main__':
60+
print("Running Knapsack tests:")
61+
unittest.main()

‎Algorithm_tests/dynamic_programming_tests/knapsack_tests/knapsack_tests.py‎

Lines changed: 0 additions & 37 deletions
This file was deleted.

‎Algorithm_tests/dynamic_programming_tests/knapsack_tests/p01_c.txt‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎Algorithm_tests/dynamic_programming_tests/knapsack_tests/p01_p.txt‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎Algorithm_tests/dynamic_programming_tests/knapsack_tests/p01_w.txt‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎Algorithm_tests/dynamic_programming_tests/knapsack_tests/p08_c.txt‎

Lines changed: 0 additions & 1 deletion
This file was deleted.

‎Algorithm_tests/dynamic_programming_tests/knapsack_tests/p08_p.txt‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎Algorithm_tests/dynamic_programming_tests/knapsack_tests/p08_w.txt‎

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import sys
2+
import unittest
3+
4+
# For importing from different folders
5+
# OBS: This is supposed to be done with automated testing, hence relative to folder we want to import from
6+
sys.path.append('Algorithms/dynamic_programming/')
7+
8+
# If run from local:
9+
#sys.path.append('../../../Algorithms/dynamic_programming/')
10+
from sequence_alignment import SequenceAlignment
11+
12+
class test_sequence_alignment(unittest.TestCase):
13+
def setUp(self):
14+
self.x1 = 'ABC'
15+
self.y1 = 'ADC'
16+
self.correct_editstep1 = 1
17+
18+
self.x2 = 'AB'
19+
self.y2 = 'A'
20+
self.correct_editstep2 = 1
21+
22+
self.x3 = 'A'
23+
self.y3 = ''
24+
self.correct_editstep3 = 1
25+
26+
self.x4 = 'ABC'
27+
self.y4 = 'ABCDE'
28+
self.correct_editstep4 = 2
29+
30+
self.x5 = 'ABCKL'
31+
self.y5 = 'ADCE'
32+
self.correct_editstep5 = 3
33+
34+
self.x6 = 'A'*10
35+
self.y6 = ''
36+
self.correct_editstep6 = 10
37+
38+
self.x7 = ''
39+
self.y7 = 'A' * 10
40+
self.correct_editstep7 = 10
41+
42+
self.x8 = 'TGACGTGC'
43+
self.y8 = 'TCGACGTCA'
44+
self.correct_editstep8 = 3
45+
46+
self.x9 = 'XYZ'
47+
self.y9 = 'XKZ'
48+
self.correct_solution9 = ['align_X', 'align_K', 'align_Z']
49+
50+
self.x10 = 'XX'
51+
self.y10 = ''
52+
self.correct_solution10 = ['remove_X', 'remove_X']
53+
54+
self.x11 = ''
55+
self.y11 = 'XX'
56+
self.correct_solution11 = ['insert_X', 'insert_X']
57+
58+
def test_simplecase(self):
59+
sequence_align = SequenceAlignment(self.x1, self.y1)
60+
editsteps, _ = sequence_align.alignment()
61+
self.assertEqual(self.correct_editstep1, editsteps)
62+
63+
def test_remove(self):
64+
sequence_align = SequenceAlignment(self.x2, self.y2)
65+
editsteps, _ = sequence_align.alignment()
66+
self.assertEqual(self.correct_editstep2, editsteps)
67+
68+
def test_remove_to_empty(self):
69+
sequence_align = SequenceAlignment(self.x3, self.y3)
70+
editsteps, _ = sequence_align.alignment()
71+
self.assertEqual(self.correct_editstep3, editsteps)
72+
73+
def test_insert_elements(self):
74+
sequence_align = SequenceAlignment(self.x4, self.y4)
75+
editsteps, _ = sequence_align.alignment()
76+
self.assertEqual(self.correct_editstep4, editsteps)
77+
78+
def test_remove_insert_align(self):
79+
sequence_align = SequenceAlignment(self.x5, self.y5)
80+
editsteps, _ = sequence_align.alignment()
81+
self.assertEqual(self.correct_editstep5, editsteps)
82+
83+
def test_x_longer_than_y(self):
84+
sequence_align = SequenceAlignment(self.x6, self.y6)
85+
editsteps, _ = sequence_align.alignment()
86+
self.assertEqual(self.correct_editstep6, editsteps)
87+
88+
def test_y_longer_than_x(self):
89+
sequence_align = SequenceAlignment(self.x7, self.y7)
90+
editsteps, _ = sequence_align.alignment()
91+
self.assertEqual(self.correct_editstep7, editsteps)
92+
93+
def test_more_complicated_example(self):
94+
sequence_align = SequenceAlignment(self.x8, self.y8)
95+
editsteps, _ = sequence_align.alignment()
96+
self.assertEqual(self.correct_editstep8, editsteps)
97+
98+
def test_findsolution_simplecase(self):
99+
sequence_align = SequenceAlignment(self.x9, self.y9)
100+
_, solution = sequence_align.alignment()
101+
self.assertEqual(self.correct_solution9, solution)
102+
103+
def test_findsolution_empty_y(self):
104+
sequence_align = SequenceAlignment(self.x10, self.y10)
105+
_, solution = sequence_align.alignment()
106+
self.assertEqual(self.correct_solution10, solution)
107+
108+
def test_findsolution_empty_x(self):
109+
sequence_align = SequenceAlignment(self.x11, self.y11)
110+
_, solution = sequence_align.alignment()
111+
self.assertEqual(self.correct_solution11, solution)
112+
113+
if __name__ == '__main__':
114+
print("Running Sequence Alignment tests:")
115+
unittest.main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /