trackler 2.2.1.61 → 2.2.1.62
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/exercises/forth/canonical-data.json +1 -7
- data/problem-specifications/exercises/meetup/description.md +16 -12
- data/problem-specifications/exercises/sum-of-multiples/description.md +3 -3
- data/tracks/c/config.json +14 -1
- data/tracks/c/exercises/anagram/src/anagram.h +19 -4
- data/tracks/c/exercises/anagram/src/example.c +27 -40
- data/tracks/c/exercises/anagram/test/test_anagram.c +100 -152
- data/tracks/c/exercises/sublist/README.md +53 -0
- data/tracks/c/exercises/sublist/makefile +15 -0
- data/tracks/c/exercises/sublist/src/example.c +63 -0
- data/tracks/c/exercises/sublist/src/sublist.h +17 -0
- data/tracks/c/exercises/sublist/test/test_sublist.c +243 -0
- data/tracks/c/exercises/sublist/test/vendor/unity.c +1300 -0
- data/tracks/c/exercises/sublist/test/vendor/unity.h +274 -0
- data/tracks/c/exercises/sublist/test/vendor/unity_internals.h +701 -0
- data/tracks/ecmascript/config.json +56 -0
- data/tracks/ecmascript/exercises/rectangles/README.md +95 -0
- data/tracks/ecmascript/exercises/rectangles/example.js +38 -0
- data/tracks/ecmascript/exercises/rectangles/package.json +72 -0
- data/tracks/ecmascript/exercises/rectangles/rectangles.spec.js +147 -0
- data/tracks/ecmascript/exercises/rotational-cipher/README.md +66 -0
- data/tracks/ecmascript/exercises/rotational-cipher/example.js +16 -0
- data/tracks/ecmascript/exercises/rotational-cipher/package.json +72 -0
- data/tracks/ecmascript/exercises/rotational-cipher/rotational-cipher.spec.js +73 -0
- data/tracks/ecmascript/exercises/spiral-matrix/README.md +59 -0
- data/tracks/ecmascript/exercises/spiral-matrix/example.js +26 -0
- data/tracks/ecmascript/exercises/spiral-matrix/package.json +72 -0
- data/tracks/ecmascript/exercises/spiral-matrix/spiral-matrix.spec.js +55 -0
- data/tracks/ecmascript/exercises/transpose/README.md +94 -0
- data/tracks/ecmascript/exercises/transpose/example.js +12 -0
- data/tracks/ecmascript/exercises/transpose/package.json +71 -0
- data/tracks/ecmascript/exercises/transpose/transpose.spec.js +121 -0
- data/tracks/go/exercises/allergies/.meta/gen.go +88 -0
- data/tracks/go/exercises/allergies/allergies_test.go +19 -46
- data/tracks/go/exercises/allergies/cases_test.go +60 -0
- data/tracks/go/exercises/bob/bob.go +0 -2
- data/tracks/go/exercises/forth/cases_test.go +2 -7
- data/tracks/go/exercises/nucleotide-count/nucleotide_count.go +0 -2
- data/tracks/go/exercises/pangram/.meta/gen.go +54 -0
- data/tracks/go/exercises/pangram/cases_test.go +62 -0
- data/tracks/go/exercises/pangram/example.go +3 -5
- data/tracks/go/exercises/pangram/pangram_test.go +3 -24
- data/tracks/go/exercises/rna-transcription/rna_transcription.go +0 -2
- data/tracks/go/exercises/robot-name/bonus_example.go +0 -2
- data/tracks/java/exercises/acronym/.meta/src/reference/java/Acronym.java +3 -3
- data/tracks/lfe/config.json +4 -3
- data/tracks/perl6/docs/SNIPPET.txt +8 -3
- data/tracks/perl6/exercises/allergies/Allergies.pm6 +1 -1
- data/tracks/perl6/exercises/allergies/Example.pm6 +1 -1
- data/tracks/perl6/exercises/allergies/allergies.t +10 -2
- data/tracks/perl6/exercises/allergies/example.yaml +10 -2
- data/tracks/perl6/exercises/leap/Example.pm6 +1 -1
- data/tracks/perl6/exercises/leap/Leap.pm6 +1 -1
- data/tracks/perl6/exercises/leap/example.yaml +10 -2
- data/tracks/perl6/exercises/leap/leap.t +10 -2
- data/tracks/perl6/exercises/luhn/Example.pm6 +1 -1
- data/tracks/perl6/exercises/luhn/Luhn.pm6 +1 -1
- data/tracks/perl6/exercises/luhn/example.yaml +10 -2
- data/tracks/perl6/exercises/luhn/luhn.t +10 -2
- data/tracks/perl6/exercises/pangram/Example.pm6 +1 -1
- data/tracks/perl6/exercises/pangram/Pangram.pm6 +1 -1
- data/tracks/perl6/exercises/pangram/example.yaml +12 -6
- data/tracks/perl6/exercises/pangram/pangram.t +9 -3
- data/tracks/python/config.json +38 -0
- data/tracks/python/exercises/complex-numbers/complex_numbers_test.py +81 -66
- data/tracks/python/exercises/connect/README.md +44 -0
- data/tracks/python/exercises/connect/connect.py +7 -0
- data/tracks/python/exercises/connect/connect_test.py +118 -0
- data/tracks/python/exercises/connect/example.py +61 -0
- data/tracks/python/exercises/go-counting/README.md +44 -0
- data/tracks/python/exercises/go-counting/example.py +62 -0
- data/tracks/python/exercises/go-counting/go_counting.py +38 -0
- data/tracks/python/exercises/go-counting/go_counting_test.py +92 -0
- data/tracks/python/exercises/parallel-letter-frequency/README.md +24 -0
- data/tracks/python/exercises/parallel-letter-frequency/example.py +56 -0
- data/tracks/python/exercises/parallel-letter-frequency/parallel_letter_frequency.py +2 -0
- data/tracks/python/exercises/parallel-letter-frequency/parallel_letter_frequency_test.py +61 -0
- data/tracks/python/exercises/strain/README.md +3 -1
- data/tracks/python/exercises/strain/strain.py +2 -2
- data/tracks/rust/.travis.yml +1 -0
- data/tracks/rust/README.md +2 -0
- data/tracks/rust/_test/check-exercises.sh +41 -54
- data/tracks/rust/_test/ensure-readmes-are-updated.sh +40 -0
- data/tracks/rust/bin/test-exercise +84 -0
- data/tracks/rust/exercises/alphametics/.meta/test-in-release-mode +2 -0
- data/tracks/rust/exercises/alphametics/src/lib.rs +1 -1
- data/tracks/rust/exercises/dominoes/README.md +3 -3
- data/tracks/rust/exercises/isbn-verifier/README.md +3 -2
- data/tracks/rust/exercises/nucleotide-count/README.md +2 -2
- data/tracks/rust/exercises/perfect-numbers/src/lib.rs +10 -0
- data/tracks/rust/exercises/phone-number/README.md +1 -1
- data/tracks/rust/exercises/pythagorean-triplet/src/lib.rs +3 -0
- data/tracks/rust/exercises/rectangles/README.md +9 -9
- data/tracks/rust/exercises/two-bucket/README.md +7 -7
- data/tracks/typescript/config.json +16 -0
- data/tracks/typescript/exercises/diamond/README.md +84 -0
- data/tracks/typescript/exercises/diamond/diamond.example.ts +51 -0
- data/tracks/typescript/exercises/diamond/diamond.test.ts +35 -0
- data/tracks/typescript/exercises/diamond/diamond.ts +0 -0
- data/tracks/typescript/exercises/diamond/package.json +36 -0
- data/tracks/typescript/exercises/diamond/tsconfig.json +22 -0
- data/tracks/typescript/exercises/diamond/tslint.json +127 -0
- data/tracks/typescript/exercises/diamond/yarn.lock +2624 -0
- metadata +53 -2
@@ -1,17 +1,23 @@
|
|
1
1
|
exercise: Pangram
|
2
|
-
version:
|
2
|
+
version: 2
|
3
3
|
plan: 12
|
4
4
|
imports: '&is-pangram'
|
5
|
-
tests:
|
6
|
-
for $c-data<cases
|
7
|
-
|
5
|
+
tests: |-
|
6
|
+
for $c-data<cases>».<cases>».Array.flat {
|
7
|
+
given is-pangram .<input> -> $result {
|
8
|
+
subtest .<description>, {
|
9
|
+
plan 2;
|
10
|
+
isa-ok $result, Bool;
|
11
|
+
is-deeply $result, .<expected>, 'Result matches expected';
|
12
|
+
}
|
13
|
+
}
|
8
14
|
}
|
9
15
|
|
10
16
|
unit: module
|
11
|
-
example:
|
17
|
+
example: |-
|
12
18
|
sub is-pangram (Str:D $string --> Bool:D) is export {
|
13
19
|
$string.lc.comb ⊇ ‘a’..‘z’
|
14
20
|
}
|
15
|
-
stub:
|
21
|
+
stub: |-
|
16
22
|
sub is-pangram ($string) is export {
|
17
23
|
}
|
@@ -5,7 +5,7 @@ use lib my $dir = $?FILE.IO.dirname;
|
|
5
5
|
use JSON::Fast;
|
6
6
|
|
7
7
|
my Str:D $exercise := 'Pangram';
|
8
|
-
my Version:D $version =
|
8
|
+
my Version:D $version = v2;
|
9
9
|
my Str $module //= $exercise;
|
10
10
|
plan 12;
|
11
11
|
|
@@ -22,8 +22,14 @@ if ::($exercise).^ver !~~ $version {
|
|
22
22
|
require ::($module) <&is-pangram>;
|
23
23
|
|
24
24
|
my $c-data = from-json $=pod.pop.contents;
|
25
|
-
for $c-data<cases
|
26
|
-
|
25
|
+
for $c-data<cases>».<cases>».Array.flat {
|
26
|
+
given is-pangram .<input> -> $result {
|
27
|
+
subtest .<description>, {
|
28
|
+
plan 2;
|
29
|
+
isa-ok $result, Bool;
|
30
|
+
is-deeply $result, .<expected>, 'Result matches expected';
|
31
|
+
}
|
32
|
+
}
|
27
33
|
}
|
28
34
|
|
29
35
|
=head2 Canonical Data
|
data/tracks/python/config.json
CHANGED
@@ -54,6 +54,20 @@
|
|
54
54
|
"logic"
|
55
55
|
]
|
56
56
|
},
|
57
|
+
{
|
58
|
+
"uuid": "7126f86c-0e7f-7080-b4cb-3c8457dfcadcfe7e446",
|
59
|
+
"slug": "parallel-letter-frequency",
|
60
|
+
"core": false,
|
61
|
+
"unlocked_by": null,
|
62
|
+
"difficulty": 5,
|
63
|
+
"topics": [
|
64
|
+
"threading",
|
65
|
+
"parallellism",
|
66
|
+
"loops",
|
67
|
+
"queues",
|
68
|
+
"strings"
|
69
|
+
]
|
70
|
+
},
|
57
71
|
{
|
58
72
|
"uuid": "ca7c5ef1-5135-4fb4-8e68-669ef0f2a51a",
|
59
73
|
"slug": "rna-transcription",
|
@@ -1021,6 +1035,17 @@
|
|
1021
1035
|
"text_formatting"
|
1022
1036
|
]
|
1023
1037
|
},
|
1038
|
+
{
|
1039
|
+
"uuid": "f5503274-ac23-11e7-abc4-cec278b6b50a",
|
1040
|
+
"slug": "connect",
|
1041
|
+
"core": false,
|
1042
|
+
"unlocked_by": null,
|
1043
|
+
"difficulty": 1,
|
1044
|
+
"topics": [
|
1045
|
+
"parsing",
|
1046
|
+
"transforming"
|
1047
|
+
]
|
1048
|
+
},
|
1024
1049
|
{
|
1025
1050
|
"uuid": "33f689ee-1d9c-4908-a71c-f84bff3510df",
|
1026
1051
|
"slug": "collatz-conjecture",
|
@@ -1031,6 +1056,19 @@
|
|
1031
1056
|
"loops"
|
1032
1057
|
]
|
1033
1058
|
},
|
1059
|
+
{
|
1060
|
+
"uuid": "d4ddeb18-ac22-11e7-abc4-cec278b6b50a",
|
1061
|
+
"slug": "go-counting",
|
1062
|
+
"core": false,
|
1063
|
+
"unlocked_by": null,
|
1064
|
+
"difficulty": 4,
|
1065
|
+
"topics": [
|
1066
|
+
"parsing",
|
1067
|
+
"tuples",
|
1068
|
+
"optional_values",
|
1069
|
+
"classes"
|
1070
|
+
]
|
1071
|
+
},
|
1034
1072
|
{
|
1035
1073
|
"uuid": "7f4d5743-7ab8-42ca-b393-767f7e9a4e97",
|
1036
1074
|
"slug": "complex-numbers",
|
@@ -5,61 +5,46 @@ import math
|
|
5
5
|
from complex_numbers import ComplexNumber
|
6
6
|
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
def test_real_part_of_a_purely_real_number(self):
|
11
|
-
input_number = ComplexNumber(1, 0)
|
12
|
-
self.assertEqual(input_number.real, 1)
|
13
|
-
|
14
|
-
def test_real_part_of_a_purely_imaginary_number(self):
|
15
|
-
input_number = ComplexNumber(0, 1)
|
16
|
-
self.assertEqual(input_number.real, 0)
|
17
|
-
|
18
|
-
def test_real_part_of_a_number_with_real_and_imaginary_part(self):
|
19
|
-
input_number = ComplexNumber(1, 2)
|
20
|
-
self.assertEqual(input_number.real, 1)
|
8
|
+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.0
|
21
9
|
|
22
|
-
def test_imaginary_part_of_a_purely_real_number(self):
|
23
|
-
input_number = ComplexNumber(1, 0)
|
24
|
-
self.assertEqual(input_number.imaginary, 0)
|
25
10
|
|
26
|
-
|
27
|
-
input_number = ComplexNumber(0, 1)
|
28
|
-
self.assertEqual(input_number.imaginary, 1)
|
29
|
-
|
30
|
-
def test_maginary_part_of_a_number_with_real_and_imaginary_part(self):
|
31
|
-
input_number = ComplexNumber(1, 2)
|
32
|
-
self.assertEqual(input_number.imaginary, 2)
|
11
|
+
class ComplexNumbersTest(unittest.TestCase):
|
33
12
|
|
34
13
|
def test_add_purely_real_numbers(self):
|
35
14
|
first_input = ComplexNumber(1, 0)
|
36
|
-
second_input = ComplexNumber(
|
37
|
-
self.assertEqual(first_input.add(second_input).real,
|
15
|
+
second_input = ComplexNumber(2, 0)
|
16
|
+
self.assertEqual(first_input.add(second_input).real, 3)
|
38
17
|
self.assertEqual(first_input.add(second_input).imaginary, 0)
|
39
18
|
|
40
19
|
def test_add_purely_imaginary_numbers(self):
|
41
20
|
first_input = ComplexNumber(0, 1)
|
42
|
-
second_input = ComplexNumber(0,
|
21
|
+
second_input = ComplexNumber(0, 2)
|
43
22
|
self.assertEqual(first_input.add(second_input).real, 0)
|
44
|
-
self.assertEqual(first_input.add(second_input).imaginary,
|
23
|
+
self.assertEqual(first_input.add(second_input).imaginary, 3)
|
45
24
|
|
46
25
|
def test_add_numbers_with_real_and_imaginary_part(self):
|
47
26
|
first_input = ComplexNumber(1, 2)
|
48
|
-
second_input = ComplexNumber(
|
49
|
-
self.assertEqual(first_input.add(second_input).real,
|
50
|
-
self.assertEqual(first_input.add(second_input).imaginary,
|
27
|
+
second_input = ComplexNumber(3, 4)
|
28
|
+
self.assertEqual(first_input.add(second_input).real, 4)
|
29
|
+
self.assertEqual(first_input.add(second_input).imaginary, 6)
|
51
30
|
|
52
31
|
def test_subtract_purely_real_numbers(self):
|
53
32
|
first_input = ComplexNumber(1, 0)
|
54
|
-
second_input = ComplexNumber(
|
55
|
-
self.assertEqual(first_input.sub(second_input).real,
|
33
|
+
second_input = ComplexNumber(2, 0)
|
34
|
+
self.assertEqual(first_input.sub(second_input).real, -1)
|
56
35
|
self.assertEqual(first_input.sub(second_input).imaginary, 0)
|
57
36
|
|
37
|
+
def test_subtract_purely_imaginary_numbers(self):
|
38
|
+
first_input = ComplexNumber(0, 1)
|
39
|
+
second_input = ComplexNumber(0, 2)
|
40
|
+
self.assertEqual(first_input.sub(second_input).real, 0)
|
41
|
+
self.assertEqual(first_input.sub(second_input).imaginary, -1)
|
42
|
+
|
58
43
|
def test_subtract_numbers_with_real_and_imaginary_part(self):
|
59
44
|
first_input = ComplexNumber(1, 2)
|
60
|
-
second_input = ComplexNumber(
|
61
|
-
self.assertEqual(first_input.sub(second_input).real,
|
62
|
-
self.assertEqual(first_input.sub(second_input).imaginary,
|
45
|
+
second_input = ComplexNumber(3, 4)
|
46
|
+
self.assertEqual(first_input.sub(second_input).real, -2)
|
47
|
+
self.assertEqual(first_input.sub(second_input).imaginary, -2)
|
63
48
|
|
64
49
|
def test_multiply_purely_real_numbers(self):
|
65
50
|
first_input = ComplexNumber(1, 0)
|
@@ -67,35 +52,41 @@ class ComplexNumbersTest(unittest.TestCase):
|
|
67
52
|
self.assertEqual(first_input.mul(second_input).real, 2)
|
68
53
|
self.assertEqual(first_input.mul(second_input).imaginary, 0)
|
69
54
|
|
55
|
+
def test_multiply_purely_imaginary_numbers(self):
|
56
|
+
first_input = ComplexNumber(0, 1)
|
57
|
+
second_input = ComplexNumber(0, 2)
|
58
|
+
self.assertEqual(first_input.mul(second_input).real, -2)
|
59
|
+
self.assertEqual(first_input.mul(second_input).imaginary, 0)
|
60
|
+
|
70
61
|
def test_multiply_numbers_with_real_and_imaginary_part(self):
|
71
62
|
first_input = ComplexNumber(1, 2)
|
72
|
-
second_input = ComplexNumber(
|
73
|
-
self.assertEqual(first_input.mul(second_input).real, -
|
74
|
-
self.assertEqual(first_input.mul(second_input).imaginary,
|
63
|
+
second_input = ComplexNumber(3, 4)
|
64
|
+
self.assertEqual(first_input.mul(second_input).real, -5)
|
65
|
+
self.assertEqual(first_input.mul(second_input).imaginary, 10)
|
75
66
|
|
76
67
|
def test_divide_purely_real_numbers(self):
|
77
68
|
input_number = ComplexNumber(1.0, 0.0)
|
78
69
|
expected = ComplexNumber(0.5, 0.0)
|
79
70
|
divider = ComplexNumber(2.0, 0.0)
|
80
|
-
self.assertEqual(
|
81
|
-
self.assertEqual(
|
82
|
-
|
71
|
+
self.assertEqual(input_number.div(divider).real, expected.real)
|
72
|
+
self.assertEqual(input_number.div(divider).imaginary,
|
73
|
+
expected.imaginary)
|
83
74
|
|
84
75
|
def test_divide_purely_imaginary_numbers(self):
|
85
76
|
input_number = ComplexNumber(0, 1)
|
86
77
|
expected = ComplexNumber(0.5, 0)
|
87
78
|
divider = ComplexNumber(0, 2)
|
88
|
-
self.assertEqual(
|
89
|
-
self.assertEqual(
|
90
|
-
|
79
|
+
self.assertEqual(input_number.div(divider).real, expected.real)
|
80
|
+
self.assertEqual(input_number.div(divider).imaginary,
|
81
|
+
expected.imaginary)
|
91
82
|
|
92
83
|
def test_divide_numbers_with_real_and_imaginary_part(self):
|
93
84
|
input_number = ComplexNumber(1, 2)
|
94
85
|
expected = ComplexNumber(0.44, 0.08)
|
95
86
|
divider = ComplexNumber(3, 4)
|
96
|
-
self.assertEqual(
|
97
|
-
self.assertEqual(
|
98
|
-
|
87
|
+
self.assertEqual(input_number.div(divider).real, expected.real)
|
88
|
+
self.assertEqual(input_number.div(divider).imaginary,
|
89
|
+
expected.imaginary)
|
99
90
|
|
100
91
|
def test_absolute_value_of_a_positive_purely_real_number(self):
|
101
92
|
self.assertEqual(ComplexNumber(5, 0).abs(), 5)
|
@@ -103,53 +94,77 @@ class ComplexNumbersTest(unittest.TestCase):
|
|
103
94
|
def test_absolute_value_of_a_negative_purely_real_number(self):
|
104
95
|
self.assertEqual(ComplexNumber(-5, 0).abs(), 5)
|
105
96
|
|
106
|
-
def test_absolute_value_of_imaginary_number_negative_imaginary_part(self):
|
107
|
-
self.assertEqual(ComplexNumber(0, -5).abs(), 5)
|
108
|
-
|
109
97
|
def test_absolute_value_of_imaginary_number_positive_imaginary_part(self):
|
110
98
|
self.assertEqual(ComplexNumber(0, 5).abs(), 5)
|
111
99
|
|
100
|
+
def test_absolute_value_of_imaginary_number_negative_imaginary_part(self):
|
101
|
+
self.assertEqual(ComplexNumber(0, -5).abs(), 5)
|
102
|
+
|
112
103
|
def test_absolute_value_of_a_number_with_real_and_imaginary_part(self):
|
113
104
|
self.assertEqual(ComplexNumber(3, 4).abs(), 5)
|
114
105
|
|
115
106
|
def test_conjugate_a_purely_real_number(self):
|
116
107
|
input_number = ComplexNumber(5, 0)
|
117
108
|
expected = ComplexNumber(5, 0)
|
118
|
-
self.assertEqual(
|
119
|
-
self.assertEqual(
|
120
|
-
|
109
|
+
self.assertEqual(input_number.conjugate().real, expected.real)
|
110
|
+
self.assertEqual(input_number.conjugate().imaginary,
|
111
|
+
expected.imaginary)
|
121
112
|
|
122
113
|
def test_conjugate_a_purely_imaginary_number(self):
|
123
114
|
input_number = ComplexNumber(0, 5)
|
124
115
|
expected = ComplexNumber(0, -5)
|
125
|
-
self.assertEqual(
|
126
|
-
self.assertEqual(
|
127
|
-
|
116
|
+
self.assertEqual(input_number.conjugate().real, expected.real)
|
117
|
+
self.assertEqual(input_number.conjugate().imaginary,
|
118
|
+
expected.imaginary)
|
128
119
|
|
129
|
-
def
|
120
|
+
def test_conjugate_a_number_with_real_and_imaginary_part(self):
|
130
121
|
input_number = ComplexNumber(1, 1)
|
131
122
|
expected = ComplexNumber(1, -1)
|
132
|
-
self.assertEqual(
|
133
|
-
self.assertEqual(
|
134
|
-
|
123
|
+
self.assertEqual(input_number.conjugate().real, expected.real)
|
124
|
+
self.assertEqual(input_number.conjugate().imaginary,
|
125
|
+
expected.imaginary)
|
126
|
+
|
127
|
+
def test_real_part_of_a_purely_real_number(self):
|
128
|
+
input_number = ComplexNumber(1, 0)
|
129
|
+
self.assertEqual(input_number.real, 1)
|
130
|
+
|
131
|
+
def test_real_part_of_a_purely_imaginary_number(self):
|
132
|
+
input_number = ComplexNumber(0, 1)
|
133
|
+
self.assertEqual(input_number.real, 0)
|
134
|
+
|
135
|
+
def test_real_part_of_a_number_with_real_and_imaginary_part(self):
|
136
|
+
input_number = ComplexNumber(1, 2)
|
137
|
+
self.assertEqual(input_number.real, 1)
|
138
|
+
|
139
|
+
def test_imaginary_part_of_a_purely_real_number(self):
|
140
|
+
input_number = ComplexNumber(1, 0)
|
141
|
+
self.assertEqual(input_number.imaginary, 0)
|
142
|
+
|
143
|
+
def test_imaginary_part_of_a_purely_imaginary_number(self):
|
144
|
+
input_number = ComplexNumber(0, 1)
|
145
|
+
self.assertEqual(input_number.imaginary, 1)
|
146
|
+
|
147
|
+
def test_imaginary_part_of_a_number_with_real_and_imaginary_part(self):
|
148
|
+
input_number = ComplexNumber(1, 2)
|
149
|
+
self.assertEqual(input_number.imaginary, 2)
|
135
150
|
|
136
151
|
def test_eulers_identity_formula(self):
|
137
152
|
input_number = ComplexNumber(0, math.pi)
|
138
153
|
expected = ComplexNumber(-1, 0)
|
139
|
-
self.assertEqual(
|
140
|
-
self.assertEqual(
|
154
|
+
self.assertEqual(input_number.exp().real, expected.real)
|
155
|
+
self.assertEqual(input_number.exp().imaginary, expected.imaginary)
|
141
156
|
|
142
157
|
def test_exponential_of_0(self):
|
143
158
|
input_number = ComplexNumber(0, 0)
|
144
159
|
expected = ComplexNumber(1, 0)
|
145
|
-
self.assertEqual(
|
146
|
-
self.assertEqual(
|
160
|
+
self.assertEqual(input_number.exp().real, expected.real)
|
161
|
+
self.assertEqual(input_number.exp().imaginary, expected.imaginary)
|
147
162
|
|
148
163
|
def test_exponential_of_a_purely_real_number(self):
|
149
164
|
input_number = ComplexNumber(1, 0)
|
150
165
|
expected = ComplexNumber(math.e, 0)
|
151
|
-
self.assertEqual(
|
152
|
-
self.assertEqual(
|
166
|
+
self.assertEqual(input_number.exp().real, expected.real)
|
167
|
+
self.assertEqual(input_number.exp().imaginary, expected.imaginary)
|
153
168
|
|
154
169
|
|
155
170
|
if __name__ == '__main__':
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Connect
|
2
|
+
|
3
|
+
Compute the result for a game of Hex / Polygon.
|
4
|
+
|
5
|
+
The abstract boardgame known as
|
6
|
+
[Hex](https://en.wikipedia.org/wiki/Hex_%28board_game%29) / Polygon /
|
7
|
+
CON-TAC-TIX is quite simple in rules, though complex in practice. Two players
|
8
|
+
place stones on a rhombus with hexagonal fields. The player to connect his/her
|
9
|
+
stones to the opposite side first wins. The four sides of the rhombus are
|
10
|
+
divided between the two players (i.e. one player gets assigned a side and the
|
11
|
+
side directly opposite it and the other player gets assigned the two other
|
12
|
+
sides).
|
13
|
+
|
14
|
+
Your goal is to build a program that given a simple representation of a board
|
15
|
+
computes the winner (or lack thereof). Note that all games need not be "fair".
|
16
|
+
(For example, players may have mismatched piece counts.)
|
17
|
+
|
18
|
+
The boards look like this (with spaces added for readability, which won't be in
|
19
|
+
the representation passed to your code):
|
20
|
+
|
21
|
+
```
|
22
|
+
. O . X .
|
23
|
+
. X X O .
|
24
|
+
O O O X .
|
25
|
+
. X O X O
|
26
|
+
X O O O X
|
27
|
+
```
|
28
|
+
|
29
|
+
"Player `O`" plays from top to bottom, "Player `X`" plays from left to right. In
|
30
|
+
the above example `O` has made a connection from left to right but nobody has
|
31
|
+
won since `O` didn't connect top and bottom.
|
32
|
+
|
33
|
+
### Submitting Exercises
|
34
|
+
|
35
|
+
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
36
|
+
|
37
|
+
For example, if you're submitting `bob.py` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/python/bob/bob.py`.
|
38
|
+
|
39
|
+
|
40
|
+
For more detailed information about running tests, code style and linting,
|
41
|
+
please see the [help page](http://exercism.io/languages/python).
|
42
|
+
|
43
|
+
## Submitting Incomplete Solutions
|
44
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import unittest
|
2
|
+
|
3
|
+
import connect
|
4
|
+
|
5
|
+
|
6
|
+
# Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.0
|
7
|
+
|
8
|
+
testcases = [
|
9
|
+
{
|
10
|
+
"description": "an empty board has no winner",
|
11
|
+
"board":
|
12
|
+
""" . . . . .
|
13
|
+
. . . . .
|
14
|
+
. . . . .
|
15
|
+
. . . . .
|
16
|
+
. . . . .""",
|
17
|
+
"winner": ""
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"description": "O can win on a 1x1 board",
|
21
|
+
"board": "O",
|
22
|
+
"winner": "O"
|
23
|
+
},
|
24
|
+
{
|
25
|
+
"description": "X can win on a 1x1 board",
|
26
|
+
"board": "X",
|
27
|
+
"winner": "X"
|
28
|
+
},
|
29
|
+
{
|
30
|
+
"description": "only edges does not make a winner",
|
31
|
+
"board":
|
32
|
+
""" O O O X
|
33
|
+
X . . X
|
34
|
+
X . . X
|
35
|
+
X O O O""",
|
36
|
+
"winner": ""
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"description": "illegal diagonal does not make a winner",
|
40
|
+
"board":
|
41
|
+
""" X O . .
|
42
|
+
O X X X
|
43
|
+
O X O .
|
44
|
+
. O X .
|
45
|
+
X X O O""",
|
46
|
+
"winner": ""
|
47
|
+
},
|
48
|
+
{
|
49
|
+
"description": "nobody wins crossing adjacent angles",
|
50
|
+
"board":
|
51
|
+
""" X . . .
|
52
|
+
. X O .
|
53
|
+
O . X O
|
54
|
+
. O . X
|
55
|
+
. . O .""",
|
56
|
+
"winner": ""
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"description": "X wins crossing from left to right",
|
60
|
+
"board":
|
61
|
+
""" . O . .
|
62
|
+
O X X X
|
63
|
+
O X O .
|
64
|
+
X X O X
|
65
|
+
. O X .""",
|
66
|
+
"winner": "X"
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"description": "X wins using a convoluted path",
|
70
|
+
"board":
|
71
|
+
""" . X X . .
|
72
|
+
X . X . X
|
73
|
+
. X . X .
|
74
|
+
. X X . .
|
75
|
+
O O O O O""",
|
76
|
+
"winner": "X"
|
77
|
+
},
|
78
|
+
{
|
79
|
+
"description": "O wins crossing from top to bottom",
|
80
|
+
"board":
|
81
|
+
""" . O . .
|
82
|
+
O X X X
|
83
|
+
O O O .
|
84
|
+
X X O X
|
85
|
+
. O X .""",
|
86
|
+
"winner": "O"
|
87
|
+
},
|
88
|
+
{
|
89
|
+
"description": "X wins using a spiral path",
|
90
|
+
"board":
|
91
|
+
""" O X X X X X X X X
|
92
|
+
O X O O O O O O O
|
93
|
+
O X O X X X X X O
|
94
|
+
O X O X O O O X O
|
95
|
+
O X O X X X O X O
|
96
|
+
O X O O O X O X O
|
97
|
+
O X X X X X O X O
|
98
|
+
O O O O O O O X O
|
99
|
+
X X X X X X X X O """,
|
100
|
+
"winner": "X"
|
101
|
+
},
|
102
|
+
]
|
103
|
+
|
104
|
+
|
105
|
+
class ConnectTest(unittest.TestCase):
|
106
|
+
def test_game(self):
|
107
|
+
for testcase in testcases:
|
108
|
+
game = connect.ConnectGame(testcase["board"])
|
109
|
+
winner = game.get_winner()
|
110
|
+
expected = testcase["winner"] if testcase["winner"] else "None"
|
111
|
+
got = winner if winner else "None"
|
112
|
+
self.assertEqual(winner, testcase["winner"],
|
113
|
+
"Test failed: %s, expected winner: %s, got: %s"
|
114
|
+
% (testcase["description"], expected, got))
|
115
|
+
|
116
|
+
|
117
|
+
if __name__ == '__main__':
|
118
|
+
unittest.main()
|