From f3a81781a9e13a77cb7bdc648f45074300a85f6f Mon Sep 17 00:00:00 2001 From: Joanna Hard Date: Tue, 1 Dec 2015 12:59:33 +0100 Subject: [PATCH 1/6] edit name in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 803b3d6..460a901 100644 --- a/README.md +++ b/README.md @@ -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/joannahard/python-tdd-exercises.svg?branch=master)](https://travis-ci.org/joannahard/python-tdd-exercises/builds) +[![Coverage Status](https://coveralls.io/repos/joannahard/python-tdd-exercises/badge.png?branch=master)](https://coveralls.io/r/joannahard/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. From e8f335f332d74abd539076f75edf374a42b88e81 Mon Sep 17 00:00:00 2001 From: Joanna Hard Date: Tue, 1 Dec 2015 12:59:44 +0100 Subject: [PATCH 2/6] please no emails --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4483e8c..fdabbdd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,3 +8,5 @@ install: script: - py.test -vv exercises.py --cov exercises - coveralls +notifications: + email: false From b6ac63b6cc8f40a13331095a23d7747dbc15d2ce Mon Sep 17 00:00:00 2001 From: Joanna Hard Date: Tue, 1 Dec 2015 13:00:08 +0100 Subject: [PATCH 3/6] fix some exercises --- exercises.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/exercises.py b/exercises.py index 38ef8b7..1612b97 100644 --- a/exercises.py +++ b/exercises.py @@ -3,20 +3,23 @@ def reverse_list(l): """ Reverses order of elements in list l. """ - return None + return list(reversed(l)) def test_reverse_list(): assert reverse_list([1, 2, 3, 4, 5]) == [5, 4, 3, 2, 1] + # ------------------------------------------------------------------------------ def reverse_string(s): """ Reverses order of characters in string s. """ - return None + return s[::-1] + + def test_reverse_string(): @@ -30,7 +33,9 @@ def is_english_vowel(c): Returns True if c is an english vowel and False otherwise. """ - return None + return (c == "a") or (c == "A") or (c == "e") or (c == "E") or (c == "i")\ + or (c == "I") or (c == "o") or (c == "O") or (c == "u") or (c == "U") or (c == "y") or (c == "Y")\ + def test_is_english_vowel(): @@ -49,15 +54,19 @@ def test_is_english_vowel(): assert not is_english_vowel('k') assert not is_english_vowel('z') assert not is_english_vowel('?') - + # ------------------------------------------------------------------------------ - +#vowels = ("a", "e", "i", "o", "u", "A", "E", "I", "O", "U") def count_num_vowels(s): """ Returns the number of vowels in a string s. """ - return None + n = 0 + for c in s: + if is_english_vowel(c): + n += 1 + return n def test_count_num_vowels(): From ef8544074721c1da99759f1760f82765afaa9f91 Mon Sep 17 00:00:00 2001 From: Joanna Hard Date: Wed, 2 Dec 2015 09:27:55 +0100 Subject: [PATCH 4/6] fix some exercises 2 --- exercises.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/exercises.py b/exercises.py index 1612b97..b0993e0 100644 --- a/exercises.py +++ b/exercises.py @@ -102,6 +102,8 @@ def get_word_lengths(s): Returns a list of integers representing the word lengths in string s. """ + + return None @@ -134,7 +136,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 + + for letter in s: + if not letter in "agtcAGTC": + return False + return True + + def test_validate_dna(): @@ -153,6 +161,9 @@ def base_pair(c): return None + + + def test_base_pair(): assert base_pair('a') == 't' assert base_pair('t') == 'a' @@ -173,7 +184,9 @@ def transcribe_dna_to_rna(s): Return string s with each letter T replaced by U. Result is always uppercase. """ - return None + + return s.replace('T', 'U') + return s.upper def test_transcribe_dna_to_rna(): @@ -189,7 +202,8 @@ def get_complement(s): (A -> T, T-> A, C -> G, G-> C). """ return None - + my_dictionary = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'} + return reversed(s) def test_get_complement(): assert get_complement('CCGGAAGAGCTTACTTAG') == 'GGCCTTCTCGAATGAATC' From 93917e15df747b1886835685739523063523b695 Mon Sep 17 00:00:00 2001 From: Joanna Hard Date: Wed, 2 Dec 2015 11:57:51 +0100 Subject: [PATCH 5/6] fix some exercises 3 --- exercises.py | 110 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 91 insertions(+), 19 deletions(-) diff --git a/exercises.py b/exercises.py index b0993e0..fe45240 100644 --- a/exercises.py +++ b/exercises.py @@ -88,9 +88,12 @@ def histogram(l): """ Converts a list of integers into a simple string histogram. """ - return None - + s= [] + for i in l: + s.append("#"*i) + return '\n'.join(s) + def test_histogram(): assert histogram([2, 5, 1]) == '##\n#####\n#' @@ -102,9 +105,12 @@ def get_word_lengths(s): Returns a list of integers representing the word lengths in string s. """ - + l = [] + for word in s.split(): + l.append(len(word)) + return l + - return None def test_get_word_lengths(): @@ -119,7 +125,13 @@ def find_longest_word(s): Returns the longest word in string s. In case there are several, return the first. """ - return None + + + longest = '' + for w in s.split(): + if len(w) > len(longest): + longest = w + return longest def test_find_longest_word(): @@ -158,9 +170,11 @@ def base_pair(c): of the base pair. If the base is not recognized, return 'unknown'. """ - return None - - + d = {'a':'t', 't':'a', 'g':'c', 'c':'g'} + if c.lower() in d: + return d[c.lower()] + else: + return 'unknown' @@ -185,8 +199,9 @@ def transcribe_dna_to_rna(s): Result is always uppercase. """ - return s.replace('T', 'U') - return s.upper + + + return s.upper().replace('T', 'U') def test_transcribe_dna_to_rna(): @@ -201,9 +216,13 @@ def get_complement(s): Return the DNA complement in uppercase (A -> T, T-> A, C -> G, G-> C). """ - return None + + my_dictionary = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'} - return reversed(s) + s_comp= '' + for c in s: + s_comp += base_pair(c) + return s_comp.upper() def test_get_complement(): assert get_complement('CCGGAAGAGCTTACTTAG') == 'GGCCTTCTCGAATGAATC' @@ -217,7 +236,9 @@ def get_reverse_complement(s): Return the reverse complement of string s (complement reversed in order). """ - return None + + return reverse_string(get_complement(s)) + def test_get_reverse_complement(): @@ -231,7 +252,10 @@ def remove_substring(substring, string): """ Returns string with all occurrences of substring removed. """ - return None + + + + return string.replace(substring, '') def test_remove_substring(): @@ -249,7 +273,13 @@ 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 + + + l = [] + for i in range(len(dna)//3): + if triplet == dna[i*3:i*3+3]: + l.append(i) + return l def test_get_position_indices(): @@ -268,7 +298,16 @@ def get_3mer_usage_chart(s): The list is alphabetically sorted by the name of the 3-mer. """ - return None + + d = {} + for i in range(len(s) - 2): + kmer = s[i:i+3] + if kmer in d: + d[kmer] += 1 + else: d[kmer] = 1 + l = list(d.items()) + l.sort() + return l def test_get_3mer_usage_chart(): @@ -299,7 +338,15 @@ 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 = [] + with open(file_name, 'r') as f: + for line in f: + words= line.split() + if len(words) > 0: + l.append(float(words[column_number -1])) + return l + + def test_read_column(): @@ -338,7 +385,20 @@ def character_statistics(file_name): Use the isalpha() method to figure out whether the character is in the alphabet. """ - return None + + #d={} + #with open(file_name, 'r') as f: + #for c in f.read().lower(): + #if c.isalpha(): + #if c in d: + #d[c] += 1 + #else: + #d[c] = 1 + #l= list(d.items()) + #l = sorted(l, key=lambda x: x[1], reverse=True) + #most=l[0] + #least= l[-1 ][0] + #return (most, least) def test_character_statistics(): @@ -347,7 +407,7 @@ def test_character_statistics(): import os text = """ -To be, or not to be: that is the question: +To be, z or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, @@ -400,6 +460,9 @@ def test_character_statistics(): def pythagorean_triples(n): """ + + + Returns list of all unique pythagorean triples (a, b, c) where a < b < c <= n. """ @@ -413,7 +476,16 @@ def pythagorean_triples(n): return l + + + + + # ------------------------------------------------------------------------------ def test_pythagorean_triples(): + assert pythagorean_triples(20) == [] + + + pass # so far we do not test anything, check also test coverage From 0019bf2250adce2546555f0e4328be42f315ff1f Mon Sep 17 00:00:00 2001 From: Joanna Hard Date: Wed, 2 Dec 2015 12:11:19 +0100 Subject: [PATCH 6/6] finished day 1 --- exercises.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/exercises.py b/exercises.py index fe45240..b86a51c 100644 --- a/exercises.py +++ b/exercises.py @@ -386,19 +386,19 @@ def character_statistics(file_name): whether the character is in the alphabet. """ - #d={} - #with open(file_name, 'r') as f: - #for c in f.read().lower(): - #if c.isalpha(): - #if c in d: - #d[c] += 1 - #else: - #d[c] = 1 - #l= list(d.items()) - #l = sorted(l, key=lambda x: x[1], reverse=True) - #most=l[0] - #least= l[-1 ][0] - #return (most, least) + d={} + with open(file_name, 'r') as f: + for c in f.read().lower(): + if c.isalpha(): + if c in d: + d[c] += 1 + else: + d[c] = 1 + l= list(d.items()) + l = sorted(l, key=lambda x: x[1], reverse=True) + most=l[0][0] + least= l[-1 ][0] + return (most, least) def test_character_statistics(): @@ -484,7 +484,7 @@ def pythagorean_triples(n): # ------------------------------------------------------------------------------ def test_pythagorean_triples(): - assert pythagorean_triples(20) == [] + assert pythagorean_triples(20) == [(3, 4, 5), (6, 8, 10), (5, 12, 13), (9, 12, 15), (8, 15, 17), (12, 16, 20)]