Quellcode durchsuchen

Issue #166: Added format string to @Parameters annotation in Scrabble… (#222)

* Added format string to @Parameters annotation in and (to make them more descriptive) changed names of variables and tests in:
  * AtbashTest,
  * BinaryTest,
  * OctalTest,
  * PigLatinTest,
  * RaindropsTest,
  * RomanNumeralsTest,
  * ScrabbleScoreTest.
* Removed repeated word in format string for PiglatinTest and ScrabbleScoreTest.

Fixes #160.
Fixes #161.
Fixes #162.
Fixes #163.
Fixes #164.
Fixes #165.
Fixes #166.
FridaTveit vor 9 Jahren
Ursprung
Commit
9dcf9a2ceb

+ 7
- 7
exercises/atbash-cipher/src/test/java/AtbashTest.java Datei anzeigen

15
 
15
 
16
     @RunWith(Parameterized.class)
16
     @RunWith(Parameterized.class)
17
     public static class EncodeTest {
17
     public static class EncodeTest {
18
-        private String input;
19
-        private String expectedOutput;
18
+        private String plaintext;
19
+        private String ciphertext;
20
 
20
 
21
-        @Parameters
21
+        @Parameters(name = "{index}: expected plaintext \"{0}\" to encode to ciphertext \"{1}\".")
22
         public static Collection<Object[]> data() {
22
         public static Collection<Object[]> data() {
23
             return Arrays.asList(new Object[][] {
23
             return Arrays.asList(new Object[][] {
24
                     { "no", "ml" },
24
                     { "no", "ml" },
31
             });
31
             });
32
         }
32
         }
33
 
33
 
34
-        public EncodeTest(String input, String expectedOutput) {
35
-            this.input = input;
36
-            this.expectedOutput = expectedOutput;
34
+        public EncodeTest(String plaintext, String ciphertext) {
35
+            this.plaintext = plaintext;
36
+            this.ciphertext = ciphertext;
37
         }
37
         }
38
 
38
 
39
 
39
 
40
     @Test
40
     @Test
41
         public void test() {
41
         public void test() {
42
-            assertEquals(expectedOutput, Atbash.encode(input));
42
+            assertEquals(ciphertext, Atbash.encode(plaintext));
43
         }
43
         }
44
     }
44
     }
45
 
45
 

+ 8
- 8
exercises/binary/src/test/java/BinaryTest.java Datei anzeigen

12
 @RunWith(Parameterized.class)
12
 @RunWith(Parameterized.class)
13
 public class BinaryTest {
13
 public class BinaryTest {
14
 
14
 
15
-    private String input;
16
-    private int expectedOutput;
15
+    private String binaryNumberAsString;
16
+    private int decimalNumber;
17
 
17
 
18
-    @Parameters
18
+    @Parameters(name = "{index}: expected {1} when converting \"{0}\" from binary to decimal.")
19
     public static Collection<Object[]> data() {
19
     public static Collection<Object[]> data() {
20
         return Arrays.asList(new Object[][]{
20
         return Arrays.asList(new Object[][]{
21
                 {"1", 1},
21
                 {"1", 1},
34
         });
34
         });
35
     }
35
     }
36
 
36
 
37
-    public BinaryTest(String input, int expectedOutput) {
38
-        this.input = input;
39
-        this.expectedOutput = expectedOutput;
37
+    public BinaryTest(String binaryNumberAsString, int decimalNumber) {
38
+        this.binaryNumberAsString = binaryNumberAsString;
39
+        this.decimalNumber = decimalNumber;
40
     }
40
     }
41
 
41
 
42
 
42
 
43
     @Test
43
     @Test
44
     public void test() {
44
     public void test() {
45
-        Binary binary = new Binary(input);
45
+        Binary binary = new Binary(binaryNumberAsString);
46
 
46
 
47
-        assertEquals(expectedOutput, binary.getDecimal());
47
+        assertEquals(decimalNumber, binary.getDecimal());
48
     }
48
     }
49
 }
49
 }

+ 8
- 8
exercises/octal/src/test/java/OctalTest.java Datei anzeigen

11
 @RunWith(Parameterized.class)
11
 @RunWith(Parameterized.class)
