Class CalculatorTest
java.lang.Object
test.CalculatorTest
Provides test cases for the
Calculator
class.
Tests the shipping cost calculation for parcels based on the defined default shipping rules. Ensures that the correct shipping cost is calculated for parcels of different sizes and weights and that exceptions are thrown for oversized parcels and parcels with invalid dimensions or weight.
Contains the following test cases:
-
testSmallParcelRate()
- Tests that a small parcel with dimensions up to 30x30x15 cm and up to 1 kg is correctly calculated to cost 3.89 EUR. -
testMediumParcelRate()
- Tests that a medium parcel with dimensions up to 60x30x15 cm and up to 2 kg is correctly calculated to cost 4.39 EUR. -
testLargeParcelRate()
- Tests that a large parcel with dimensions up to 120x60x60 cm, girth up to 300 cm, and up to 5 kg is correctly calculated to cost 5.89 EUR. -
testXLParcelRate()
- Tests that an extra-large parcel with dimensions up to 120x60x60 cm, girth up to 300 cm, and up to 10 kg is correctly calculated to cost 7.99 EUR. -
testXXLParcelRate()
- Tests that an extra-extra-large parcel with dimensions up to 120x60x60 cm and a weight up to 31 kg is correctly calculated to cost 14.99 EUR. -
testRotatedParcelRate()
- Tests that a parcel that has to be rotated to fit the dimensions is priced correctly. -
testSmallHeavyParcelRate()
- Tests that a small parcel with a heavy weight is priced correctly. -
testExceedMaxWeight()
- Tests that a parcel exceeding the maximum weight of 31 kg throws anIllegalArgumentException
. -
testExceedMaxDimensions()
- Tests that a parcel exceeding the maximum dimensions of 120x60x60 cm throws anIllegalArgumentException
. -
testAllZeroDimensions()
- Tests that a parcel with all dimensions set to zero throws anIllegalArgumentException
. -
testOneZeroDimension()
- Tests that a parcel with only one zero dimension throws anIllegalArgumentException
. -
testNegativeDimensions()
- Tests that a parcel with negative dimensions throws anIllegalArgumentException
. -
testNegativeWeight()
- Tests that a parcel with negative weight throws anIllegalArgumentException
. -
testNullPacket()
- Tests that passing a null packet to the calculator throws anIllegalArgumentException
. -
testExceedMaxGirth()
- Tests that a parcel exceeding the girth limit is priced correctly. -
testOrientationsWidth()
- Tests that a parcel which would normally not fit due to it's width is priced correctly (due to trying all orientations). -
testOrientationsHeight()
- Tests that a parcel which would normally not fit due to it's height is priced correctly (due to trying all orientations). -
testFloatingPointPrecisionForWeight()
- Tests calculation precision for a weight very close to the 10 kg boundary. -
testNearLimitCombination()
- Tests a parcel with near-limit dimensions and weight to ensure correct rule selection. -
testMaxIntegerDimensions()
- Tests that a parcel with maximum integer dimensions and weight does not crash the program and throws an appropriateIllegalArgumentException
.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Tests that a parcel with no dimension throws an IllegalArgumentException.void
Tests that a parcel exceeding the maximum dimensions of 120x60x60 cm throws an IllegalArgumentException.void
Tests that a parcel exceeding the girth limit is priced correctly.void
Tests that a parcel exceeding the maximum weight of 31 kg throws an IllegalArgumentException.void
Tests calculation precision for a weight that is very close to 10 kg boundary.void
Tests that a large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 5 kg is correctly calculated to cost 5.89 EUR.void
Tests that a parcel with maximum integer dimensions and weight does not crash the program.void
Tests that a medium parcel with dimensions up to 60x30x15 cm and up to 2 kg is correctly calculated to cost 4.39 EUR.void
Tests a parcel with near-limit dimensions and weight to ensure correct rule selection.void
Tests that a parcel with negative dimensions throws an IllegalArgumentException.void
Tests that a parcel with negative weight throws an IllegalArgumentException.void
Tests that a Null parcel throws an IllegalArgumentException.void
Tests that a parcel with only one null dimension throws an IllegalArgumentException.void
Tests that a parcel that has to be rotated to fit the dimensions is priced correctly.void
Tests that small heavy parcel is priced correctly.void
Tests that a small parcel with dimensions up to 30x30x15 cm and up to 1 kg is correctly calculated to cost 3.89 EUR.void
Tests that an extra-large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 10 kg is correctly calculated to cost 7.99 EUR.void
Tests that an extra-extra-large parcel with dimensions up to 120x60x60 cm and a weight up to 31 kg is correctly calculated to cost 14.99 EUR.
-
Constructor Details
-
CalculatorTest
public CalculatorTest()
-
-
Method Details
-
testSmallParcelRate
Tests that a small parcel with dimensions up to 30x30x15 cm and up to 1 kg is correctly calculated to cost 3.89 EUR.- Throws:
ShippingRuleException
-
testMediumParcelRate
Tests that a medium parcel with dimensions up to 60x30x15 cm and up to 2 kg is correctly calculated to cost 4.39 EUR.- Throws:
ShippingRuleException
-
testLargeParcelRate
Tests that a large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 5 kg is correctly calculated to cost 5.89 EUR.- Throws:
ShippingRuleException
-
testXLParcelRate
Tests that an extra-large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 10 kg is correctly calculated to cost 7.99 EUR.- Throws:
ShippingRuleException
-
testXXLParcelRate
Tests that an extra-extra-large parcel with dimensions up to 120x60x60 cm and a weight up to 31 kg is correctly calculated to cost 14.99 EUR.- Throws:
ShippingRuleException
-
testRotatedParcelRate
Tests that a parcel that has to be rotated to fit the dimensions is priced correctly.- Throws:
ShippingRuleException
-
testSmallHeavyParcelRate
Tests that small heavy parcel is priced correctly.- Throws:
ShippingRuleException
-
testExceedMaxWeight
@Test public void testExceedMaxWeight()Tests that a parcel exceeding the maximum weight of 31 kg throws an IllegalArgumentException. -
testExceedMaxDimensions
@Test public void testExceedMaxDimensions()Tests that a parcel exceeding the maximum dimensions of 120x60x60 cm throws an IllegalArgumentException. -
testAllZeroDimensions
@Test public void testAllZeroDimensions()Tests that a parcel with no dimension throws an IllegalArgumentException. -
testOneZeroDimension
@Test public void testOneZeroDimension()Tests that a parcel with only one null dimension throws an IllegalArgumentException. -
testNegativeDimensions
@Test public void testNegativeDimensions()Tests that a parcel with negative dimensions throws an IllegalArgumentException. -
testNegativeWeight
@Test public void testNegativeWeight()Tests that a parcel with negative weight throws an IllegalArgumentException. -
testNullPacket
@Test public void testNullPacket()Tests that a Null parcel throws an IllegalArgumentException. -
testExceedMaxGirth
Tests that a parcel exceeding the girth limit is priced correctly.- Throws:
ShippingRuleException
-
testFloatingPointPrecisionForWeight
Tests calculation precision for a weight that is very close to 10 kg boundary.- Throws:
ShippingRuleException
-
testNearLimitCombination
Tests a parcel with near-limit dimensions and weight to ensure correct rule selection.- Throws:
ShippingRuleException
-
testMaxIntegerDimensions
@Test public void testMaxIntegerDimensions()Tests that a parcel with maximum integer dimensions and weight does not crash the program.
-