def testFactoryCreateManyInstances(self): factory = OwnerInfoFactory() info = factory.create("Unique", 0.5) info2 = factory.create("Unique", 1) info3 = factory.create("Not Unique", 1) self.assertIsNot(info, info2) self.assertIsNot(info, info3) self.assertIsNot(info2, info3)
def testGetCostsPerPerson(self): groupFactory = OwnerGroupFactory() infoFactory = OwnerInfoFactory() info1 = infoFactory.create("Me", 0.25) info2 = infoFactory.create("You", 0.75) group = groupFactory.create([info1, info2]) product = Product("Test", 12, group) self.assertEqual(product.costPerPerson(), {"Me": 3, "You": 9})
def clear(self): self.shoppingList.clear() self.expectedSum = 0 for widget in self.entry_widgets: self.layout.remove_widget(widget) self.entry_widgets = [] OwnerGroupFactory().clear() OwnerInfoFactory().clear()
def generateFromProducts(self, products, realSum = 0): shopping_list = ShoppingList() shopping_list.realSum = realSum groupFactory = OwnerGroupFactory() infoFactory = OwnerInfoFactory() infoList = [infoFactory.create(person, 1/len(self.persons)) for person in self.persons] defaultGroup = groupFactory.create(infoList) for (name, price) in products: product = Product(name, price, defaultGroup) shopping_list.addProduct(product) return shopping_list
def setQuantityForOwner(self, owner, quantity): groupFactory = OwnerGroupFactory() infoFactory = OwnerInfoFactory() newInfo = infoFactory.create(owner, quantity) self.ownerGroup = groupFactory.updateGroup(self.ownerGroup, newInfo)
def testFactorySingleton(self): instance = OwnerInfoFactory() instance2 = OwnerInfoFactory() self.assertIs(instance, instance2)
def testFactoryCreateOneInstance(self): factory = OwnerInfoFactory() info = factory.create("Unique", 1) info2 = factory.create("Unique", 1) self.assertIs(info, info2)
def testFactoryCreate(self): factory = OwnerInfoFactory() info = factory.create("Test", 1) self.assertEqual(info.getOwner(), "Test") self.assertEqual(info.getQuantity(), 1)