• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with PriceTest fixture

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Consider a grocery market where items have prices per unit but also volume prices. For example, doughnuts may be $1.00 each or 4 for $3 dollars.

So far, I have created the following test cases along with the "objects under test":

PriceTest:



Price:



My first two tests work inside PriceTest, but my testCombinedPrice() method throws the following error:



How do I fix this failing test?

-Mike
[ September 13, 2008: Message edited by: Michael K. Wilson ]
 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why do you expect 4? 5*3/4=3.75
 
Michael K. Wilson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because for the 5 doughnuts count, the combined price should be $4...

Four doughnuts are given for $3.00 plus the extra doughnut which is given for $1.00. The combined price is then $3.00 + $1.00 = $4.00 not $3.75.

Obviously, its something inside the Price#calc() method which has to be altered but I need all the tests to work (including testMultiUnitPrice() and testCombinedPrice() methods).

Is there a way to change Price#calc() method to work for both tests?

Happy coding,

Mike
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to work in this
return pricePerPackage * count / itemsPerPackage;
 
Michael K. Wilson
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Misha,

I understand this part... I am just wondering how to correctly fix it...
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like you want to
a) find out how many full packages the purchases qualifies for
b) multiply the number of full package by the package prince
c) add on the product of the unit price and the remainder

div & mod will be your friend....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic