MCPcopy Create free account
hub / github.com/Berkeley-CS61B/skeleton-sp23 / MapExercisesTest

Class MapExercisesTest

hw0b/tests/MapExercisesTest.java:12–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10import static com.google.common.truth.Truth.assertThat;
11
12@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
13public class MapExercisesTest {
14
15 @Test
16 @Order(0)
17 @DisplayName("Test letterToNumber correctness")
18 public void testLetterToNum() {
19 Map<Character, Integer> map = MapExercises.letterToNum();
20
21 assertThat(map.size()).isEqualTo(26);
22 for (int i = 0; i < 26; i++) {
23 assertThat(map.get((char) ('a' + i))).isEqualTo(i + 1);
24 }
25 }
26
27 @Test
28 @Order(1)
29 @DisplayName("Test squares correctness")
30 public void testSquares() {
31 List<Integer> lst = List.of(1, 3, 6, 7);
32
33 Map<Integer, Integer> map = MapExercises.squares(lst);
34 assertThat(map).containsExactly(
35 1, 1,
36 3, 9,
37 6, 36,
38 7, 49
39 );
40 }
41
42 @Test
43 @Order(2)
44 @DisplayName("Test countWords correctness")
45 public void testCountWords() {
46 List<String> lst = List.of(
47 "hug", "hug", "hug", "hug",
48 "shreyas", "shreyas", "shreyas",
49 "ergun", "ergun",
50 "cs61b"
51 );
52
53 Map<String, Integer> map = MapExercises.countWords(lst);
54
55 assertThat(map).containsExactly(
56 "hug", 4,
57 "shreyas", 3,
58 "ergun", 2,
59 "cs61b", 1
60 );
61 }
62
63}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected