Skip to content

Commit

Permalink
Merge 8e4eb0c into 7dd36c0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwennid committed Dec 2, 2015
2 parents 7dd36c0 + 8e4eb0c commit b030637
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 27 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -2,8 +2,8 @@

## Make these badges green

[![Build Status](https://travis-ci.org/bast/python-tdd-exercises.svg?branch=master)](https://travis-ci.org/bast/python-tdd-exercises/builds)
[![Coverage Status](https://coveralls.io/repos/bast/python-tdd-exercises/badge.png?branch=master)](https://coveralls.io/r/bast/python-tdd-exercises?branch=master)
[![Build Status](https://travis-ci.org/Gwennid/python-tdd-exercises.svg?branch=master)](https://travis-ci.org/Gwennid/python-tdd-exercises/builds)
[![Coverage Status](https://coveralls.io/repos/Gwennid/python-tdd-exercises/badge.png?branch=master)](https://coveralls.io/r/Gwennid/python-tdd-exercises?branch=master)

After you fork, edit this `README.md` and rename "bast" to your GitHub username
or namespace to make the badges point to your fork.
Expand All @@ -22,7 +22,7 @@ or namespace to make the badges point to your fork.
- Login to [Travis CI](https://travis-ci.org) with your GitHub account and activate this repo for testing.
- Login to [Coveralls](https://coveralls.io) with your GitHub account and activate this repo for code coverage analysis.
- Implement missing functions to make the unit tests pass (run tests either locally or let Travis run them for you each time you push changes).
- Increase the test coverage to 100% by making [all lines](https://coveralls.io/r/bast/python-tdd-exercises?branch=master) green.
- Increase the test coverage to 100% by making [all lines](https://coveralls.io/r/Gwennid/python-tdd-exercises?branch=master) green.


## How to run tests locally (Linux or Mac OS X)
Expand Down
140 changes: 116 additions & 24 deletions exercises.py
@@ -1,10 +1,11 @@

def reverse_list(l):
"""
Reverses order of elements in list l.
"""
return None

"""Reverses order of elements in list l."""
max=len(l)
L=[0]*max
for i in range(1,(max+1)):
L[i-1]=l[max-i]
return(L)

def test_reverse_list():
assert reverse_list([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1]
Expand All @@ -16,7 +17,7 @@ def reverse_string(s):
"""
Reverses order of characters in string s.
"""
return None
return(s[::-1])


def test_reverse_string():
Expand All @@ -30,7 +31,8 @@ def is_english_vowel(c):
Returns True if c is an english vowel
and False otherwise.
"""
return None
vowels="aeiouyAEIOUY"
return(c in vowels)


def test_is_english_vowel():
Expand All @@ -57,7 +59,13 @@ def count_num_vowels(s):
"""
Returns the number of vowels in a string s.
"""
return None
vowels="aeiouyAEIOUY"
S=0
max=len(s)
for i in range(0,max):
if s[i] in vowels:
S=S+1
return(S)


def test_count_num_vowels():
Expand All @@ -79,7 +87,11 @@ def histogram(l):
"""
Converts a list of integers into a simple string histogram.
"""
return None
list=[0]*(len(l)*2-1)
for i in range(0,len(l)):
list[(i*2):((i*2)+2)]=['#'*l[i],'\n']
hist=''.join(list[0:(len(l)*2-1)])
return(hist)


def test_histogram():
Expand All @@ -93,7 +105,11 @@ def get_word_lengths(s):
Returns a list of integers representing
the word lengths in string s.
"""
return None
ssplit=s.split()
L=[0]*len(ssplit)
for i in range(0,len(ssplit)):
L[i]=len(ssplit[i])
return(L)


def test_get_word_lengths():
Expand All @@ -108,7 +124,14 @@ def find_longest_word(s):
Returns the longest word in string s.
In case there are several, return the first.
"""
return None
ssplit=s.split()
longest=len(ssplit[0])
indice=0
for i in range(1,len(ssplit)):
if len(ssplit[i])>longest:
longest=len(ssplit[i])
indice=i
return(ssplit[indice])


def test_find_longest_word():
Expand All @@ -125,7 +148,13 @@ def validate_dna(s):
Return True if the DNA string only contains characters
a, c, t, or g (lower or uppercase). False otherwise.
"""
return None
dna='actgACTG'
L=len(s)
sum=0
for i in range(0,L):
if s[i] in dna:
sum+=1
return(L==sum)


def test_validate_dna():
Expand All @@ -142,8 +171,11 @@ def base_pair(c):
of the base pair. If the base is not recognized,
return 'unknown'.
"""
return None

basepair={'a':'t','A':'t','c':'g','C':'g','g':'c','G':'c','t':'a','T':'a'}
if c in 'actgACTG':
return(basepair[c])
else:
return('unknown')

def test_base_pair():
assert base_pair('a') == 't'
Expand All @@ -165,7 +197,14 @@ def transcribe_dna_to_rna(s):
Return string s with each letter T replaced by U.
Result is always uppercase.
"""
return None
rna=[0]*len(s)
translation={'a':'A','c':'C','t':'U','T':'U','g':'G'}
for i in range(0,len(s)):
if s[i] in 'ACG':
rna[i]=s[i]
else:
rna[i]=translation[s[i]]
return(''.join(rna))


def test_transcribe_dna_to_rna():
Expand All @@ -180,7 +219,11 @@ def get_complement(s):
Return the DNA complement in uppercase
(A -> T, T-> A, C -> G, G-> C).
"""
return None
complement={'a':'T','A':'T','c':'G','C':'G','g':'C','G':'C','t':'A','T':'A'}
com=[0]*len(s)
for i in range(0,len(s)):
com[i]=complement[s[i]]
return(''.join(com))


def test_get_complement():
Expand All @@ -195,7 +238,12 @@ def get_reverse_complement(s):
Return the reverse complement of string s
(complement reversed in order).
"""
return None
complement={'a':'T','A':'T','c':'G','C':'G','g':'C','G':'C','t':'A','T':'A'}
max=len(s)
rev=[0]*max
for i in range(1,(max+1)):
rev[i-1]=complement[s[max-i]]
return(''.join(rev))


def test_get_reverse_complement():
Expand All @@ -209,7 +257,12 @@ def remove_substring(substring, string):
"""
Returns string with all occurrences of substring removed.
"""
return None
L=[]
ite=int(len(string)/len(substring))
for i in range(0,ite):
if string[(i*3):(i*3+3)]!=substring:
L+=string[(i*3):(i*3+3)]
return(''.join(L))


def test_remove_substring():
Expand All @@ -227,7 +280,12 @@ def get_position_indices(triplet, dna):
in a DNA sequence. We start counting from 0
and jump by 3 characters from one position to the next.
"""
return None
ite=int(len(dna)/3)
L=[]
for i in range(0,ite):
if dna[(i*3):(i*3+3)]==triplet:
L+=[i]
return(L)


def test_get_position_indices():
Expand All @@ -246,7 +304,17 @@ def get_3mer_usage_chart(s):
The list is alphabetically sorted by the name
of the 3-mer.
"""
return None
triplets={}
for i in range(0,len(s)-2):
if s[i:i+3] in triplets:
triplets[s[i:i+3]]+=1
else:
triplets[s[i:i+3]]=1
sort_triplets=sorted(triplets)
L=[]
for j in sort_triplets:
L+=[(j,triplets[j])]
return(L)


def test_get_3mer_usage_chart():
Expand Down Expand Up @@ -277,7 +345,11 @@ def read_column(file_name, column_number):
Reads column column_number from file file_name
and returns the values as floats in a list.
"""
return None
L=[]
for line in open(file_name):
column = line.split()
L.append(float(column[column_number - 1]))
return(L)


def test_read_column():
Expand Down Expand Up @@ -315,7 +387,24 @@ def character_statistics(file_name):
Use the isalpha() method to figure out
whether the character is in the alphabet.
"""
return None
fo = open(file_name,'r')
text = fo.readlines()
text = ''.join(text)
from collections import Counter
count = Counter(c for c in text.lower() if c.isalpha())
max=count['a']
min=count['a']
ind_max='a'
ind_min='a'
for i in ('b','c','d','e','f','g','h','i','q','j','k','l','m','n','o','p','r','s','t','u','v','w','x','y','z'):
if 0<count[i]<min:
min=count[i]
ind_min=i
elif count[i]>max:
max=count[i]
ind_max=i
out = (ind_max,ind_min)
return(out)


def test_character_statistics():
Expand Down Expand Up @@ -377,7 +466,7 @@ def test_character_statistics():

def pythagorean_triples(n):
"""
Returns list of all unique pythagorean triples
Returns list of all unique pythagorean triples (a^2 + b^2 = c^2)
(a, b, c) where a < b < c <= n.
"""
l = []
Expand All @@ -393,4 +482,7 @@ def pythagorean_triples(n):
# ------------------------------------------------------------------------------

def test_pythagorean_triples():
pass # so far we do not test anything, check also test coverage
assert pythagorean_triples(6) == [(3,4,5)]
assert pythagorean_triples(15) == [(3, 4, 5), (6, 8, 10), (5, 12, 13), (9, 12, 15)]
assert pythagorean_triples(20) != [(3, 4, 5), (6, 8, 10), (5, 12, 13), (9, 12, 15)]
# so far we do not test anything, check also test coverage

0 comments on commit b030637

Please sign in to comment.