Sfoglia il codice sorgente

Merge branch 'master' into JourneyTestMakeWorkWithExercises

Frida Tveit 9 anni fa
parent
commit
c07ec34a0f

+ 8
- 0
.travis.yml Vedi File

3
 jdk:
3
 jdk:
4
   - oraclejdk8
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
 # http://docs.travis-ci.com/user/migrating-from-legacy
14
 # http://docs.travis-ci.com/user/migrating-from-legacy
7
 sudo: false
15
 sudo: false
8
 cache: bundler
16
 cache: bundler

+ 1
- 1
README.md Vedi File

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
 Source for Exercism Exercises in Java.
3
 Source for Exercism Exercises in Java.
4
 
4
 

+ 7
- 1
config.json Vedi File

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

+ 4
- 0
exercises/etl/src/test/java/EtlTest.java Vedi File

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

+ 6
- 0
exercises/hello-world/src/test/java/HelloWorldTest.java Vedi File

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

+ 17
- 0
exercises/perfect-numbers/build.gradle Vedi File

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 Vedi File

1
+../../main/java/Classification.java

+ 30
- 0
exercises/perfect-numbers/src/example/java/NaturalNumber.java Vedi File

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 Vedi File

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

+ 5
- 0
exercises/perfect-numbers/src/main/java/NaturalNumber.java Vedi File

1
+final class NaturalNumber {
2
+
3
+
4
+
5
+}

+ 61
- 0
exercises/perfect-numbers/src/test/java/NaturalNumberTest.java Vedi File

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 Vedi File

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