def testEvaluatesToTrueIfArgumentIsEqualToAValueWithinSomeError(self): matcher = close_to(1.0, 0.5) self.assert_matches("equal", matcher, 1.0) self.assert_matches("less but within delta", matcher, 0.5) self.assert_matches("greater but within delta", matcher, 1.5) self.assert_does_not_match("too small", matcher, 0.4) self.assert_does_not_match("too large", matcher, 1.6)
def test_cash_amount_changed_balance(self) -> None: """Cash amount changed must balance.""" drawer: CashDrawer = CashDrawer() total: float = drawer.get_total() drawer.open(187.91) for denom in CashDenomination: drawer.add_count(denom, 1) try: drawer.close() assert_that(drawer.get_total(), close_to(total + 187.91, 0.001)) except Exception: pytest.fail("Unexpected Exception when closing drawer")
def test_cash_amount_changed_make_change(self) -> None: """Cash amount changed must balance with change given.""" drawer: CashDrawer = CashDrawer() total: float = drawer.get_total() drawer.open(187.91) cash_in: float = 200.0 drawer.add_count(CashDenomination.HUNDRED_DOLLAR_BILL, 2) cash_in -= 0.01 * 4 drawer.remove_count(CashDenomination.PENNY, 4) cash_in -= 0.05 * 1 drawer.remove_count(CashDenomination.NICKEL, 1) cash_in -= 1.0 * 1 drawer.remove_count(CashDenomination.DOLLAR_COIN, 1) cash_in -= 1.0 * 1 drawer.remove_count(CashDenomination.ONE_DOLLAR_BILL, 1) cash_in -= 10.0 * 1 drawer.remove_count(CashDenomination.TEN_DOLLAR_BILL, 1) assert_that(cash_in, close_to(187.91, 0.001)) try: drawer.close() assert_that(drawer.get_total(), close_to(total + 187.91, 0.001)) except Exception: pytest.fail("Unexpected Exception when closing drawer")
def test_twenty_dollar_bill(self) -> None: """Test Twenty Dollar Bill.""" assert_that(str(CashDenomination.TWENTY_DOLLAR_BILL), is_("$20 Bill")) assert_that(CashDenomination.TWENTY_DOLLAR_BILL.amount, close_to(20.0, 0.00001))
def test_one_dollar_bill(self) -> None: """Test One Dollar Bill.""" assert_that(str(CashDenomination.ONE_DOLLAR_BILL), is_("$1 Bill")) assert_that(CashDenomination.ONE_DOLLAR_BILL.amount, close_to(1.0, 0.00001))
def test_ten_dollar_bill(self) -> None: """Test Ten Dollar Bill.""" assert_that(str(CashDenomination.TEN_DOLLAR_BILL), is_("$10 Bill")) assert_that(CashDenomination.TEN_DOLLAR_BILL.amount, close_to(10.0, 0.00001))
def test_half_dollar(self) -> None: """Test Half Dollar.""" assert_that(str(CashDenomination.HALF_DOLLAR), is_("Half Dollar")) assert_that(CashDenomination.HALF_DOLLAR.amount, close_to(0.50, 0.00001))
def test_dollar_coin(self) -> None: """Test Dollar Coin.""" assert_that(str(CashDenomination.DOLLAR_COIN), is_("Dollar Coin")) assert_that(CashDenomination.DOLLAR_COIN.amount, close_to(1.0, 0.00001))
def testFailsIfMatchingAgainstNonNumber(self): self.assert_does_not_match("not a number", close_to(1.0, 0.5), "a")
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): self.assert_no_mismatch_description(close_to(1.0, 0.5), 1.0)
def test_penny(self) -> None: """Test Penny.""" assert_that(str(CashDenomination.PENNY), is_("Penny")) assert_that(CashDenomination.PENNY.amount, close_to(0.01, 0.00001))
def testMatcherCreationAcceptsOtherNumericTypes(self): close_to(int(5), int(1))
def testDescribeMismatchShowsActualArgumentIfNotNumeric(self): self.assert_describe_mismatch("was 'bad'", close_to(1.0, 0.5), "bad")
def testMatcherSupportsDecimal(self): matcher = close_to(Decimal("1.0"), Decimal("0.5")) self.assert_matches("equal", matcher, Decimal("1.4"))
def testDescribeMismatchShowsActualDeltaIfArgumentIsNumeric(self): self.assert_describe_mismatch("<1.7> differed by <0.7>", close_to(1.0, 0.5), 1.7)
def testMismatchDescriptionShowsActualArgumentIfNotNumeric(self): self.assert_mismatch_description("was 'bad'", close_to(1.0, 0.5), "bad")
def testMismatchDescriptionShowsActualDeltaIfArgumentIsNumeric(self): self.assert_mismatch_description("<1.7> differed by <0.7>", close_to(1.0, 0.5), 1.7)
def test_fifty_dollar_bill(self) -> None: """Test Fifty Dollar Bill.""" assert_that(str(CashDenomination.FIFTY_DOLLAR_BILL), is_("$50 Bill")) assert_that(CashDenomination.FIFTY_DOLLAR_BILL.amount, close_to(50.0, 0.00001))
def test_dime(self) -> None: """Test Dime.""" assert_that(str(CashDenomination.DIME), is_("Dime")) assert_that(CashDenomination.DIME.amount, close_to(0.10, 0.00001))
def test_hundred_dollar_bill(self) -> None: """Test Hundred Dollar Bill.""" assert_that(str(CashDenomination.HUNDRED_DOLLAR_BILL), is_("$100 Bill")) assert_that(CashDenomination.HUNDRED_DOLLAR_BILL.amount, close_to(100.0, 0.00001))
def test_quarter(self) -> None: """Test Quarter.""" assert_that(str(CashDenomination.QUARTER), is_("Quarter")) assert_that(CashDenomination.QUARTER.amount, close_to(0.25, 0.00001))
def test_nickel(self) -> None: """Test Nickel.""" assert_that(str(CashDenomination.NICKEL), is_("Nickel")) assert_that(CashDenomination.NICKEL.amount, close_to(0.05, 0.00001))
def testHasAReadableDescription(self): self.assert_description("a numeric value within <0.5> of <1.0>", close_to(1.0, 0.5))