Просмотр исходного кода

Merge branch 'master' into JourneyTestMakeWorkWithExercises

Frida Tveit 9 лет назад
Родитель
Сommit
c07ec34a0f

+ 8
- 0
.travis.yml Просмотреть файл

@@ -3,6 +3,14 @@ language: java
3 3
 jdk:
4 4
   - oraclejdk8
5 5
 
6
+notifications:
7
+  webhooks:
8
+    urls:
9
+      - https://webhooks.gitter.im/e/5e9ccd41111917b19478
10
+    on_success: change  # options: [always|never|change] default: always
11
+    on_failure: always  # options: [always|never|change] default: always
12
+    on_start: never     # options: [always|never|change] default: always
13
+
6 14
 # http://docs.travis-ci.com/user/migrating-from-legacy
7 15
 sudo: false
8 16
 cache: bundler

+ 1
- 1
README.md Просмотреть файл

@@ -1,4 +1,4 @@
1
-# xJava [![Build Status](https://travis-ci.org/exercism/xjava.svg?branch=master)](https://travis-ci.org/exercism/xjava)
1
+# xJava [![Build Status](https://travis-ci.org/exercism/xjava.svg?branch=master)](https://travis-ci.org/exercism/xjava) [![Join the chat at https://gitter.im/exercism/xjava](https://badges.gitter.im/exercism/xjava.svg)](https://gitter.im/exercism/xjava?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2 2
 
3 3
 Source for Exercism Exercises in Java.
4 4
 

+ 7
- 1
config.json Просмотреть файл

@@ -61,7 +61,8 @@
61 61
     "clock",
62 62
     "diamond",
63 63
     "secret-handshake",
64
-    "flatten-array"
64
+    "flatten-array",
65
+    "perfect-numbers"
65 66
   ],
66 67
   "exercises": [
67 68
     {
@@ -353,6 +354,11 @@
353 354
       "slug": "flatten-array",
354 355
       "difficulty": 1,
355 356
       "topics": []
357
+    },
358
+    {
359
+      "slug": "perfect-numbers",
360
+      "difficulty": 1,
361
+      "topics": []
356 362
     }
357 363
   ],