12
 public class OctalTest {
12
 public class OctalTest {
13
 
13
 
14
-    private String input;
15
-    private int expectedOutput;
14
+    private String octalNumberAsString;
15
+    private int decimalNumber;
16
 
16
 
17
-    @Parameterized.Parameters
17
+    @Parameterized.Parameters(name = "{index}: expected {1} when converting \"{0}\" from octal to decimal.")
18
     public static Collection<Object[]> data() {
18
     public static Collection<Object[]> data() {
19
         return Arrays.asList(new Object[][]{
19
         return Arrays.asList(new Object[][]{
20
                 {"1", 1},
20
                 {"1", 1},
34
         });
34
         });
35
     }
35
     }
36
 
36
 
37
-    public OctalTest(String input, int expectedOutput) {
38
-        this.input = input;
39
-        this.expectedOutput = expectedOutput;
37
+    public OctalTest(String octalNumberAsString, int decimalNumber) {
38
+        this.octalNumberAsString = octalNumberAsString;
39
+        this.decimalNumber = decimalNumber;
40
     }
40
     }
41
 
41
 
42
 
42
 
43
     @Test
43
     @Test
44
     public void test() {
44
     public void test() {
45
-        Octal octal = new Octal(input);
45
+        Octal octal = new Octal(octalNumberAsString);
46
 
46
 
47
-        assertEquals(expectedOutput, octal.getDecimal());
47
+        assertEquals(decimalNumber, octal.getDecimal());
48
     }
48
     }
49
 }
49
 }

+ 7
- 7
exercises/pig-latin/src/test/java/PigLatinTest.java Datei anzeigen

11
 @RunWith(Parameterized.class)
11
 @RunWith(Parameterized.class)
12
 public class PigLatinTest {
12
 public class PigLatinTest {
13
 
13
 
14
-    private String input;
15
-    private String expectedOutput;
14
+    private String englishPhrase;
15
+    private String pigLatinTranslation;
16
 
16
 
17
-    @Parameterized.Parameters
17
+    @Parameterized.Parameters(name = "{index}: expected \"{0}\" to translate to the pig latin phrase \"{1}\"")
18
     public static Collection<Object[]> data() {
18
     public static Collection<Object[]> data() {
19
         return Arrays.asList(new Object[][]{
19
         return Arrays.asList(new Object[][]{
20
                 // Ay is added to words that start with vowels
20
                 // Ay is added to words that start with vowels
59
         });
59
         });
60
     }
60
     }
61
 
61
 
62
-    public PigLatinTest(String input, String expectedOutput) {
63
-        this.input = input;
64
-        this.expectedOutput = expectedOutput;
62
+    public PigLatinTest(String englishPhrase, String pigLatinTranslation) {
63
+        this.englishPhrase = englishPhrase;
64
+        this.pigLatinTranslation = pigLatinTranslation;
65
     }
65
     }
66
 
66
 
67
 
67
 
68
     @Test
68
     @Test
69
     public void test() {
69
     public void test() {
70
-        assertEquals(expectedOutput, PigLatin.translate(input));
70
+        assertEquals(pigLatinTranslation, PigLatin.translate(englishPhrase));
71
     }
71
     }
72
 }
72
 }

+ 7
- 7
exercises/raindrops/src/test/java/RaindropsTest.java Datei anzeigen

12
 @RunWith(Parameterized.class)
12
 @RunWith(Parameterized.class)
13
 public class RaindropsTest {
13
 public class RaindropsTest {
14
 
14
 
15
-    private int input;
16
-    private String expectedOutput;
15
+    private int inputNumber;
16
+    private String outputFromRaindropConversion;
17
 
17
 
18
-    @Parameters
18
+    @Parameters(name = "{index}: expected input number {0} to be converted to \"{1}\"")
19
     public static Collection<Object[]> data() {
19
     public static Collection<Object[]> data() {
20
         return Arrays.asList(new Object[][]{
20
         return Arrays.asList(new Object[][]{
21
                 // Non-primes
21
                 // Non-primes
46
         });
46
         });
47
     }
47
     }
48
 
48
 
49
-    public RaindropsTest(int input, String expectedOutput) {
50
-        this.input = input;
51
-        this.expectedOutput = expectedOutput;
49
+    public RaindropsTest(int inputNumber, String outputFromRaindropConversion) {
50
+        this.inputNumber = inputNumber;
51
+        this.outputFromRaindropConversion = outputFromRaindropConversion;
52
     }
52
     }
53
 
53
 
54
 
54
 
55
     @Test
55
     @Test
56
     public void test() {
56
     public void test() {
57
-        assertEquals(expectedOutput, Raindrops.convert(input));
57
+        assertEquals(outputFromRaindropConversion, Raindrops.convert(inputNumber));
58
     }
58
     }
59
 }
59
 }

