trackler 2.0.8.33 → 2.0.8.34
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/tracks/csharp/exercises/food-chain/Example.cs +2 -2
- data/tracks/csharp/exercises/food-chain/FoodChain.cs +2 -2
- data/tracks/csharp/exercises/food-chain/FoodChainTest.cs +150 -73
- data/tracks/csharp/exercises/luhn/LuhnTest.cs +5 -8
- data/tracks/csharp/generators/Data/CanonicalDataValue.cs +10 -0
- data/tracks/csharp/generators/Exercises/FoodChainExercise.cs +27 -0
- data/tracks/csharp/generators/Exercises/NthPrimeExercise.cs +1 -3
- data/tracks/csharp/generators/Methods/EqualityTestMethodGenerator.cs +25 -1
- data/tracks/csharp/generators/Methods/TestMethodGenerator.cs +16 -4
- data/tracks/csharp/generators/Methods/TestMethodOptions.cs +1 -0
- data/tracks/csharp/generators/Methods/TestMethodRenderer.cs +15 -7
- data/tracks/csharp/generators/Program.cs +2 -0
- data/tracks/java/exercises/difference-of-squares/src/example/java/{Difference.java → DifferenceOfSquaresCalculator.java} +4 -4
- data/tracks/java/exercises/difference-of-squares/src/main/java/DifferenceOfSquaresCalculator.java +5 -0
- data/tracks/java/exercises/difference-of-squares/src/test/java/{DifferenceTest.java → DifferenceOfSquaresCalculatorTest.java} +18 -11
- data/tracks/java/exercises/sum-of-multiples/src/example/java/SumOfMultiples.java +17 -9
- data/tracks/java/exercises/sum-of-multiples/src/test/java/SumOfMultiplesTest.java +73 -88
- data/tracks/perl6/.travis.yml +3 -0
- data/tracks/python/exercises/bob/bob_test.py +47 -71
- data/tracks/python/exercises/leap/leap_test.py +10 -11
- data/tracks/python/exercises/pangram/pangram_test.py +16 -16
- data/tracks/python/exercises/prime-factors/prime_factors_test.py +11 -21
- data/tracks/python/exercises/sieve/sieve_test.py +32 -24
- data/tracks/swift/.gitignore +3 -0
- data/tracks/swift/.swiftlint.yml +4 -2
- data/tracks/swift/exercises/kindergarten-garden/Sources/KindergartenGardenExample.swift +4 -4
- data/tracks/swift/exercises/kindergarten-garden/Tests/KindergartenGardenTests/KindergartenGardenTests.swift +25 -25
- data/tracks/swift/exercises/meetup/Sources/MeetupExample.swift +6 -6
- data/tracks/swift/exercises/poker/Sources/PokerExample.swift +12 -14
- data/tracks/swift/exercises/robot-simulator/Sources/RobotSimulatorExample.swift +6 -6
- data/tracks/swift/exercises/robot-simulator/Tests/RobotSimulatorTests/RobotSimulatorTests.swift +4 -4
- metadata +7 -5
- data/tracks/java/exercises/difference-of-squares/src/main/java/Difference.java +0 -5
@@ -1,4 +1,5 @@
|
|
1
1
|
using System.Collections.Generic;
|
2
|
+
using System.Linq;
|
2
3
|
using Humanizer;
|
3
4
|
using To = Generators.Helpers.To;
|
4
5
|
|
@@ -37,7 +38,7 @@ protected virtual string TestedMethod
|
|
37
38
|
|
38
39
|
protected virtual object Input =>
|
39
40
|
TestMethodData.Options.FormatInput
|
40
|
-
?
|
41
|
+
? FormatInputValue(InputValue)
|
41
42
|
: InputValue;
|
42
43
|
|
43
44
|
protected virtual object Expected =>
|
@@ -45,9 +46,9 @@ protected virtual string TestedMethod
|
|
45
46
|
? FormatValue(TestMethodData.CanonicalDataCase.Expected)
|
46
47
|
: TestMethodData.CanonicalDataCase.Expected;
|
47
48
|
|
48
|
-
protected virtual object InputValue
|
49
|
-
|
50
|
-
? TestMethodData.CanonicalDataCase.Input
|
49
|
+
protected virtual object InputValue =>
|
50
|
+
TestMethodData.Options.InputProperty == null
|
51
|
+
? TestMethodData.CanonicalDataCase.Input
|
51
52
|
: TestMethodData.CanonicalDataCase.Data[TestMethodData.Options.InputProperty];
|
52
53
|
|
53
54
|
protected virtual object FormatValue(object val)
|
@@ -60,5 +61,16 @@ protected virtual object FormatValue(object val)
|
|
60
61
|
return val;
|
61
62
|
}
|
62
63
|
}
|
64
|
+
|
65
|
+
protected virtual object FormatInputValue(object val)
|
66
|
+
{
|
67
|
+
switch (val)
|
68
|
+
{
|
69
|
+
case IEnumerable<object> inputs when !(val is string):
|
70
|
+
return string.Join(", ", inputs.Select(FormatValue));
|
71
|
+
default:
|
72
|
+
return FormatValue(val);
|
73
|
+
}
|
74
|
+
}
|
63
75
|
}
|
64
76
|
}
|
@@ -7,6 +7,7 @@ public class TestMethodOptions
|
|
7
7
|
public string InputProperty { get; set; }
|
8
8
|
public bool FormatInput { get; set; } = true;
|
9
9
|
public bool FormatExpected { get; set; } = true;
|
10
|
+
public bool UseVariableForExpected { get; set; } = false;
|
10
11
|
public Type ExceptionType { get; set; } = typeof(ArgumentException);
|
11
12
|
public TestedMethodType TestedMethodType { get; set; } = TestedMethodType.Static;
|
12
13
|
}
|
@@ -1,18 +1,26 @@
|
|
1
|
-
|
1
|
+
using System.Linq;
|
2
|
+
|
3
|
+
namespace Generators.Methods
|
2
4
|
{
|
3
5
|
public static class TestMethodRenderer
|
4
6
|
{
|
7
|
+
private const string Tab = " ";
|
8
|
+
|
5
9
|
private const string TestMethodTemplate =
|
6
|
-
@"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
@"{Tab}[Fact{Skip}]
|
11
|
+
{Tab}public void {Name}()
|
12
|
+
{Tab}{
|
13
|
+
{Body}
|
14
|
+
{Tab}}";
|
11
15
|
|
12
16
|
public static string Render(TestMethod testMethod) =>
|
13
17
|
TestMethodTemplate
|
18
|
+
.Replace("{Tab}", Tab)
|
14
19
|
.Replace("{Name}", testMethod.MethodName)
|
15
|
-
.Replace("{Body}", testMethod
|
20
|
+
.Replace("{Body}", RenderBody(testMethod))
|
16
21
|
.Replace("{Skip}", testMethod.Index == 0 ? "" : "(Skip = \"Remove to run test\")");
|
22
|
+
|
23
|
+
private static string RenderBody(TestMethod testMethod)
|
24
|
+
=> string.Join("\n", testMethod.Body.Split('\n').Select(line => $"{Tab}{Tab}{line}"));
|
17
25
|
}
|
18
26
|
}
|
@@ -1,19 +1,19 @@
|
|
1
1
|
import java.util.stream.IntStream;
|
2
2
|
|
3
|
-
public final class
|
3
|
+
public final class DifferenceOfSquaresCalculator {
|
4
4
|
|
5
|
-
public
|
5
|
+
public int computeSquareOfSumTo(final int input) {
|
6
6
|
final int sum = input * (input + 1) / 2;
|
7
7
|
return (int) Math.pow(sum, 2);
|
8
8
|
}
|
9
9
|
|
10
|
-
public
|
10
|
+
public int computeSumOfSquaresTo(final int input) {
|
11
11
|
return IntStream.rangeClosed(1, input)
|
12
12
|
.map(i -> (int) Math.pow(i, 2))
|
13
13
|
.sum();
|
14
14
|
}
|
15
15
|
|
16
|
-
public
|
16
|
+
public int computeDifferenceOfSquares(final int input) {
|
17
17
|
return computeSquareOfSumTo(input) - computeSumOfSquaresTo(input);
|
18
18
|
}
|
19
19
|
|
@@ -1,14 +1,21 @@
|
|
1
|
+
import org.junit.Before;
|
1
2
|
import org.junit.Ignore;
|
2
3
|
import org.junit.Test;
|
3
4
|
|
4
5
|
import static org.junit.Assert.assertEquals;
|
5
6
|
|
6
|
-
public final class
|
7
|
+
public final class DifferenceOfSquaresCalculatorTest {
|
8
|
+
private DifferenceOfSquaresCalculator calculator;
|
9
|
+
|
10
|
+
@Before
|
11
|
+
public void setUp() {
|
12
|
+
calculator = new DifferenceOfSquaresCalculator();
|
13
|
+
}
|
7
14
|
|
8
15
|
@Test
|
9
16
|
public void testSquareOfSum5() {
|
10
17
|
final int expected = 225;
|
11
|
-
final int actual =
|
18
|
+
final int actual = calculator.computeSquareOfSumTo(5);
|
12
19
|
assertEquals(expected, actual);
|
13
20
|
}
|
14
21
|
|
@@ -16,7 +23,7 @@ public final class DifferenceTest {
|
|
16
23
|
@Test
|
17
24
|
public void testSquareOfSum10() {
|
18
25
|
final int expected = 3025;
|
19
|
-
final int actual =
|
26
|
+
final int actual = calculator.computeSquareOfSumTo(10);
|
20
27
|
assertEquals(expected, actual);
|
21
28
|
}
|
22
29
|
|
@@ -24,7 +31,7 @@ public final class DifferenceTest {
|
|
24
31
|
@Test
|
25
32
|
public void testSquareOfSum100() {
|
26
33
|
final int expected = 25502500;
|
27
|
-
final int actual =
|
34
|
+
final int actual = calculator.computeSquareOfSumTo(100);
|
28
35
|
assertEquals(expected, actual);
|
29
36
|
}
|
30
37
|
|
@@ -32,7 +39,7 @@ public final class DifferenceTest {
|
|
32
39
|
@Test
|
33
40
|
public void testSumOfSquares5() {
|
34
41
|
final int expected = 55;
|
35
|
-
final int actual =
|
42
|
+
final int actual = calculator.computeSumOfSquaresTo(5);
|
36
43
|
assertEquals(expected, actual);
|
37
44
|
}
|
38
45
|
|
@@ -40,7 +47,7 @@ public final class DifferenceTest {
|
|
40
47
|
@Test
|
41
48
|
public void testSumOfSquares10() {
|
42
49
|
final int expected = 385;
|
43
|
-
final int actual =
|
50
|
+
final int actual = calculator.computeSumOfSquaresTo(10);
|
44
51
|
assertEquals(expected, actual);
|
45
52
|
}
|
46
53
|
|
@@ -48,7 +55,7 @@ public final class DifferenceTest {
|
|
48
55
|
@Test
|
49
56
|
public void testSumOfSquares100() {
|
50
57
|
final int expected = 338350;
|
51
|
-
final int actual =
|
58
|
+
final int actual = calculator.computeSumOfSquaresTo(100);
|
52
59
|
assertEquals(expected, actual);
|
53
60
|
}
|
54
61
|
|
@@ -56,7 +63,7 @@ public final class DifferenceTest {
|
|
56
63
|
@Test
|
57
64
|
public void testDifferenceOfSquares0() {
|
58
65
|
final int expected = 0;
|
59
|
-
final int actual =
|
66
|
+
final int actual = calculator.computeDifferenceOfSquares(0);
|
60
67
|
assertEquals(expected, actual);
|
61
68
|
}
|
62
69
|
|
@@ -64,7 +71,7 @@ public final class DifferenceTest {
|
|
64
71
|
@Test
|
65
72
|
public void testDifferenceOfSquares5() {
|
66
73
|
final int expected = 170;
|
67
|
-
final int actual =
|
74
|
+
final int actual = calculator.computeDifferenceOfSquares(5);
|
68
75
|
assertEquals(expected, actual);
|
69
76
|
}
|
70
77
|
|
@@ -72,7 +79,7 @@ public final class DifferenceTest {
|
|
72
79
|
@Test
|
73
80
|
public void testDifferenceOfSquares10() {
|
74
81
|
final int expected = 2640;
|
75
|
-
final int actual =
|
82
|
+
final int actual = calculator.computeDifferenceOfSquares(10);
|
76
83
|
assertEquals(expected, actual);
|
77
84
|
}
|
78
85
|
|
@@ -80,7 +87,7 @@ public final class DifferenceTest {
|
|
80
87
|
@Test
|
81
88
|
public void testDifferenceOfSquares100() {
|
82
89
|
final int expected = 25164150;
|
83
|
-
final int actual =
|
90
|
+
final int actual = calculator.computeDifferenceOfSquares(100);
|
84
91
|
assertEquals(expected, actual);
|
85
92
|
}
|
86
93
|
|
@@ -1,26 +1,34 @@
|
|
1
1
|
public class SumOfMultiples {
|
2
|
-
|
3
|
-
|
4
|
-
public
|
5
|
-
|
2
|
+
private final int sum;
|
3
|
+
|
4
|
+
public SumOfMultiples(int number, int[] set) {
|
5
|
+
sum = calculateSum(number, set);
|
6
|
+
}
|
7
|
+
|
8
|
+
public int getSum() {
|
9
|
+
return sum;
|
10
|
+
}
|
11
|
+
|
12
|
+
private int calculateSum(int number, int[] set) {
|
13
|
+
|
6
14
|
int sum = 0;
|
7
15
|
int count = 0;
|
8
|
-
|
16
|
+
|
9
17
|
for (int i = 1; i < number; i++) {
|
10
|
-
|
18
|
+
|
11
19
|
for (int j = 0; j < set.length; j++) {
|
12
20
|
if (i % set[j] == 0) {
|
13
21
|
count++;
|
14
22
|
}
|
15
23
|
}
|
16
|
-
|
24
|
+
|
17
25
|
if (count > 0) {
|
18
26
|
sum = sum + i;
|
19
27
|
count = 0;
|
20
28
|
}
|
21
29
|
}
|
22
|
-
|
30
|
+
|
23
31
|
return sum;
|
24
32
|
}
|
25
|
-
|
33
|
+
|
26
34
|
}
|
@@ -1,175 +1,160 @@
|
|
1
|
-
import static org.junit.Assert.*;
|
2
|
-
|
3
1
|
import org.junit.Ignore;
|
4
2
|
import org.junit.Test;
|
5
3
|
|
4
|
+
import static org.junit.Assert.*;
|
5
|
+
|
6
6
|
public class SumOfMultiplesTest {
|
7
|
-
|
8
|
-
|
7
|
+
|
9
8
|
@Test
|
10
9
|
public void testSumOfMultiplesOf3and4UpToOne() {
|
11
|
-
|
10
|
+
|
12
11
|
int[] set = {
|
13
|
-
|
14
|
-
|
12
|
+
3,
|
13
|
+
5
|
15
14
|
};
|
16
|
-
int output = SumOfMultiples
|
15
|
+
int output = new SumOfMultiples(1, set).getSum();
|
17
16
|
assertEquals(0, output);
|
18
|
-
|
17
|
+
|
19
18
|
}
|
20
|
-
|
21
|
-
|
19
|
+
|
22
20
|
@Test
|
23
21
|
@Ignore
|
24
22
|
public void testSumOfMultiplesOf3and5UpToFour() {
|
25
|
-
|
23
|
+
|
26
24
|
int[] set = {
|
27
|
-
|
28
|
-
|
25
|
+
3,
|
26
|
+
5
|
29
27
|
};
|
30
|
-
int output = SumOfMultiples
|
28
|
+
int output = new SumOfMultiples(4, set).getSum();
|
31
29
|
assertEquals(3, output);
|
32
|
-
|
30
|
+
|
33
31
|
}
|
34
|
-
|
35
|
-
|
32
|
+
|
36
33
|
@Test
|
37
34
|
@Ignore
|
38
35
|
public void testSumOfMultiplesOf3and5UpToTen() {
|
39
|
-
|
36
|
+
|
40
37
|
int[] set = {
|
41
|
-
|
42
|
-
|
38
|
+
3,
|
39
|
+
5
|
43
40
|
};
|
44
|
-
int output = SumOfMultiples
|
41
|
+
int output = new SumOfMultiples(10, set).getSum();
|
45
42
|
assertEquals(23, output);
|
46
|
-
|
43
|
+
|
47
44
|
}
|
48
|
-
|
49
|
-
|
45
|
+
|
50
46
|
@Test
|
51
47
|
@Ignore
|
52
48
|
public void testSumOfMultiplesOf3and5UpToOneHundred() {
|
53
|
-
|
49
|
+
|
54
50
|
int[] set = {
|
55
|
-
|
56
|
-
|
51
|
+
3,
|
52
|
+
5
|
57
53
|
};
|
58
|
-
int output = SumOfMultiples
|
54
|
+
int output = new SumOfMultiples(100, set).getSum();
|
59
55
|
assertEquals(2318, output);
|
60
|
-
|
56
|
+
|
61
57
|
}
|
62
|
-
|
63
|
-
|
58
|
+
|
64
59
|
@Test
|
65
60
|
@Ignore
|
66
61
|
public void testSumOfMultiplesOf3and5UpToOneThousand() {
|
67
|
-
|
62
|
+
|
68
63
|
int[] set = {
|
69
|
-
|
70
|
-
|
64
|
+
3,
|
65
|
+
5
|
71
66
|
};
|
72
|
-
int output = SumOfMultiples
|
67
|
+
int output = new SumOfMultiples(1000, set).getSum();
|
73
68
|
assertEquals(233168, output);
|
74
|
-
|
69
|
+
|
75
70
|
}
|
76
|
-
|
77
|
-
|
71
|
+
|
78
72
|
@Test
|
79
73
|
@Ignore
|
80
74
|
public void testSumOfMultiplesOf7and13and17UpToTwenty() {
|
81
|
-
|
75
|
+
|
82
76
|
int[] set = {
|
83
|
-
|
84
|
-
|
85
|
-
|
77
|
+
7,
|
78
|
+
13,
|
79
|
+
17
|
86
80
|
};
|
87
|
-
int output = SumOfMultiples
|
81
|
+
int output = new SumOfMultiples(20, set).getSum();
|
88
82
|
assertEquals(51, output);
|
89
|
-
|
83
|
+
|
90
84
|
}
|
91
|
-
|
92
|
-
|
85
|
+
|
93
86
|
@Test
|
94
87
|
@Ignore
|
95
88
|
public void testSumOfMultiplesOf4and6UpToFifteen() {
|
96
|
-
|
89
|
+
|
97
90
|
int[] set = {
|
98
|
-
|
99
|
-
|
91
|
+
4,
|
92
|
+
6
|
100
93
|
};
|
101
|
-
int output = SumOfMultiples
|
94
|
+
int output = new SumOfMultiples(15, set).getSum();
|
102
95
|
assertEquals(30, output);
|
103
|
-
|
96
|
+
|
104
97
|
}
|
105
|
-
|
106
|
-
|
98
|
+
|
107
99
|
@Test
|
108
100
|
@Ignore
|
109
101
|
public void testSumOfMultiplesOf5and6and8UpToOneHundredFifty() {
|
110
|
-
|
102
|
+
|
111
103
|
int[] set = {
|
112
|
-
|
113
|
-
|
114
|
-
|
104
|
+
5,
|
105
|
+
6,
|
106
|
+
8
|
115
107
|
};
|
116
|
-
int output = SumOfMultiples
|
108
|
+
int output = new SumOfMultiples(150, set).getSum();
|
117
109
|
assertEquals(4419, output);
|
118
|
-
|
110
|
+
|
119
111
|
}
|
120
|
-
|
121
|
-
|
112
|
+
|
122
113
|
@Test
|
123
114
|
@Ignore
|
124
115
|
public void testSumOfMultiplesOf5and25UpToTwoHundredSeventyFive() {
|
125
|
-
|
116
|
+
|
126
117
|
int[] set = {
|
127
|
-
|
128
|
-
|
118
|
+
5,
|
119
|
+
25
|
129
120
|
};
|
130
|
-
int output = SumOfMultiples
|
121
|
+
int output = new SumOfMultiples(51, set).getSum();
|
131
122
|
assertEquals(275, output);
|
132
|
-
|
123
|
+
|
133
124
|
}
|
134
|
-
|
135
|
-
|
125
|
+
|
136
126
|
@Test
|
137
127
|
@Ignore
|
138
128
|
public void testSumOfMultiplesOf43and47UpToTenThousand() {
|
139
|
-
|
129
|
+
|
140
130
|
int[] set = {
|
141
|
-
|
142
|
-
|
131
|
+
43,
|
132
|
+
47
|
143
133
|
};
|
144
|
-
int output = SumOfMultiples
|
134
|
+
int output = new SumOfMultiples(10000, set).getSum();
|
145
135
|
assertEquals(2203160, output);
|
146
|
-
|
136
|
+
|
147
137
|
}
|
148
|
-
|
149
|
-
|
138
|
+
|
150
139
|
@Test
|
151
140
|
@Ignore
|
152
141
|
public void testSumOfMultiplesOfOneUpToOneHundred() {
|
153
|
-
|
142
|
+
|
154
143
|
int[] set = {
|
155
|
-
|
144
|
+
1
|
156
145
|
};
|
157
|
-
int output = SumOfMultiples
|
146
|
+
int output = new SumOfMultiples(100, set).getSum();
|
158
147
|
assertEquals(4950, output);
|
159
|
-
|
148
|
+
|
160
149
|
}
|
161
|
-
|
162
|
-
|
150
|
+
|
163
151
|
@Test
|
164
152
|
@Ignore
|
165
153
|
public void testSumOfMultiplesOfNoneUpToTenThousand() {
|
166
|
-
|
154
|
+
|
167
155
|
int[] set = {};
|
168
|
-
int output = SumOfMultiples
|
156
|
+
int output = new SumOfMultiples(10000, set).getSum();
|
169
157
|
assertEquals(0, output);
|
170
|
-
|
158
|
+
|
171
159
|
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
160
|
}
|