def test_two_similar_lots(self): # There are two lots that have the same values, but were bought # separately. lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lots = lots_lib.Lots([lot1, lot2]) self.assertSameLot(lot2, wash.best_replacement_lot(lot1, lots))
def test_replacement_is_first_bought(self): lots = lots_lib.Lots([ self.first_gain, self.first_gain_earlier_sale, self.first_gain_later_sale ]) self.assertSameLot(self.first_gain_earlier_sale, wash.best_replacement_lot(self.loss, lots))
def test_two_similar_lots(self): # There are two lots that have the same values, but were bought # separately. lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lots = lots_lib.Lots([lot1, lot2]) self.assertSameLot(lot2, wash.best_replacement_lot(lot1, lots))
def test_two_lots_from_same_buy_lot(self): # There are two lots that have the same values, and were bought # together. lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot1.buy_lot = '1' lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2.buy_lot = '1' lots = lots_lib.Lots([lot1, lot2]) self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
def test_two_lots_from_same_buy_lot(self): # There are two lots that have the same values, and were bought # together. lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot1.buy_lot = '1' lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2.buy_lot = '1' lots = lots_lib.Lots([lot1, lot2]) self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
def test_replacement_for_large_loss(self): lots = lots_lib.Lots([self.unsold, self.first_gain, self.large_loss]) final_lots = copy.deepcopy(lots) wash_lot = wash.best_replacement_lot(self.large_loss, lots) self.assertSameLot(self.first_gain, wash_lot) self.assertEqual(10, wash_lot.num_shares) self.assertEqual(3, lots.size()) lots.sort(key=cmp_to_key(lots_lib.Lot.cmp_by_original_buy_date)) final_lots.sort(key=cmp_to_key(lots_lib.Lot.cmp_by_original_buy_date)) self.assertSameLots(lots, final_lots)
def test_replacement_for_large_loss(self): lots = lots_lib.Lots([self.unsold, self.first_gain, self.large_loss]) final_lots = copy.deepcopy(lots) wash_lot = wash.best_replacement_lot(self.large_loss, lots) self.assertSameLot(self.first_gain, wash_lot) self.assertEqual(10, wash_lot.num_shares) self.assertEqual(3, lots.size()) lots.sort(cmp=lots_lib.Lot.cmp_by_original_buy_date) final_lots.sort(cmp=lots_lib.Lot.cmp_by_original_buy_date) self.assertSameLots(lots, final_lots)
def test_replacement_30_days_after(self): lots = lots_lib.Lots([self.days_after_30]) self.assertSameLot(self.days_after_30, wash.best_replacement_lot(self.loss, lots))
def test_replacement_30_days_before(self): lots = lots_lib.Lots([self.days_early_30]) self.assertSameLot(self.days_early_30, wash.best_replacement_lot(self.loss, lots))
def test_no_replacement_31_days_after(self): lots = lots_lib.Lots([self.days_after_31]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_no_replacement_too_late(self): lots = lots_lib.Lots([self.second_gain, self.loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_replacement_for_loss_multiple_options(self): lots = lots_lib.Lots([self.loss, self.small_first_gain, self.large_first_gain]) wash_lot = wash.best_replacement_lot(self.loss, lots) self.assertSameLot(self.small_first_gain, wash_lot)
def test_replacement_for_loss_multiple_options(self): lots = lots_lib.Lots( [self.loss, self.small_first_gain, self.large_first_gain]) wash_lot = wash.best_replacement_lot(self.loss, lots) self.assertSameLot(self.small_first_gain, wash_lot)
def test_replacement_checks_sell_date(self): # If there are multiple possible replacements that were bought on the # same day, the one with the earlier sell date is chosen. lots = lots_lib.Lots([self.unsold, self.first_gain, self.loss]) self.assertSameLot(self.first_gain, wash.best_replacement_lot(self.loss, lots))
def test_loss_not_in_lots(self): lots = lots_lib.Lots([self.unsold, self.first_gain]) self.assertSameLot(self.first_gain, wash.best_replacement_lot(self.loss, lots))
def test_lot_sold_before_loss_is_not_replacement(self): lots = lots_lib.Lots([self.loss, self.gain_just_before_loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_already_used_replacement_is_not_used_again(self): lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2.is_replacement = True lots = lots_lib.Lots([lot1, lot2]) self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
def test_replacement_is_first_bought(self): lots = lots_lib.Lots([self.first_gain, self.first_gain_earlier_sale, self.first_gain_later_sale]) self.assertSameLot(self.first_gain_earlier_sale, wash.best_replacement_lot(self.loss, lots))
def test_replacement_checks_sell_date(self): # If there are multiple possible replacements that were bought on the # same day, the one with the earlier sell date is chosen. lots = lots_lib.Lots([self.unsold, self.first_gain, self.loss]) self.assertSameLot(self.first_gain, wash.best_replacement_lot(self.loss, lots))
def test_loss_not_in_lots(self): lots = lots_lib.Lots([self.unsold, self.first_gain]) self.assertSameLot(self.first_gain, wash.best_replacement_lot(self.loss, lots))
def test_replacement_is_unsold(self): lots = lots_lib.Lots([self.unsold, self.loss]) self.assertSameLot(self.unsold, wash.best_replacement_lot(self.loss, lots))
def test_replacement_is_unsold(self): lots = lots_lib.Lots([self.unsold, self.loss]) self.assertSameLot(self.unsold, wash.best_replacement_lot(self.loss, lots))
def test_replacement_30_days_after(self): lots = lots_lib.Lots([self.days_after_30]) self.assertSameLot(self.days_after_30, wash.best_replacement_lot(self.loss, lots))
def test_lot_sold_before_loss_is_not_replacement(self): lots = lots_lib.Lots([self.loss, self.gain_just_before_loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_replacement_for_small_loss(self): lots = lots_lib.Lots([self.unsold, self.first_gain, self.small_loss]) wash_lot = wash.best_replacement_lot(self.small_loss, lots) self.assertSameLot(self.first_gain, wash_lot)
def test_replacement_30_days_before(self): lots = lots_lib.Lots([self.days_early_30]) self.assertSameLot(self.days_early_30, wash.best_replacement_lot(self.loss, lots))
def test_only_loss_lot_exists(self): lots = lots_lib.Lots([self.loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_replacement_for_small_loss(self): lots = lots_lib.Lots([self.unsold, self.first_gain, self.small_loss]) wash_lot = wash.best_replacement_lot(self.small_loss, lots) self.assertSameLot(self.first_gain, wash_lot)
def test_no_replacement_too_early(self): lots = lots_lib.Lots([self.very_early_gain, self.loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_no_replacement_too_late(self): lots = lots_lib.Lots([self.second_gain, self.loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_already_used_replacement_is_not_used_again(self): lot1 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2 = create_lot(10, 2012, 1, 1, 120, 2012, 1, 10, 110) lot2.is_replacement = True lots = lots_lib.Lots([lot1, lot2]) self.assertLotIsNone(wash.best_replacement_lot(lot1, lots))
def test_no_replacement_too_early(self): lots = lots_lib.Lots([self.very_early_gain, self.loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_only_loss_lot_exists(self): lots = lots_lib.Lots([self.loss]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))
def test_no_replacement_31_days_after(self): lots = lots_lib.Lots([self.days_after_31]) self.assertLotIsNone(wash.best_replacement_lot(self.loss, lots))