他の質問のコード サンプルに従って、Python 3.3 で標準の等価演算子を実装しようとしています。アサーション エラーが発生しましたが、何が壊れているのかわかりません。ここで何を見逃したのですか?
class RollResult:
def __init__(self, points, unscored_dice):
self.points = points
self.unscored_dice = unscored_dice
def __eq__(self, other):
return (self.points == other.points and self.unscored_dice == other.unscored_dice)
そして、これがテストです。他の多くのテストに合格しているので、基本的なセットアップは正しいです。これはクラスの私の最初のテストであり、これまで等価オーバーロードの単体テストを試みたことがないため、テストの誤りである可能性もあります。
class TestRollResultClass(unittest.TestCase):
def test_rollresult_equality_overload_does_not_test_for_same_object(self):
copy1 = RollResult(350,2)
copy2 = RollResult(350,2)
self.assertNotEqual(copy1,copy2)
結果:
AssertionError: <greed.RollResult object at 0x7fbc21c1b650> == <greed.RollResult object at 0x7fbc21c1b650>