Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume a developer writes the following class that calculates an item\'s retail

ID: 3829844 • Letter: A

Question

Assume a developer writes the following class that calculates an item's retail price based on the wholesale cost and markup percentage. Describe how a unit test can be developed to test this class. You may use code in any language, pseudo code, or natural language.   

public class RetailPriceCalculator

{

                                …   

                public static double calculateRetail(double wholesale, double markUp)

                {

                                double retail = wholesale (1+ markup/100);

                                return retail;

                }

}

Explanation / Answer

package com.vogella.junit.first;

import static org.junit.Assert.*;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

public class MyTest {

   @Test
   public void negativityTest() {
       double wholeSale = 150.0;
       double markUp = -50;
       double retailPrice = RetailPriceCalculator.calculateRetail(wholeSale, markUp);
       assertTrue("markUp percentage is negative", wholeSale > retailPrice);      
   }

   @Test
   public void equalityTest() {
       double wholeSale = 150.0;
       double markUp = 0;
       double retailPrice = RetailPriceCalculator.calculateRetail(wholeSale, markUp);
       assertEquals("markUp percentage is zero", wholeSale, retailPrice);      
   }

   @Test
   public void normalTest() {
       double wholeSale = 150.0;
       double markUp = 40;
       double retailPrice = RetailPriceCalculator.calculateRetail(wholeSale, markUp);
       assertTrue("markUp percentage is non-negative", wholeSale <= retailPrice);      
   }

   @Test
   public void zeroTest() {
       double wholeSale = 0;
       double markUp = 40;
       double retailPrice = RetailPriceCalculator.calculateRetail(wholeSale, markUp);
       assertEquals("wholesale price is zero", 0, retailPrice);      
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote