This repository has been archived by the owner on Nov 6, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 49609cc
Showing
10 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pyc | ||
algo_venv/ |
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" Implementation of Bubble Sort. """ | ||
|
||
def sort(seq): | ||
|
||
for x in seq: | ||
temp = 0 | ||
for n in range(1, len(seq)): | ||
temp = seq[n] | ||
if seq[n] < seq[n-1]: | ||
seq[n] = seq[n-1] | ||
seq[n-1] = temp | ||
return seq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" Implementation of Insertion Sort """ | ||
|
||
def sort(seq): | ||
for n in range(1, len(seq)): | ||
item = seq[n] | ||
hole = n | ||
while hole > 0 and seq[ hole - 1] > item: | ||
seq[hole] = seq[hole - 1] | ||
hole = hole - 1 | ||
seq[hole] = item | ||
return seq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" Implementation of Selection Sort. """ | ||
|
||
def sort(seq): | ||
|
||
for i in range(0, len(seq)): | ||
minat = i | ||
minum = seq[i] | ||
for j in range(i+1, len(seq)): | ||
if minum > seq[j]: | ||
minat = j | ||
minum = seq[j] | ||
temp = seq[i] | ||
seq[i] = seq[minat] | ||
seq[minat] = temp | ||
|
||
return seq |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import random | ||
import unittest | ||
from ..sorting import bubble_sort, selection_sort, insertion_sort | ||
|
||
class TestBubbleSort(unittest.TestCase): | ||
""" | ||
Tests Bubble sort on a small range from 0-9 | ||
""" | ||
def test_bubblesort(self): | ||
self.seq = range(10) | ||
random.shuffle(self.seq) | ||
rv = bubble_sort.sort(self.seq) | ||
self.assertIs(self.seq[0], 0) | ||
self.assertIs(self.seq[-1], 9) | ||
|
||
class TestSelectionSort(unittest.TestCase): | ||
""" | ||
Tests Selection sort on a small range from 0-9 | ||
""" | ||
def test_selectionsort(self): | ||
self.seq = range(10) | ||
random.shuffle(self.seq) | ||
rv = selection_sort.sort(self.seq) | ||
self.assertIs(self.seq[0], 0) | ||
self.assertIs(self.seq[-1], 9) | ||
|
||
class TestInsertionSort(unittest.TestCase): | ||
""" | ||
Tests Insertion sort on a small range from 0-9 | ||
""" | ||
def test_selectionsort(self): | ||
self.seq = range(10) | ||
random.shuffle(self.seq) | ||
rv = insertion_sort.sort(self.seq) | ||
self.assertIs(self.seq[0], 0) | ||
self.assertIs(self.seq[-1], 9) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import nose | ||
|
||
if __name__ == '__main__': | ||
nose.main() |