class TestOutcome(TestCase): def setUp(self): self.sampleOutcomeOne = Outcome("1", 1) self.sampleOutcomeTwo = Outcome("Red", 17) self.sampleOutcomeThree = Outcome("Red", 17) def test_sameNameReturnsTrue(self): self.assertEqual(True, self.sampleOutcomeTwo.__eq__(self.sampleOutcomeThree)) self.assertEqual(True, self.sampleOutcomeThree.__eq__(self.sampleOutcomeTwo)) def test_sameNameReturnsSameHash(self): self.assertEqual( True, self.sampleOutcomeTwo.__hash__() == self.sampleOutcomeThree.__hash__()) self.assertEqual( True, self.sampleOutcomeThree.__hash__() == self.sampleOutcomeTwo.__hash__()) def test_winAmount(self): self.assertEqual(170, self.sampleOutcomeTwo.winAmount(10)) self.assertEqual(34, self.sampleOutcomeThree.winAmount(2))
class TestOutcome(unittest.TestCase): def setUp(self): self.outcome1 = Outcome(name="red", odds=17) self.outcome2 = Outcome("red", 17) self.outcome3 = Outcome("first-12", 2) self.outcome4 = Outcome("split-bet", 19) def test_setup(self): self.assertEqual(self.outcome1, self.outcome2) self.assertNotEqual(self.outcome1, self.outcome3) self.assertEqual(self.outcome1.getName(), self.outcome2.getName()) def test___eq__(self): self.assertTrue(self.outcome1.__eq__(self.outcome2)) self.assertFalse(self.outcome1.__eq__(self.outcome3)) def test___ne__(self): self.assertTrue(self.outcome1.__ne__(self.outcome3)) self.assertFalse(self.outcome1.__ne__(self.outcome1)) def test___str__(self): self.assertEqual(str(self.outcome1), "red (17:1)") self.assertEqual(self.outcome1.__str__(), "red (17:1)") def test___repr__(self): self.assertEqual(self.outcome1.__repr__(), "red (17:1)") def test_winAmount(self): self.assertEqual(self.outcome1.winAmount(10), 170) def test_hash(self): self.assertEqual(hash(self.outcome1), hash(self.outcome2)) self.assertNotEqual(hash(self.outcome1), hash(self.outcome3))