コード例 #1
0
    def test_dispense_mixed(self):
        mock = FlagServiceMock()
        bs = BeerService('*****@*****.**', DataService(mock))
        cs = CoffeeService('*****@*****.**', DataService(mock))

        self.assertEqual(1, bs.status())
        self.assertEqual(2, cs.status())
        bs.dispensed()
        self.assertEqual(0, bs.status())
        self.assertEqual(0, cs.status())

        mock.data['*****@*****.**']['coffee|remaining'] = 4
        self.assertEqual(2, bs.status())
        self.assertEqual(4, cs.status())
        cs.dispensed()
        self.assertEqual(3, mock.data['*****@*****.**']['coffee|remaining'])
        self.assertEqual(1, bs.status())
        self.assertEqual(3, cs.status())
        bs.dispensed()
        self.assertEqual(1, mock.data['*****@*****.**']['coffee|remaining'])
        self.assertEqual(0, bs.status())
        self.assertEqual(1, cs.status())
        cs.dispensed()
        self.assertEqual(0, mock.data['*****@*****.**']['coffee|remaining'])
        self.assertEqual(0, bs.status())
        self.assertEqual(0, cs.status())
コード例 #2
0
    def test_total_beers_when_dispensed(self):
        mock = FlagServiceMock()
        bs = BeerService('*****@*****.**', DataService(mock))

        self.assertEqual(1, bs.status())
        self.assertEqual(0, bs.total_beers())
        bs.dispensed()
        self.assertEqual(1, bs.total_beers())
        bs.dispensed()
        self.assertEqual(1, bs.total_beers())

        mock.data['*****@*****.**']['coffee|remaining'] = 4
        self.assertEqual(1, bs.total_beers())
        bs.dispensed()
        self.assertEqual(2, bs.total_beers())
        bs.dispensed()
        self.assertEqual(3, bs.total_beers())
        bs.dispensed()
        self.assertEqual(3, bs.total_beers())