358 364
   "deprecated": [

+ 4
- 0
exercises/etl/src/test/java/EtlTest.java Просмотреть файл

@@ -1,4 +1,5 @@
1 1
 import org.junit.Test;
2
+import org.junit.Ignore;
2 3
 
3 4
 import java.util.*;
4 5
 
@@ -27,6 +28,7 @@ public class EtlTest {
27 28
         assertEquals(expected, etl.transform(old));
28 29
     }
29 30
 
31
+    @Ignore
30 32
     @Test
31 33
     public void testTransformMoreValues() {
32 34
         Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
@@ -50,6 +52,7 @@ public class EtlTest {
50 52
         assertEquals(expected, etl.transform(old));
51 53
     }
52 54
 
55
+    @Ignore
53 56
     @Test
54 57
     public void testMoreKeys() {
55 58
         Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {
@@ -73,6 +76,7 @@ public class EtlTest {
73 76
         assertEquals(expected, etl.transform(old));
74 77
     }
75 78
 
79
+    @Ignore
76 80
     @Test
77 81
     public void testFullDataset() {
78 82
         Map<Integer, List<String>> old = new HashMap<Integer, List<String>>() {

+ 6
- 0
exercises/hello-world/src/test/java/HelloWorldTest.java Просмотреть файл

@@ -14,6 +14,12 @@ public class HelloWorldTest {
14 14
 
15 15
     @Test
16 16
     @Ignore
17
+    public void emptyStringIsComparedByValue() {
18
+        assertEquals("Hello, World!", HelloWorld.hello(new String("")));
19
+    }
20
+    
21
+    @Test
22
+    @Ignore
17 23
     public void helloSampleName() {
18 24
         assertEquals("Hello, Alice!", HelloWorld.hello("Alice"));
19 25
     }

+ 17
- 0
exercises/perfect-numbers/build.gradle Просмотреть файл

@@ -0,0 +1,17 @@
1
+apply plugin: "java"
2
+apply plugin: "eclipse"
3
+apply plugin: "idea"
4
+
5
+repositories {
6
+  mavenCentral()
7
+}
8
+
9
+dependencies {
10
+  testCompile "junit:junit:4.12"
11
+}
12
+test {
13
+  testLogging {
14
+    exceptionFormat = 'full'
15
+    events = ["passed", "failed", "skipped"]
16
+  }
17
+}

+ 1
- 0
exercises/perfect-numbers/src/example/java/Classification.java Просмотреть файл

@@ -0,0 +1 @@
1
+../../main/java/Classification.java

+ 30
- 0
exercises/perfect-numbers/src/example/java/NaturalNumber.java Просмотреть файл

@@ -0,0 +1,30 @@
1
+import java.util.stream.IntStream;
2
+
3
+final class NaturalNumber {
4
+
5
+    private final int naturalNumber;
6
+
7
+    NaturalNumber(int naturalNumber) {
8
+        if (naturalNumber <= 0) throw new IllegalStateException("Natural numbers are all positive.");
9
+        this.naturalNumber = naturalNumber;
10
+    }
11
+
12
+    Classification getClassification() {
13
+        final int aliquotSum = computeAliquotSum();
14
+
15
+        if (aliquotSum == naturalNumber) {
16
+            return Classification.PERFECT;
17
+        } else if (aliquotSum > naturalNumber) {
18
+            return Classification.ABUNDANT;
19
+        } else {
20
+            return Classification.DEFICIENT;
21
+        }
22
+    }
23
+
24
+    private int computeAliquotSum() {
25
+        return IntStream.range(1, naturalNumber)
26
+                .filter(it -> naturalNumber % it == 0)
27
+                .sum();
28
+    }
29
+
30
+}

+ 5
- 0
exercises/perfect-numbers/src/main/java/Classification.java Просмотреть файл

@@ -0,0 +1,5 @@
1
+enum Classification {
2
+
3
+    DEFICIENT, PERFECT, ABUNDANT
4
+
5
+}

+ 5
- 0
exercises/perfect-numbers/src/main/java/NaturalNumber.java Просмотреть файл

@@ -0,0 +1,5 @@
1
+final class NaturalNumber {
2
+
3
+
4
+
5
+}

+ 61
- 0
exercises/perfect-numbers/src/test/java/NaturalNumberTest.java Просмотреть файл

@@ -0,0 +1,61 @@
1
+import org.junit.Ignore;
2
+import org.junit.Test;
3
+
4
+import static org.junit.Assert.assertEquals;
5
+
6
+public final class NaturalNumberTest {
7
+
8
+    @Test
9
+    public void testSmallPerfectNumberIsClassifiedCorrectly() {
10
+        assertEquals(Classification.PERFECT, new NaturalNumber(6).getClassification());
11
+    }
12
+
13
+    @Ignore
14
+    @Test
15
+    public void testMediumPerfectNumberIsClassifiedCorrectly() {
16
+        assertEquals(Classification.PERFECT, new NaturalNumber(28).getClassification());
17
+    }
18
+
19
+    @Ignore
20
+    @Test
21
+    public void testLargePerfectNumberIsClassifiedCorrectly() {
22
+        assertEquals(Classification.PERFECT, new NaturalNumber(33550336).getClassification());
23
+    }
24
+
25
+    @Ignore
26
+    @Test
27
+    public void testSmallAbundantNumberIsClassifiedCorrectly() {
28
+        assertEquals(Classification.ABUNDANT, new NaturalNumber(12).getClassification());
29
+    }
30
+
31
+    @Ignore
32
+    @Test
33
+    public void testMediumAbundantNumberIsClassifiedCorrectly() {
34
+        assertEquals(Classification.ABUNDANT, new NaturalNumber(24).getClassification());
35
+    }
36
+
37
+    @Ignore
38
+    @Test
39
+    public void testLargeAbundantNumberIsClassifiedCorrectly() {
40
+        assertEquals(Classification.ABUNDANT, new NaturalNumber(33550335).getClassification());
41
+    }
42
+
43
+    @Ignore
44
+    @Test
45
+    public void testSmallDeficientNumberIsClassifiedCorrectly() {
46
+        assertEquals(Classification.DEFICIENT, new NaturalNumber(8).getClassification());
47
+    }
48
+
49
+    @Ignore
50
+    @Test
51
+    public void testMediumNumberIsClassifiedCorrectly() {
52
+        assertEquals(Classification.DEFICIENT, new NaturalNumber(31).getClassification());
53
+    }
54
+
55
+    @Ignore
56
+    @Test
57
+    public void testLargeDeficientNumberIsClassifiedCorrectly() {
58
+        assertEquals(Classification.DEFICIENT, new NaturalNumber(33550337).getClassification());
59
+    }
60
+
61
+}

+ 1
- 0
exercises/settings.gradle Просмотреть файл

@@ -34,6 +34,7 @@ include 'octal'
34 34
 include 'palindrome-products'
35 35
 include 'pangram'
36 36
 include 'pascals-triangle'
37
+include 'perfect-numbers'
37 38
 include 'phone-number'
38 39
 include 'pig-latin'
39 40
 include 'prime-factors'