Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1.  
  2. /* Tunji Afolabi-Brown osa2qx
  3. * Homework 3*/
  4. import static org.junit.Assert.*;
  5.  
  6. import java.util.ArrayList;
  7.  
  8. import org.junit.Before;
  9. import org.junit.Test;
  10. public class testLibrary {
  11. Book Alice=new Book("Alice in Wonderland", "Lewis Caroll",1001,25.00);
  12. Book Alice1=new Book("Alice in Wonderland", "Lewis Caroll",1005,12.99);
  13. Book Dragon=new Book("Red Dragon", "Thomas Harris",1002,15.49);
  14. Book Catch=new Book("Catch-22", "Joseph Heller",1003,20.00);
  15. Book Gatsby=new Book("The Great Gastby","F. Scott Fitzgerald",1000,12.99);
  16. Person renat=new Person("Renat Abasov", "4572 Lambeth",0100);
  17. Person walta=new Person("Walta Muruts", "313 Lucky Lane",0200);
  18. ArrayList<Person> people = new ArrayList<Person>();
  19. ArrayList<Book> books= new ArrayList<Book>();
  20. Library pizza=new Library("Pizza");
  21. @Before
  22. public void setUp() {
  23. books.add(Alice); books.add(Alice1); books.add(Dragon); books.add(Gatsby); books.add(Catch);
  24. people.add(walta); people.add(renat);
  25. pizza.setLibraryBooks(books);
  26. }
  27.  
  28. @Test
  29. public void checkNumTest() {
  30. assertEquals("Should return the correct value of 2 copies of Alice in Wonderland in the library",2,pizza.checkNumCopies("Alice in Wonderland", "Lewis Caroll"));
  31. }
  32.  
  33. @Test
  34. public void checkNumTest2() {
  35. pizza.setPatrons(people);
  36. pizza.checkOut(renat, Alice, "11 10 2017");
  37. 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"));
  38. }
  39.  
  40. @Test
  41. public void checkOutTest() {
  42. assertFalse("Should return false since Renat is not a patron of the library", pizza.checkOut(renat, Dragon, "11 11 2017"));
  43. }
  44.  
  45. @Test
  46. public void checkOutTest2() {
  47. pizza.setPatrons(people);
  48. pizza.checkOut(renat, Dragon, "11 10 2017");
  49. assertFalse("Should return false as renat already checked this book out", pizza.checkOut(renat, Dragon, "11 11 2017"));
  50. }
  51.  
  52. @Test
  53. public void booksDueOnDateTest() {
  54. pizza.setPatrons(people);
  55. pizza.checkOut(walta, Alice, "22 10 2017");
  56. assertEquals("Should be one as walta checked out a book due on this date",1,pizza.booksDueOnDate("22 10 2017").size());
  57. }
  58.  
  59. @Test
  60. public void booksDueOnDateTest2() {
  61. pizza.setPatrons(people);
  62. pizza.checkOut(walta, Catch, "22 12 2017");
  63. assertEquals("Should be zero as there are no books due on this date",0,pizza.booksDueOnDate("22 11 2017").size());
  64. }
  65.  
  66. @Test
  67. public void lateFeeTest() {
  68. pizza.setPatrons(people);
  69. pizza.checkOut(renat, Catch, "11 10 2017");
  70. pizza.setCurrentDate("20 10 2017");
  71. assertEquals("Should equal 1.80 as the book that renat checked out is nine days late",1.80,pizza.lateFee(renat),.1);
  72. }
  73.  
  74. @Test
  75. public void lateFeeTest2() {
  76. pizza.setPatrons(people);
  77. pizza.checkOut(renat, Catch, "11 10 2017");
  78. pizza.checkOut(renat, Alice, "11 10 2017");
  79. pizza.checkOut(renat, Dragon, "14 10 2017");
  80. pizza.setCurrentDate("20 10 2017");
  81. 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);
  82. }
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement