Results 1 to 6 of 6
- 12-12-2012, 06:50 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 22
- Rep Power
- 0
JUnit test - comparison problems.
Hi, for this assignment our teacher provided us with a J Unit test that we had to match with our code. This is the class i wrote - OrderManager
This is the J unit test that our teacher provide - OrderManagerTestJava Code:import java.text.DecimalFormat; import java.util.ArrayList; /** * * */ public class OrderManager implements OrderManagerInterface { private double order; private int numberOfOrders; DecimalFormat format = new DecimalFormat("##.00"); Sorting sortingClass = new Sorting(); //create an array list of type employee ArrayList<Comparable> orderList = new ArrayList<Comparable>(); /** * Initialize the numWorkers, numManager, numHourlyWorker, numThrowers to 0. * @param */ public OrderManager() { } public double addOrder(String toLn, String toFn, String toStr, String toC, String toSt, int toZ, String fromLn, String fromFn, String fromStr, String fromC, String fromSt, int fromZ, boolean beforeN, String d, int ship, int bSize, String msg) { Order newOrder = new Order(toLn, toFn, toStr, toC, toSt, toZ, fromLn, fromFn, fromStr, fromC, fromSt, fromZ, beforeN, d, ship, bSize, msg); orderList.add(newOrder); return order; } @Override public String printMessageCards() { String message = ""; for (Comparable element:orderList) { message += ((Order) element).getMsg()+"\n"+"\n"; } return message; } @Override public String deliverySchedule() { // TODO Auto-generated method stub System.out.println(orderList.toString()); orderList = sortingClass.selectionSort(orderList); System.out.println(orderList.toString()); String message = "Delivery Schedule"+"\n"+"\n"; for (Comparable element:orderList) { String deliveryTime = ""; if(((Order) element).getBeforeN()==true) { deliveryTime = "(a before noon delivery, preceeded by *)"; } else if (((Order) element).getBeforeN()==false) { deliveryTime = "(an after noon delivery)"; } message += ((Order) element).getDelivery()+"\n"+((Order) element).getToSt()+", "+((Order) element).getToC()+" - "+((Order) element).getToLn()+", "+((Order) element).getToFn()+" "+deliveryTime+"\n"; } return message; } /** * getNumOrders which is responsible for the size of the list * @return numberOfOrders */ @Override public int getNumOrders() { // TODO Auto-generated method stub numberOfOrders = orderList.size(); return numberOfOrders; } /** * Method toString * @return the String representation */ public String toString() { return orderList.toString(); } }
Here are the tests that i am failing.Java Code:import static org.junit.Assert.*; import java.util.Scanner; import org.junit.After; import org.junit.Before; import org.junit.Test; public class OrderManagerTest { OrderManager orders1, order2; @Before public void setUp() throws Exception { orders1 = new OrderManager(); orders1.addOrder("Brown", "Angela", "55321 Sycamore St.", "Gaithersburg", "MD", 20879, "Smith", "Agnus", "344 Oak St.", "Pocatello", "ID", 83205, true, "May 9", 1, 2, "Happy Mother's Day"); orders1.addOrder("Miller", "Karen", "3399 Campus St.", "Rockville", "MD", 20850, "Jones", "Peggy", "5633 Meadow Way", "Bloomington", "IN", 47404, false, "May 8", 1, 1, "Love ya"); orders1.addOrder("Hanson", "Beverly", "3356 Cypress Ln.", "North Potomac", "MD", 20878, "Hanson", "Ken", "2985 Pointer Dr.", "Fountain Valley", "CA", 83205, false, "May 11", 2, 3, "You're the greatest"); orders1.addOrder("White", "Carolyn", "4488 Pinewood Ave.", "Olney", "MD", 20859, "Green", "George", "492 Apple Way", "St. Louis", "MO", 35587, false, "May 9", 1, 2, "All the Best!"); } @After public void tearDown() throws Exception { orders1 = null; } @Test public void testPrintMessageCards() { String result = orders1.printMessageCards(); Scanner scan = new Scanner(result); assertEquals("Dear Mom", scan.nextLine()); assertEquals("Love ya", scan.nextLine()); assertEquals("Love Peggy", scan.nextLine()); scan.nextLine(); // blank line scan.nextLine(); // blank line assertEquals("Dear Mom", scan.nextLine()); assertEquals("Happy Mother's Day", scan.nextLine()); assertEquals("Love Agnus", scan.nextLine()); scan.nextLine(); // blank line scan.nextLine(); // blank line assertEquals("Dear Mom", scan.nextLine()); assertEquals("All the Best!", scan.nextLine()); assertEquals("Love George", scan.nextLine()); } @Test public void testAddOrder() { assertEquals(4,orders1.getNumOrders()); orders1.addOrder("Myers", "Stephanie", "8355 Grove Ave.", "Darnestown", "MD", 20874, "Simco", "Rebecca", "34 Charleston St.", "Orlando", "FL", 11334, true, "May 8", 1, 1, "I miss you"); assertEquals(5,orders1.getNumOrders()); } @Test public void testDeliverySchedule() { String result = orders1.deliverySchedule(); Scanner scan = new Scanner(result); assertEquals("Delivery Schedule", scan.nextLine()); scan.nextLine(); // blank line scan.nextLine(); // blank line assertEquals("May 8", scan.nextLine()); assertEquals("3399", scan.next()); scan.nextLine(); // get rest of line scan.nextLine(); // blank line scan.nextLine(); // blank line assertEquals("May 9", scan.nextLine()); assertEquals("*55321", scan.next()); scan.nextLine(); // get rest of line assertEquals("4488", scan.next()); } @Test public void testSortClass() { String result = orders1.printMessageCards(); Scanner scan = new Scanner(result); assertEquals("Dear Mom", scan.nextLine()); assertEquals("Love ya", scan.nextLine()); assertEquals("Love Peggy", scan.nextLine()); // add a May 8 before noon order which should be // sorted to be first before Peggy orders1.addOrder("Myers", "Stephanie", "8355 Grove Ave.", "Darnestown", "MD", 20874, "Simco", "Rebecca", "34 Charleston St.", "Orlando", "FL", 11334, true, "May 8", 1, 1, "I miss you"); result = orders1.printMessageCards(); scan = new Scanner(result); assertEquals("Dear Mom", scan.nextLine()); assertEquals("I miss you", scan.nextLine()); assertEquals("Love Rebecca", scan.nextLine()); scan.nextLine(); // blank line scan.nextLine(); // blank line assertEquals("Dear Mom", scan.nextLine()); assertEquals("Love ya", scan.nextLine()); assertEquals("Love Peggy", scan.nextLine()); } }
J unit test fails testPrintMessageCards - which says ...:expected: <[Dear Mom]> but was:<Happy Mother's Day]>
J unit test fails testDeliverySchedule - which says.....:expected: <M[ay 8]> but was: M[D, North Potomac - Hanson, Beverly(an after noon delivery)]>
J unit test fails testSortClass - which says........ :expected: <[Dear Mom]> but was:<Happy Mother's Day]>
Can anyone provide the correct code that i need to fix in my OrderManager class?
- 12-12-2012, 06:59 AM #2
Re: JUnit test - comparison problems.
Cross posted
junit - J Unit Test - Codes conflict problems - Stack Overflow
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-12-2012, 07:01 AM #3
Re: JUnit test - comparison problems.
Why do they call it rush hour when nothing moves? - Robin Williams
- 12-12-2012, 07:02 AM #4
Member
- Join Date
- Dec 2012
- Posts
- 22
- Rep Power
- 0
Re: JUnit test - comparison problems.
im sorry, is that not allowed in this forum? if it isnt ill take it off the stackoverflow website.
- 12-12-2012, 07:03 AM #5
Member
- Join Date
- Dec 2012
- Posts
- 22
- Rep Power
- 0
Re: JUnit test - comparison problems.
What i mean by the correct code is, give me pointers as to where im going wrong so i can fix it. and how am i cheating here?
- 12-12-2012, 10:15 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
JUnit test nullPointerException
By danboy4 in forum New To JavaReplies: 1Last Post: 10-10-2012, 07:06 AM -
problem with JUnit test
By exltus in forum Advanced JavaReplies: 12Last Post: 12-19-2011, 07:49 PM -
JUnit Test??? What is it all about????? Please help!!
By nikosa in forum New To JavaReplies: 1Last Post: 08-03-2009, 05:31 PM -
JUnit Test Help!
By pharo in forum New To JavaReplies: 0Last Post: 04-10-2009, 05:15 PM -
Junit test
By alice in forum New To JavaReplies: 1Last Post: 06-14-2008, 01:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks