generated from ohjelmointi2/gradle-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMorseCodeTest.java
More file actions
66 lines (53 loc) · 2.22 KB
/
MorseCodeTest.java
File metadata and controls
66 lines (53 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package part04;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
public class MorseCodeTest {
private MorseCode solution = new MorseCode();
/**
* The tests in this class are skipped, if the methods in the MorseCode class
* have not been implemented.
*/
@BeforeAll
static void skipTheseTestsIfMorseCodeIsNotImplemented() {
MorseCode morseCode = new MorseCode();
assumeTrue(morseCode.textToMorse("a") != null || morseCode.morseToText(".-") != null);
}
@Test
void morseToTextTranslatesCommonCharactersCorrectly() {
assertEqualsIgnoreCase("a", solution.morseToText(".-"));
assertEqualsIgnoreCase("x", solution.morseToText("-..-"));
}
@Test
void morseToTextUsesASpaceBetweenCharacters() {
assertEqualsIgnoreCase("hello", solution.morseToText(".... . .-.. .-.. ---"));
}
@Test
void morseToTextUsesThreeSpacesBetweenWords() {
assertEqualsIgnoreCase("hello world", solution.morseToText(".... . .-.. .-.. --- .-- --- .-. .-.. -.."));
}
@Test
void textToMorseTranslatesBothUpperAndLowerCaseLetters() {
assertEqualsIgnoreCase(".-", solution.textToMorse("a"));
assertEqualsIgnoreCase(".-", solution.textToMorse("A"));
assertEqualsIgnoreCase("-..-", solution.textToMorse("x"));
assertEqualsIgnoreCase("-..-", solution.textToMorse("X"));
}
@Test
void textToMorseUsesSpaceBetweenCharacters() {
assertEqualsIgnoreCase(".... . .-.. .-.. ---", solution.textToMorse("hello"));
}
@Test
void textToMorseUsesThreeSpacesBetweenWords() {
assertEqualsIgnoreCase(".... . .-.. .-.. --- .-- --- .-. .-.. -..", solution.textToMorse("hello world"));
}
/**
* This helper method is used to compare two strings, ignoring the case of the
* characters. This way we don't need to repeat the same code for transforming
* the strings to lower case in every test.
*/
private void assertEqualsIgnoreCase(String expected, String actual) {
assertEquals(expected.toLowerCase(), actual.toLowerCase());
}
}