-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTesting.java
More file actions
64 lines (50 loc) · 2.23 KB
/
Testing.java
File metadata and controls
64 lines (50 loc) · 2.23 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
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
import java.util.*;
public class Testing {
@Test
@DisplayName("Book string, list constructor")
public void testBookStringList() {
Book book = new Book("Title", List.of("Author 1", "Author 2"), new Scanner("Content"));
assertEquals("Title", book.getTitle());
assertEquals(List.of("Author 1", "Author 2"), book.getArtists());
assertEquals("Title by [Author 1, Author 2]", book.toString());
assertEquals(List.of("Content"), book.getContent());
}
@Test
@DisplayName("getNumRatings")
public void testNumRatings() {
Book book = new Book("Title", List.of("Author"), new Scanner("Content"));
assertEquals(0, book.getNumRatings());
book.addRating(1);
assertEquals(1, book.getNumRatings());
book.addRating(1);
assertEquals(2, book.getNumRatings());
}
@Test
@DisplayName("getAvgRating")
public void testAvgRatings() {
Book book = new Book("Title", List.of("Author"), new Scanner("Content"));
assertEquals(0.0, book.getAverageRating(), 1e-9);
book.addRating(4);
assertEquals(4.0, book.getAverageRating(), 1e-9);
book.addRating(5);
assertEquals(4.5, book.getAverageRating(), 1e-9);
}
@Test
@DisplayName("createIndex tests")
public void testInvertedIndex() {
Book mistborn = new Book("Mistborn", List.of("Brandon Sanderson"),
new Scanner("Epic fantasy worldbuildling content"));
Book farenheit = new Book("Farenheit 451", List.of("Ray Bradbury"),
new Scanner("Realistic \"sci-fi\" content"));
Book hobbit = new Book("The Hobbit", List.of("J.R.R. Tolkein"),
new Scanner("Epic fantasy quest content"));
List<Media> books = List.of(mistborn, farenheit, hobbit);
Map<String, Set<Media>> index = SearchClient.createIndex(books);
assertFalse(index.containsKey("sci-fi"));
assertTrue(index.containsKey("\"sci-fi\""));
Set<Media> expected = Set.of(mistborn, hobbit);
assertEquals(expected, index.get("fantasy"));
}
}