-
Notifications
You must be signed in to change notification settings - Fork 129
Expand file tree
/
Copy pathExerciseTest.java
More file actions
81 lines (69 loc) · 2.59 KB
/
ExerciseTest.java
File metadata and controls
81 lines (69 loc) · 2.59 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.booleanuk.core;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
class ExerciseTest {
Exercise exercise;
public ExerciseTest() {
this.exercise = new Exercise();
}
@Test
public void shouldReturnMappedValues() {
Assertions.assertEquals("Nathan", this.exercise.getValue("firstName"));
Assertions.assertEquals("King", this.exercise.getValue("lastName"));
Assertions.assertEquals("Software Developer", this.exercise.getValue("occupation"));
}
@Test
public void shouldHaveKey() {
HashMap<String, String> map = new HashMap<>(){{
put("name", "Joe");
put("vocation", "Artist");
}};
Assertions.assertTrue(this.exercise.hasKey(map, "vocation"));
Assertions.assertFalse(this.exercise.hasKey(map, "wubbalubbadubdub"));
}
@Test
public void shouldDefault() {
HashMap<String, Integer> map = new HashMap<>(){{
put("age", 32);
put("heightFeet", 6);
}};
Assertions.assertEquals(32, this.exercise.getValueOrDefault(map, "age"));
Assertions.assertEquals(6, this.exercise.getValueOrDefault(map, "heightFeet"));
Assertions.assertEquals(-1, this.exercise.getValueOrDefault(map, "score"));
}
@Test
public void shouldBuildSecret() {
ArrayList<Integer> list1 = new ArrayList<>(){{
add(42);
add(6712);
add(7);
}};
ArrayList<String> result1 = this.exercise.buildSecretPhrase(list1);
Assertions.assertEquals(3, result1.size());
Assertions.assertEquals("universe", result1.get(0));
Assertions.assertEquals("bass", result1.get(1));
Assertions.assertEquals("muse", result1.get(2));
ArrayList<Integer> list2 = new ArrayList<>(){{
add(23);
add(19);
add(96);
add(23);
add(165);
}};
ArrayList<String> result2 = this.exercise.buildSecretPhrase(list2);
Assertions.assertEquals(4, result2.size());
Assertions.assertEquals("chicken", result2.get(0));
Assertions.assertEquals("nice", result2.get(1));
Assertions.assertEquals("chicken", result2.get(2));
Assertions.assertEquals("soup", result2.get(3));
ArrayList<Integer> list3 = new ArrayList<>(){{
add(918);
add(71);
add(88);
}};
ArrayList<String> result3 = this.exercise.buildSecretPhrase(list3);
Assertions.assertEquals(0, result3.size());
}
}