forked from YearOfProgramming/2017Challenges
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
2 changed files
with
47 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,23 @@ | ||
def square_n_sort(L): | ||
|
||
L_square = [] | ||
L_sorted = [] | ||
count = len(L) | ||
|
||
if L[0] >= 0: | ||
for i in L: | ||
L_square.append(i**2) | ||
return L_square | ||
|
||
while count > 0: | ||
if abs(L[0]) >= abs(L[-1]): | ||
L_square.append(L[0]**2) | ||
L.remove(L[0]) | ||
else: | ||
L_square.append(L[-1]**2) | ||
L.remove(L[-1]) | ||
count -= 1 | ||
|
||
L_sorted = L_square[::-1] | ||
|
||
return L_sorted |
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,24 @@ | ||
# we start by importing the unittest module | ||
import unittest | ||
|
||
# Next lets import our function that we intend to do testing on | ||
# | ||
# **We could also import all functions by using * or just import the module | ||
# itself but for now lets just import the function | ||
from challenge_9 import square_n_sort | ||
|
||
# lets define our suite of tests as a class and lets inherit from unittest.TestCase | ||
class TestBinaryMethods(unittest.TestCase): | ||
|
||
def test_squareSort(self): | ||
""" Tests from the READ.me """ | ||
|
||
self.assertEqual(square_n_sort([0,1,2]), [0,1,4]) | ||
self.assertEqual(square_n_sort([-5,-4,-3,-2]), [4,9,16,25]) | ||
self.assertEqual(square_n_sort([1,2]), [1,4]) | ||
self.assertEqual(square_n_sort([-2,-1,0,1,2]), [0,1,1,4,4]) | ||
|
||
# if the python file is ran by itself run unittest | ||
# This allows us to import the members of the file without running main if we need to | ||
if __name__ == '__main__': | ||
unittest.main() |