trackler 2.0.8.27 → 2.0.8.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/common/exercises/simple-cipher/description.md +1 -1
- data/common/exercises/triangle/description.md +12 -23
- data/lib/trackler/version.rb +1 -1
- data/tracks/kotlin/config.json +5 -0
- data/tracks/kotlin/exercises/bank-account/build.gradle +32 -0
- data/tracks/kotlin/exercises/bank-account/src/example/kotlin/BankAccount.kt +27 -0
- data/tracks/kotlin/exercises/bank-account/src/main/kotlin/.keep +0 -0
- data/tracks/kotlin/exercises/bank-account/src/test/kotlin/BankAccountTest.kt +73 -0
- data/tracks/kotlin/exercises/settings.gradle +1 -0
- data/tracks/python/config.json +11 -11
- data/tracks/python/exercises/accumulate/accumulate_test.py +16 -14
- data/tracks/python/exercises/acronym/acronym_test.py +8 -7
- data/tracks/python/exercises/allergies/allergies_test.py +5 -6
- data/tracks/python/exercises/atbash-cipher/atbash_cipher_test.py +16 -22
- data/tracks/python/exercises/binary-search/binary_search_test.py +12 -10
- data/tracks/python/exercises/binary/binary_test.py +7 -8
- data/tracks/python/exercises/circular-buffer/circular_buffer_test.py +16 -17
- data/tracks/python/exercises/clock/clock_test.py +35 -35
- data/tracks/python/exercises/crypto-square/crypto_square_test.py +5 -6
- data/tracks/python/exercises/diamond/diamond_test.py +3 -4
- data/tracks/python/exercises/etl/etl_test.py +4 -4
- data/tracks/python/exercises/gigasecond/gigasecond_test.py +11 -19
- data/tracks/python/exercises/grade-school/grade_school_test.py +17 -19
- data/tracks/python/exercises/grains/grains_test.py +14 -14
- data/tracks/python/exercises/grep/grep_test.py +51 -64
- data/tracks/python/exercises/hamming/hamming_test.py +13 -13
- data/tracks/python/exercises/hello-world/hello_world_test.py +1 -2
- data/tracks/python/exercises/hexadecimal/hexadecimal_test.py +9 -10
- data/tracks/python/exercises/house/house_test.py +6 -6
- data/tracks/python/exercises/kindergarten-garden/kindergarten_garden_test.py +22 -19
- data/tracks/python/exercises/largest-series-product/largest_series_product_test.py +29 -28
- data/tracks/python/exercises/linked-list/linked_list_test.py +18 -19
- data/tracks/python/exercises/list-ops/list_ops_test.py +44 -39
- data/tracks/python/exercises/matrix/matrix_test.py +6 -6
- data/tracks/python/exercises/meetup/meetup_test.py +27 -27
- data/tracks/python/exercises/minesweeper/example.py +4 -2
- data/tracks/python/exercises/minesweeper/minesweeper_test.py +9 -9
- data/tracks/python/exercises/nucleotide-count/nucleotide_count_test.py +6 -6
- data/tracks/python/exercises/ocr-numbers/ocr_numbers_test.py +63 -49
- data/tracks/python/exercises/octal/octal_test.py +7 -7
- data/tracks/python/exercises/palindrome-products/palindrome_products_test.py +9 -9
- data/tracks/python/exercises/pascals-triangle/pascals_triangle_test.py +7 -7
- data/tracks/python/exercises/phone-number/phone_number_test.py +8 -8
- data/tracks/python/exercises/pig-latin/pig_latin_test.py +15 -15
- data/tracks/python/exercises/point-mutations/point_mutations_test.py +11 -11
- data/tracks/python/exercises/poker/poker_test.py +32 -30
- data/tracks/python/exercises/prime-factors/prime_factors_test.py +11 -11
- data/tracks/python/exercises/proverb/proverb_test.py +16 -9
- data/tracks/python/exercises/pythagorean-triplet/pythagorean_triplet_test.py +14 -12
- data/tracks/python/exercises/queen-attack/queen_attack_test.py +10 -10
- data/tracks/python/exercises/rail-fence-cipher/example.py +2 -1
- data/tracks/python/exercises/rail-fence-cipher/rail_fence_cipher_test.py +14 -13
- data/tracks/python/exercises/raindrops/raindrops_test.py +16 -16
- data/tracks/python/exercises/rectangles/rectangles_test.py +9 -9
- data/tracks/python/exercises/rna-transcription/rna_transcription_test.py +8 -8
- data/tracks/python/exercises/robot-name/robot_name_test.py +1 -1
- data/tracks/python/exercises/robot-simulator/robot_simulator_test.py +18 -19
- data/tracks/python/exercises/roman-numerals/roman_numerals_test.py +1 -1
- data/tracks/python/exercises/run-length-encoding/run_length_encoding_test.py +15 -16
- data/tracks/python/exercises/saddle-points/saddle_points_test.py +4 -4
- data/tracks/python/exercises/say/say_test.py +21 -23
- data/tracks/python/exercises/scrabble-score/scrabble_score_test.py +9 -9
- data/tracks/python/exercises/secret-handshake/secret_handshake_test.py +14 -13
- data/tracks/python/exercises/series/example.py +3 -3
- data/tracks/python/exercises/series/series_test.py +16 -12
- data/tracks/python/exercises/simple-cipher/simple_cipher_test.py +21 -19
- data/tracks/python/exercises/space-age/space_age_test.py +16 -16
- data/tracks/python/exercises/strain/strain_test.py +9 -8
- data/tracks/python/exercises/sublist/sublist_test.py +19 -20
- data/tracks/python/exercises/sum-of-multiples/example.py +1 -4
- data/tracks/python/exercises/sum-of-multiples/sum_of_multiples_test.py +31 -26
- data/tracks/python/exercises/triangle/triangle_test.py +15 -30
- data/tracks/python/exercises/trinary/trinary_test.py +7 -7
- data/tracks/python/exercises/twelve-days/twelve_days_test.py +13 -14
- data/tracks/python/exercises/word-count/example.py +1 -9
- data/tracks/python/exercises/word-count/word_count_test.py +0 -15
- data/tracks/python/exercises/wordy/wordy_test.py +17 -18
- data/tracks/python/exercises/zebra-puzzle/example.py +20 -23
- data/tracks/python/exercises/zebra-puzzle/zebra_puzzle_test.py +3 -3
- data/tracks/python/test/check-exercises.py +1 -1
- metadata +6 -2
@@ -8,25 +8,25 @@ from house import rhyme, verse
|
|
8
8
|
class VerseTest(unittest.TestCase):
|
9
9
|
def test_verse_0(self):
|
10
10
|
expected = 'This is the house that Jack built.'
|
11
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(verse(0), expected)
|
12
12
|
|
13
13
|
def test_verse_1(self):
|
14
14
|
expected = 'This is the malt\n'\
|
15
15
|
'that lay in the house that Jack built.'
|
16
|
-
self.assertEqual(
|
16
|
+
self.assertEqual(verse(1), expected)
|
17
17
|
|
18
18
|
def test_verse_2(self):
|
19
19
|
expected = 'This is the rat\n'\
|
20
20
|
'that ate the malt\n'\
|
21
21
|
'that lay in the house that Jack built.'
|
22
|
-
self.assertEqual(
|
22
|
+
self.assertEqual(verse(2), expected)
|
23
23
|
|
24
24
|
def test_verse_3(self):
|
25
25
|
expected = 'This is the cat\n'\
|
26
26
|
'that killed the rat\n'\
|
27
27
|
'that ate the malt\n'\
|
28
28
|
'that lay in the house that Jack built.'
|
29
|
-
self.assertEqual(
|
29
|
+
self.assertEqual(verse(3), expected)
|
30
30
|
|
31
31
|
def test_verse_11(self):
|
32
32
|
expected = 'This is the horse and the hound and the horn\n'\
|
@@ -41,7 +41,7 @@ class VerseTest(unittest.TestCase):
|
|
41
41
|
'that killed the rat\n'\
|
42
42
|
'that ate the malt\n'\
|
43
43
|
'that lay in the house that Jack built.'
|
44
|
-
self.assertEqual(
|
44
|
+
self.assertEqual(verse(11), expected)
|
45
45
|
|
46
46
|
def test_rhyme(self):
|
47
47
|
expected = 'This is the house that Jack built.\n\n'\
|
@@ -122,7 +122,7 @@ class VerseTest(unittest.TestCase):
|
|
122
122
|
'that killed the rat\n'\
|
123
123
|
'that ate the malt\n'\
|
124
124
|
'that lay in the house that Jack built.'
|
125
|
-
self.assertEqual(
|
125
|
+
self.assertEqual(rhyme(), expected)
|
126
126
|
|
127
127
|
|
128
128
|
if __name__ == '__main__':
|
@@ -4,34 +4,37 @@ from kindergarten_garden import Garden
|
|
4
4
|
|
5
5
|
|
6
6
|
class KindergartenGardenTests(unittest.TestCase):
|
7
|
-
|
8
7
|
def test_alices_garden(self):
|
9
|
-
self.assertEqual(
|
10
|
-
|
8
|
+
self.assertEqual(
|
9
|
+
Garden("RC\nGG").plants("Alice"),
|
10
|
+
"Radishes Clover Grass Grass".split())
|
11
11
|
|
12
12
|
def test_bob_and_charlies_gardens(self):
|
13
13
|
garden = Garden("VVCCGG\nVVCCGG")
|
14
|
-
self.assertEqual(["Clover"] * 4
|
15
|
-
self.assertEqual(["Grass"] * 4
|
14
|
+
self.assertEqual(garden.plants("Bob"), ["Clover"] * 4)
|
15
|
+
self.assertEqual(garden.plants("Charlie"), ["Grass"] * 4)
|
16
16
|
|
17
17
|
def test_full_garden(self):
|
18
18
|
garden = Garden("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV")
|
19
|
-
self.assertEqual(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
self.assertEqual(
|
20
|
+
garden.plants("Alice"),
|
21
|
+
"Violets Radishes Violets Radishes".split())
|
22
|
+
self.assertEqual(
|
23
|
+
garden.plants("Bob"), "Clover Grass Clover Clover".split())
|
24
|
+
self.assertEqual(
|
25
|
+
garden.plants("Kincaid"), "Grass Clover Clover Grass".split())
|
26
|
+
self.assertEqual(
|
27
|
+
garden.plants("Larry"), "Grass Violets Clover Violets".split())
|
27
28
|
|
28
29
|
def test_disordered_test(self):
|
29
|
-
garden = Garden(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
garden = Garden(
|
31
|
+
"VCRRGVRG\nRVGCCGCV",
|
32
|
+
students="Samantha Patricia Xander Roger".split())
|
33
|
+
self.assertEqual(
|
34
|
+
garden.plants("Patricia"),
|
35
|
+
"Violets Clover Radishes Violets".split())
|
36
|
+
self.assertEqual(
|
37
|
+
garden.plants("Xander"), "Radishes Grass Clover Violets".split())
|
35
38
|
|
36
39
|
|
37
40
|
if __name__ == '__main__':
|
@@ -13,61 +13,62 @@ from largest_series_product import largest_product
|
|
13
13
|
|
14
14
|
class SeriesTest(unittest.TestCase):
|
15
15
|
def test_largest_product_of_2(self):
|
16
|
-
self.assertEqual(
|
16
|
+
self.assertEqual(largest_product("0123456789", 2), 72)
|
17
17
|
|
18
18
|
def test_largest_product_of_2_unordered(self):
|
19
|
-
self.assertEqual(
|
19
|
+
self.assertEqual(largest_product("576802143", 2), 48)
|
20
20
|
|
21
21
|
def test__largest_product_span_equals_length(self):
|
22
|
-
self.assertEqual(
|
22
|
+
self.assertEqual(largest_product("29", 2), 18)
|
23
23
|
|
24
24
|
def test_largest_product_of_3(self):
|
25
|
-
self.assertEqual(
|
25
|
+
self.assertEqual(largest_product("0123456789", 3), 504)
|
26
26
|
|
27
27
|
def test_largest_product_of_3_unordered(self):
|
28
|
-
self.assertEqual(
|
28
|
+
self.assertEqual(largest_product("1027839564", 3), 270)
|
29
29
|
|
30
30
|
def test_largest_product_of_5(self):
|
31
|
-
self.assertEqual(
|
31
|
+
self.assertEqual(largest_product("0123456789", 5), 15120)
|
32
32
|
|
33
33
|
def test_big_number(self):
|
34
34
|
series = "73167176531330624919225119674426574742355349194934"
|
35
|
-
self.assertEqual(
|
35
|
+
self.assertEqual(largest_product(series, 6), 23520)
|
36
36
|
|
37
37
|
def test_another_big_number(self):
|
38
38
|
series = "52677741234314237566414902593461595376319419139427"
|
39
|
-
self.assertEqual(
|
39
|
+
self.assertEqual(largest_product(series, 6), 28350)
|
40
40
|
|
41
41
|
def test_project_euler_big_number(self):
|
42
42
|
series = (
|
43
|
-
"
|
44
|
-
"
|
45
|
-
"
|
46
|
-
"
|
47
|
-
"
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"
|
52
|
-
"
|
53
|
-
"
|
54
|
-
"
|
55
|
-
"
|
56
|
-
"
|
57
|
-
|
58
|
-
|
43
|
+
"73167176531330624919225119674426574742355349194934969835203127745"
|
44
|
+
"06326239578318016984801869478851843858615607891129494954595017379"
|
45
|
+
"58331952853208805511125406987471585238630507156932909632952274430"
|
46
|
+
"43557668966489504452445231617318564030987111217223831136222989342"
|
47
|
+
"33803081353362766142828064444866452387493035890729629049156044077"
|
48
|
+
"23907138105158593079608667017242712188399879790879227492190169972"
|
49
|
+
"08880937766572733300105336788122023542180975125454059475224352584"
|
50
|
+
"90771167055601360483958644670632441572215539753697817977846174064"
|
51
|
+
"95514929086256932197846862248283972241375657056057490261407972968"
|
52
|
+
"65241453510047482166370484403199890008895243450658541227588666881"
|
53
|
+
"16427171479924442928230863465674813919123162824586178664583591245"
|
54
|
+
"66529476545682848912883142607690042242190226710556263211111093705"
|
55
|
+
"44217506941658960408071984038509624554443629812309878799272442849"
|
56
|
+
"09188845801561660979191338754992005240636899125607176060588611646"
|
57
|
+
"71094050775410022569831552000559357297257163626956188267042825248"
|
58
|
+
"3600823257530420752963450")
|
59
|
+
self.assertEqual(largest_product(series, 13), 23514624000)
|
59
60
|
|
60
61
|
def test_all_digits_zero(self):
|
61
|
-
self.assertEqual(
|
62
|
+
self.assertEqual(largest_product("0000", 2), 0)
|
62
63
|
|
63
64
|
def test_all_spans_contain_zero(self):
|
64
|
-
self.assertEqual(
|
65
|
+
self.assertEqual(largest_product("99099", 3), 0)
|
65
66
|
|
66
67
|
def test_identity_with_empty_string(self):
|
67
|
-
self.assertEqual(
|
68
|
+
self.assertEqual(largest_product("", 0), 1)
|
68
69
|
|
69
70
|
def test_identity_with_nonempty_string(self):
|
70
|
-
self.assertEqual(
|
71
|
+
self.assertEqual(largest_product("123", 0), 1)
|
71
72
|
|
72
73
|
def test_span_long_than_number(self):
|
73
74
|
with self.assertRaises(ValueError):
|
@@ -4,63 +4,62 @@ from linked_list import LinkedList
|
|
4
4
|
|
5
5
|
|
6
6
|
class LinkedListTests(unittest.TestCase):
|
7
|
-
|
8
7
|
def setUp(self):
|
9
8
|
self.list = LinkedList()
|
10
9
|
|
11
10
|
def test_push_pop(self):
|
12
11
|
self.list.push(10)
|
13
12
|
self.list.push(20)
|
14
|
-
self.assertEqual(
|
15
|
-
self.assertEqual(
|
13
|
+
self.assertEqual(self.list.pop(), 20)
|
14
|
+
self.assertEqual(self.list.pop(), 10)
|
16
15
|
|
17
16
|
def test_push_shift(self):
|
18
17
|
self.list.push(10)
|
19
18
|
self.list.push(20)
|
20
|
-
self.assertEqual(
|
21
|
-
self.assertEqual(
|
19
|
+
self.assertEqual(self.list.shift(), 10)
|
20
|
+
self.assertEqual(self.list.shift(), 20)
|
22
21
|
|
23
22
|
def test_unshift_shift(self):
|
24
23
|
self.list.unshift(10)
|
25
24
|
self.list.unshift(20)
|
26
|
-
self.assertEqual(
|
27
|
-
self.assertEqual(
|
25
|
+
self.assertEqual(self.list.shift(), 20)
|
26
|
+
self.assertEqual(self.list.shift(), 10)
|
28
27
|
|
29
28
|
def test_unshift_pop(self):
|
30
29
|
self.list.unshift(10)
|
31
30
|
self.list.unshift(20)
|
32
|
-
self.assertEqual(
|
33
|
-
self.assertEqual(
|
31
|
+
self.assertEqual(self.list.pop(), 10)
|
32
|
+
self.assertEqual(self.list.pop(), 20)
|
34
33
|
|
35
34
|
def test_all(self):
|
36
35
|
self.list.push(10)
|
37
36
|
self.list.push(20)
|
38
|
-
self.assertEqual(
|
37
|
+
self.assertEqual(self.list.pop(), 20)
|
39
38
|
self.list.push(30)
|
40
|
-
self.assertEqual(
|
39
|
+
self.assertEqual(self.list.shift(), 10)
|
41
40
|
self.list.unshift(40)
|
42
41
|
self.list.push(50)
|
43
|
-
self.assertEqual(
|
44
|
-
self.assertEqual(
|
45
|
-
self.assertEqual(
|
42
|
+
self.assertEqual(self.list.shift(), 40)
|
43
|
+
self.assertEqual(self.list.pop(), 50)
|
44
|
+
self.assertEqual(self.list.shift(), 30)
|
46
45
|
|
47
46
|
@unittest.skip("extra-credit")
|
48
47
|
def test_length(self):
|
49
48
|
self.list.push(10)
|
50
49
|
self.list.push(20)
|
51
|
-
self.assertEqual(
|
50
|
+
self.assertEqual(len(self.list), 2)
|
52
51
|
self.list.shift()
|
53
|
-
self.assertEqual(
|
52
|
+
self.assertEqual(len(self.list), 1)
|
54
53
|
self.list.pop()
|
55
|
-
self.assertEqual(
|
54
|
+
self.assertEqual(len(self.list), 0)
|
56
55
|
|
57
56
|
@unittest.skip("extra-credit")
|
58
57
|
def test_iterator(self):
|
59
58
|
self.list.push(10)
|
60
59
|
self.list.push(20)
|
61
60
|
iterator = iter(self.list)
|
62
|
-
self.assertEqual(
|
63
|
-
self.assertEqual(
|
61
|
+
self.assertEqual(next(iterator), 10)
|
62
|
+
self.assertEqual(next(iterator), 20)
|
64
63
|
|
65
64
|
|
66
65
|
if __name__ == '__main__':
|
@@ -9,112 +9,117 @@ class ListOpsTest(unittest.TestCase):
|
|
9
9
|
# tests for map
|
10
10
|
def test_map_square(self):
|
11
11
|
self.assertEqual(
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
list_ops.map_clone(lambda x: x**2,
|
13
|
+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
|
14
|
+
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100])
|
15
15
|
|
16
16
|
def test_map_cube(self):
|
17
17
|
self.assertEqual(
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
list_ops.map_clone(lambda x: x**3,
|
19
|
+
[-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]),
|
20
|
+
[-1, 8, -27, 64, -125, 216, -343, 512, -729, 1000])
|
21
21
|
|
22
22
|
def test_map_absolute(self):
|
23
23
|
self.assertEqual(
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
list_ops.map_clone(lambda x: abs(x),
|
25
|
+
[-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]),
|
26
|
+
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
27
27
|
|
28
28
|
def test_map_empty(self):
|
29
|
-
self.assertEqual(
|
29
|
+
self.assertEqual(list_ops.map_clone(operator.index, []), [])
|
30
30
|
|
31
31
|
# tests for length
|
32
32
|
def test_pos_leng(self):
|
33
|
-
self.assertEqual(
|
33
|
+
self.assertEqual(
|
34
|
+
list_ops.length([-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]), 10)
|
34
35
|
|
35
36
|
def test_empty_len(self):
|
36
|
-
self.assertEqual(
|
37
|
+
self.assertEqual(list_ops.length([]), 0)
|
37
38
|
|
38
39
|
# tests for filter
|
39
40
|
def test_filter_odd(self):
|
40
41
|
self.assertEqual(
|
41
|
-
[1, 3, 5],
|
42
|
-
|
42
|
+
list_ops.filter_clone(lambda x: x % 2 != 0, [1, 2, 3, 4, 5, 6]),
|
43
|
+
[1, 3, 5])
|
43
44
|
|
44
45
|
def test_filter_even(self):
|
45
46
|
self.assertEqual(
|
46
|
-
[2, 4, 6],
|
47
|
-
|
47
|
+
list_ops.filter_clone(lambda x: x % 2 == 0, [1, 2, 3, 4, 5, 6]),
|
48
|
+
[2, 4, 6])
|
48
49
|
|
49
50
|
# tests for reverse
|
50
51
|
def test_reverse_small(self):
|
51
|
-
self.assertEqual([
|
52
|
+
self.assertEqual(list_ops.reverse([3, 2, 1]), [1, 2, 3])
|
52
53
|
|
53
54
|
def test_reverse_mixed_types(self):
|
54
55
|
self.assertEqual(
|
55
|
-
[1, "cat", 4.0, "xyz"]
|
56
|
-
list_ops.reverse(["xyz", 4.0, "cat", 1]))
|
56
|
+
list_ops.reverse(["xyz", 4.0, "cat", 1]), [1, "cat", 4.0, "xyz"])
|
57
57
|
|
58
58
|
def test_reverse_empty(self):
|
59
|
-
self.assertEqual(
|
59
|
+
self.assertEqual(list_ops.reverse([]), [])
|
60
60
|
|
61
61
|
# tests for append
|
62
62
|
def test_append_tuple(self):
|
63
63
|
self.assertEqual(
|
64
|
-
["10", "python", "hello"
|
65
|
-
|
64
|
+
list_ops.append(["10", "python"], "hello"),
|
65
|
+
["10", "python", "hello"])
|
66
66
|
|
67
67
|
def test_append_range(self):
|
68
|
-
self.assertEqual(
|
68
|
+
self.assertEqual(
|
69
|
+
list_ops.append([100], range(1000)), [100, range(1000)])
|
69
70
|
|
70
71
|
def test_append_to_empty(self):
|
71
|
-
self.assertEqual(
|
72
|
+
self.assertEqual(list_ops.append([], 42), [42])
|
72
73
|
|
73
74
|
# tests for foldl
|
74
75
|
def test_foldl_sum(self):
|
75
|
-
self.assertEqual(
|
76
|
+
self.assertEqual(
|
77
|
+
list_ops.foldl(operator.add, [1, 2, 3, 4, 5, 6], 0), 21)
|
76
78
|
|
77
79
|
def test_foldl_product(self):
|
78
|
-
self.assertEqual(
|
80
|
+
self.assertEqual(
|
81
|
+
list_ops.foldl(operator.mul, [1, 2, 3, 4, 5, 6], 1), 720)
|
79
82
|
|
80
83
|
def test_foldl_div(self):
|
81
|
-
self.assertEqual(
|
84
|
+
self.assertEqual(
|
85
|
+
list_ops.foldl(operator.floordiv, [1, 2, 3, 4, 5, 6], 1), 0)
|
82
86
|
|
83
87
|
def test_foldl_sub(self):
|
84
|
-
self.assertEqual(
|
88
|
+
self.assertEqual(list_ops.foldl(operator.sub, [1, 2, 3, 4, 5], 0), -15)
|
85
89
|
|
86
90
|
# tests for foldr
|
87
91
|
def test_foldr_sub(self):
|
88
|
-
self.assertEqual(
|
92
|
+
self.assertEqual(list_ops.foldr(operator.sub, [1, 2, 3, 4, 5], 0), 3)
|
89
93
|
|
90
94
|
def test_foldr_add_str(self):
|
91
95
|
self.assertEqual(
|
92
|
-
|
93
|
-
|
96
|
+
list_ops.foldr(operator.add,
|
97
|
+
["e", "x", "e", "r", "c", "i", "s", "m"], "!"),
|
98
|
+
"exercism!")
|
94
99
|
|
95
100
|
# tests for flatten
|
96
101
|
def test_flatten_nested(self):
|
97
|
-
self.assertEqual(
|
102
|
+
self.assertEqual(list_ops.flat([[[1, 2], [3]], [[4]]]), [1, 2, 3, 4])
|
98
103
|
|
99
104
|
def test_flatten_once(self):
|
100
|
-
self.assertEqual(["x", "y", "z"],
|
105
|
+
self.assertEqual(list_ops.flat([["x", "y", "z"]]), ["x", "y", "z"])
|
101
106
|
|
102
107
|
def test_flatten_empty(self):
|
103
|
-
self.assertEqual(
|
108
|
+
self.assertEqual(list_ops.flat([]), [])
|
104
109
|
|
105
110
|
# tests for concat
|
106
111
|
def test_concat_two(self):
|
107
112
|
self.assertEqual(
|
108
|
-
[1, 3, 5, 8, 9, 4, 5, 6],
|
109
|
-
|
113
|
+
list_ops.concat([1, 3, 5, 8], [9, 4, 5, 6]),
|
114
|
+
[1, 3, 5, 8, 9, 4, 5, 6])
|
110
115
|
|
111
116
|
def test_concat_nothing(self):
|
112
117
|
self.assertEqual(
|
113
|
-
[
|
114
|
-
|
118
|
+
list_ops.concat(['orange', 'apple', 'banana'], None),
|
119
|
+
["orange", "apple", "banana"])
|
115
120
|
|
116
121
|
def test_concat_empty(self):
|
117
|
-
self.assertEqual(
|
122
|
+
self.assertEqual(list_ops.concat([], []), [])
|
118
123
|
|
119
124
|
|
120
125
|
if __name__ == '__main__':
|
@@ -6,27 +6,27 @@ from matrix import Matrix
|
|
6
6
|
class MatrixTest(unittest.TestCase):
|
7
7
|
def test_extract_a_row(self):
|
8
8
|
matrix = Matrix("1 2\n10 20")
|
9
|
-
self.assertEqual([1, 2]
|
9
|
+
self.assertEqual(matrix.rows[0], [1, 2])
|
10
10
|
|
11
11
|
def test_extract_same_row_again(self):
|
12
12
|
matrix = Matrix("9 7\n8 6")
|
13
|
-
self.assertEqual([9, 7]
|
13
|
+
self.assertEqual(matrix.rows[0], [9, 7])
|
14
14
|
|
15
15
|
def test_extract_other_row(self):
|
16
16
|
matrix = Matrix("9 8 7\n19 18 17")
|
17
|
-
self.assertEqual([19, 18, 17]
|
17
|
+
self.assertEqual(matrix.rows[1], [19, 18, 17])
|
18
18
|
|
19
19
|
def test_extract_other_row_again(self):
|
20
20
|
matrix = Matrix("1 4 9\n16 25 36")
|
21
|
-
self.assertEqual([16, 25, 36]
|
21
|
+
self.assertEqual(matrix.rows[1], [16, 25, 36])
|
22
22
|
|
23
23
|
def test_extract_a_column(self):
|
24
24
|
matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
|
25
|
-
self.assertEqual([1, 4, 7, 8]
|
25
|
+
self.assertEqual(matrix.columns[0], [1, 4, 7, 8])
|
26
26
|
|
27
27
|
def test_extract_another_column(self):
|
28
28
|
matrix = Matrix("89 1903 3\n18 3 1\n9 4 800")
|
29
|
-
self.assertEqual([1903, 3, 4]
|
29
|
+
self.assertEqual(matrix.columns[1], [1903, 3, 4])
|
30
30
|
|
31
31
|
|
32
32
|
if __name__ == '__main__':
|