+ 8
- 8
exercises/roman-numerals/src/test/java/RomanNumeralsTest.java Datei anzeigen

12
 @RunWith(Parameterized.class)
12
 @RunWith(Parameterized.class)
13
 public class RomanNumeralsTest {
13
 public class RomanNumeralsTest {
14
 
14
 
15
-    private int input;
16
-    private String expectedOutput;
15
+    private int arabicNumeral;
16
+    private String romanNumeral;
17
 
17
 
18
-    @Parameters
18
+    @Parameters(name = "{index}: expected arabic numeral {0} to be converted to roman numeral \"{1}\".")
19
     public static Collection<Object[]> data() {
19
     public static Collection<Object[]> data() {
20
         return Arrays.asList(new Object[][]{
20
         return Arrays.asList(new Object[][]{
21
                 {0, ""},
21
                 {0, ""},
40
         });
40
         });
41
     }
41
     }
42
 
42
 
43
-    public RomanNumeralsTest(int input, String expectedOutput) {
44
-        this.input = input;
45
-        this.expectedOutput = expectedOutput;
43
+    public RomanNumeralsTest(int arabicNumeral, String romanNumeral) {
44
+        this.arabicNumeral = arabicNumeral;
45
+        this.romanNumeral = romanNumeral;
46
     }
46
     }
47
 
47
 
48
 
48
 
49
     @Test
49
     @Test
50
     public void convertArabicNumberalToRomanNumeral() {
50
     public void convertArabicNumberalToRomanNumeral() {
51
-        RomanNumeral romanNumeral = new RomanNumeral(input);
51
+        RomanNumeral romanNumeral = new RomanNumeral(arabicNumeral);
52
 
52
 
53
-        assertEquals(expectedOutput, romanNumeral.getRomanNumeral());
53
+        assertEquals(this.romanNumeral, romanNumeral.getRomanNumeral());
54
     }
54
     }
55
 }
55
 }

+ 8
- 8
exercises/scrabble-score/src/test/java/ScrabbleScoreTest.java Datei anzeigen

11
 @RunWith(Parameterized.class)
11
 @RunWith(Parameterized.class)
12
 public class ScrabbleScoreTest {
12
 public class ScrabbleScoreTest {
13
 
13
 
14
-    private String input;
15
-    private int expectedOutput;
14
+    private String scrabbleInput;
15
+    private int scrabbleScore;
16
 
16
 
17
-    @Parameterized.Parameters
17
+    @Parameterized.Parameters(name = "{index}: expected scrabble score for \"{0}\" to be {1}")
18
     public static Collection<Object[]> data() {
18
     public static Collection<Object[]> data() {
19
         return Arrays.asList(new Object[][]{
19
         return Arrays.asList(new Object[][]{
20
                 {"", 0},
20
                 {"", 0},
29
         });
29
         });
30
     }
30
     }
31
 
31
 
32
-    public ScrabbleScoreTest(String input, int expectedOutput) {
33
-        this.input = input;
34
-        this.expectedOutput = expectedOutput;
32
+    public ScrabbleScoreTest(String scrabbleInput, int scrabbleScore) {
33
+        this.scrabbleInput = scrabbleInput;
34
+        this.scrabbleScore = scrabbleScore;
35
     }
35
     }
36
 
36
 
37
 
37
 
38
     @Test
38
     @Test
39
     public void test() {
39
     public void test() {
40
-        Scrabble scrabble = new Scrabble(input);
40
+        Scrabble scrabble = new Scrabble(scrabbleInput);
41
 
41
 
42
-        assertEquals(expectedOutput, scrabble.getScore());
42
+        assertEquals(scrabbleScore, scrabble.getScore());
43
     }
43
     }
44
 }
44
 }