Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Tunji Afolabi-Brown osa2qx
- * Homework 3*/
- import static org.junit.Assert.*;
- import java.util.ArrayList;
- import org.junit.Before;
- import org.junit.Test;
- public class testLibrary {
- Book Alice=new Book("Alice in Wonderland", "Lewis Caroll",1001,25.00);
- Book Alice1=new Book("Alice in Wonderland", "Lewis Caroll",1005,12.99);
- Book Dragon=new Book("Red Dragon", "Thomas Harris",1002,15.49);
- Book Catch=new Book("Catch-22", "Joseph Heller",1003,20.00);
- Book Gatsby=new Book("The Great Gastby","F. Scott Fitzgerald",1000,12.99);
- Person renat=new Person("Renat Abasov", "4572 Lambeth",0100);
- Person walta=new Person("Walta Muruts", "313 Lucky Lane",0200);
- ArrayList<Person> people = new ArrayList<Person>();
- ArrayList<Book> books= new ArrayList<Book>();
- Library pizza=new Library("Pizza");
- @Before
- public void setUp() {
- books.add(Alice); books.add(Alice1); books.add(Dragon); books.add(Gatsby); books.add(Catch);
- people.add(walta); people.add(renat);
- pizza.setLibraryBooks(books);
- }
- @Test
- public void checkNumTest() {
- assertEquals("Should return the correct value of 2 copies of Alice in Wonderland in the library",2,pizza.checkNumCopies("Alice in Wonderland", "Lewis Caroll"));
- }
- @Test
- public void checkNumTest2() {
- pizza.setPatrons(people);
- pizza.checkOut(renat, Alice, "11 10 2017");
- assertEquals("Should still return the correct value of 2 copies of Alice in Wonderland in the library",2,pizza.checkNumCopies("Alice in Wonderland", "Lewis Caroll"));
- }
- @Test
- public void checkOutTest() {
- assertFalse("Should return false since Renat is not a patron of the library", pizza.checkOut(renat, Dragon, "11 11 2017"));
- }
- @Test
- public void checkOutTest2() {
- pizza.setPatrons(people);
- pizza.checkOut(renat, Dragon, "11 10 2017");
- assertFalse("Should return false as renat already checked this book out", pizza.checkOut(renat, Dragon, "11 11 2017"));
- }
- @Test
- public void booksDueOnDateTest() {
- pizza.setPatrons(people);
- pizza.checkOut(walta, Alice, "22 10 2017");
- assertEquals("Should be one as walta checked out a book due on this date",1,pizza.booksDueOnDate("22 10 2017").size());
- }
- @Test
- public void booksDueOnDateTest2() {
- pizza.setPatrons(people);
- pizza.checkOut(walta, Catch, "22 12 2017");
- assertEquals("Should be zero as there are no books due on this date",0,pizza.booksDueOnDate("22 11 2017").size());
- }
- @Test
- public void lateFeeTest() {
- pizza.setPatrons(people);
- pizza.checkOut(renat, Catch, "11 10 2017");
- pizza.setCurrentDate("20 10 2017");
- assertEquals("Should equal 1.80 as the book that renat checked out is nine days late",1.80,pizza.lateFee(renat),.1);
- }
- @Test
- public void lateFeeTest2() {
- pizza.setPatrons(people);
- pizza.checkOut(renat, Catch, "11 10 2017");
- pizza.checkOut(renat, Alice, "11 10 2017");
- pizza.checkOut(renat, Dragon, "14 10 2017");
- pizza.setCurrentDate("20 10 2017");
- assertEquals("Should equal as all three are late. Late fee of Alice is 2.25, 1.80 for Catch, and .93 for Dragon, so 4.98 total", 4.98,pizza.lateFee(renat),.1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement