public void TestPackaging() { double one = 1; double four = 4; double six = 6; double ten = 10; double forty = 40; UnitOfMeasure one16ozCan = sys.CreateScalarUOM(UnitType.VOLUME, "16 oz can", "16ozCan", "16 oz can"); one16ozCan.SetConversion(16, sys.GetUOM(Unit.US_FLUID_OUNCE)); Quantity q400 = new Quantity(400, one16ozCan); Quantity q50 = q400.Convert(sys.GetUOM(Unit.US_GALLON)); Assert.IsTrue(IsCloseTo(q50.Amount, 50, DELTA6)); // 1 12 oz can = 12 fl.oz. UnitOfMeasure one12ozCan = sys.CreateScalarUOM(UnitType.VOLUME, "12 oz can", "12ozCan", "12 oz can"); one12ozCan.SetConversion(12, sys.GetUOM(Unit.US_FLUID_OUNCE)); Quantity q48 = new Quantity(48, one12ozCan); Quantity q36 = q48.Convert(one16ozCan); Assert.IsTrue(IsCloseTo(q36.Amount, 36, DELTA6)); // 6 12 oz cans = 1 6-pack of 12 oz cans UnitOfMeasure sixPackCan = sys.CreateScalarUOM(UnitType.VOLUME, "6-pack", "6PCan", "6-pack of 12 oz cans"); sixPackCan.SetConversion(six, one12ozCan); UnitOfMeasure fourPackCase = sys.CreateScalarUOM(UnitType.VOLUME, "4 pack case", "4PCase", "case of 4 6-packs"); fourPackCase.SetConversion(four, sixPackCan); double bd = fourPackCase.GetConversionFactor(one12ozCan); Assert.IsTrue(IsCloseTo(bd, 24, DELTA6)); bd = one12ozCan.GetConversionFactor(fourPackCase); bd = fourPackCase.GetConversionFactor(sixPackCan); bd = sixPackCan.GetConversionFactor(fourPackCase); bd = sixPackCan.GetConversionFactor(one12ozCan); bd = one12ozCan.GetConversionFactor(sixPackCan); Quantity tenCases = new Quantity(ten, fourPackCase); Quantity q1 = tenCases.Convert(one12ozCan); Assert.IsTrue(IsCloseTo(q1.Amount, 240, DELTA6)); Quantity q2 = q1.Convert(fourPackCase); Assert.IsTrue(IsCloseTo(q2.Amount, 10, DELTA6)); Quantity fortyPacks = new Quantity(forty, sixPackCan); q2 = fortyPacks.Convert(one12ozCan); Assert.IsTrue(IsCloseTo(q2.Amount, 240, DELTA6)); Quantity oneCan = new Quantity(one, one12ozCan); q2 = oneCan.Convert(sixPackCan); Assert.IsTrue(IsCloseTo(q2.Amount, 0.1666666666666667, DELTA6)); // A beer bottling line is rated at 2000 12 ounce cans/hour (US) at the // filler. The case packer packs four 6-packs of cans into a case. // Assuming no losses, what should be the rating of the case packer in // cases per hour? And, what is the draw-down rate on the holding tank // in gallons/minute? UnitOfMeasure canph = sys.CreateQuotientUOM(one12ozCan, sys.GetHour()); UnitOfMeasure caseph = sys.CreateQuotientUOM(fourPackCase, sys.GetHour()); UnitOfMeasure gpm = sys.CreateQuotientUOM(sys.GetUOM(Unit.US_GALLON), sys.GetMinute()); Quantity filler = new Quantity(2000, canph); // draw-down Quantity draw = filler.Convert(gpm); Assert.IsTrue(IsCloseTo(draw.Amount, 3.125, DELTA6)); // case production Quantity packer = filler.Convert(caseph); Assert.IsTrue(IsCloseTo(packer.Amount, 83.333333, DELTA6)); }