summaryrefslogtreecommitdiff
path: root/debugging/Testing.java
blob: a50fe62d46b7e9441c366f91041f125597136b46 (plain)
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
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.*;

public class Testing {

    @Test
    @DisplayName("EXAMPLE TEST CASE - createIndex Example")
    public void firstCaseTest() {
        List<String> documents = new ArrayList<>(List.of("The Bee Movie is great!",
                                                         "I love the Bee Movie",
                                                         "Y'all seen Dune 2?"));
        Map<String, Set<String>> index = InvertedIndex.createIndex(documents);
        
        // Make sure that tokens are correctly converted to lower case
        assertTrue(index.containsKey("bee"));
        assertFalse(index.containsKey("Bee"));
        
        // Make sure that punctuation is ignored
        assertTrue(index.containsKey("great!"));
        assertFalse(index.containsKey("great"));

        // Check one of the sets
        assertEquals(Set.of("The Bee Movie is great!",
                             "I love the Bee Movie"),
                     index.get("movie"));
    }

    @Test
    @DisplayName("EXAMPLE TEST CASE - Book 2 String constructor + getters")
    public void secondCaseTest() {
        Book b = new Book("Title", "Author");
        
        // Test all getters after constructing with 2 Strings
        assertEquals("Title", b.getTitle());
        assertEquals(List.of("Author"), b.getArtists());
        assertEquals(0, b.getNumRatings());
        assertEquals(0.0, b.getAverageRating());
    }
}