def detach(self, *args, **kwargs): super(WindowWidget, self).__delitem__(*args, **kwargs) def retrieve(self, *args, **kwargs): return super(WindowWidget, self).__getitem__(*args, **kwargs) def show(self): self.__str__() if __name__ == "__main__": with Section("Container Abstract Data Type"): val_cont = ContainerADT() for n in range(4): val_cont[n * n] = randchars(n) val_cont.insert(n, randchars(n)) print(val_cont.size()) print(val_cont.new("fooo")) for el in val_cont: print("Iterator: {}, membership check ({}) => {}".format(val_cont[el], el, el in val_cont)) prnt("Value Container", val_cont.elements) print(val_cont.clear()) prnt("Empty Container", val_cont.elements) assert len(val_cont) == 0 ref_cont = ReferenceContainer()
values = self.items.values() is_both_key = key in keys and key in values is_both_val = val in keys and val in values if is_both_key or is_both_val: raise ValueError( 'Item already exists in both key and value' ' -- it can only exist in one!') super(BidirectionalMap, self).__setitem__(key, val) if DEBUG: with Section('Map Abstract Data Type'): map_adt = MapADT(title='map_head') for n in range(6): key = 'map_item-{}'.format(''.join(randchars(8))) map_adt[key] = ''.join(randchars(4)) print(map_adt) with Section('Multi-Map Abstract Data Type'): faker = Factory.create() multimap = MultiMap(title='multi-map_head') print_h2('Multimap', desc='General abstract usage.') for n in range(4): key = 'map_item-{}'.format(n) multimap[key] = ''.join(randchars(4)) print(multimap)
def create(self, *args, **kwargs): self.__init__(self, *args, **kwargs) def tail(self): return self.items[1:] def head(self): return self.items[0] def empty(self): return len(self.items) == 0 def prepend(self, item): self.items.insert(0, item) def append(self, item): self.items.append(item) if __name__ == '__main__': with Section('List Abstract Data Type'): list_adt = ListADT() for n in range(4): list_adt.prepend(randchars(n)) list_adt.append(randchars(n)) print(list_adt) print('List ADT head', list_adt.head()) print('List ADT tail', list_adt.tail()) print('List ADT empty?', list_adt.empty())
def detach(self, *args, **kwargs): super(WindowWidget, self).__delitem__(*args, **kwargs) def retrieve(self, *args, **kwargs): return super(WindowWidget, self).__getitem__(*args, **kwargs) def show(self): self.__str__() if __name__ == '__main__': with Section('Container Abstract Data Type'): val_cont = ContainerADT() for n in range(4): val_cont[n * n] = randchars(n) val_cont.insert(n, randchars(n)) print(val_cont.size()) print(val_cont.new('fooo')) for el in val_cont: print('Iterator: {}, membership check ({}) => {}'.format( val_cont[el], el, el in val_cont)) prnt('Value Container', val_cont.elements) print(val_cont.clear()) prnt('Empty Container', val_cont.elements) assert len(val_cont) == 0 ref_cont = ReferenceContainer()
_count += 1 except TypeError: continue if DEBUG: print('Count = {} for property {}'.format(_count, prop)) return _count if DEBUG: with Section('Set Abstract Data Type'): set_adt = SetADT() frozen_set_adt = FrozenSetADT([1, 2, 3, 4, True, False, 'A', 'B', 'C']) for n in range(6): set_adt[n] = rr(0, 10) set_adt[n] = ''.join(randchars(1)) set_adt[n] = choice([True, False]) try: frozen_set_adt[n] = rr(0, 10) except ImmutableSetError: print('Frozen set cannot be modified after creation.') print_h4('Set/Frozen set items', '') ppr(set_adt.items) ppr(frozen_set_adt.items) dynam_set = DynamicSet.create([1, 2, 3, 4], capacity=4) print('Capacity', dynam_set.set_capacity(4)) print('Room left', dynam_set.room_left()) dynam_set.add(range(100))
keys = self.items.keys() values = self.items.values() is_both_key = key in keys and key in values is_both_val = val in keys and val in values if is_both_key or is_both_val: raise ValueError('Item already exists in both key and value' ' -- it can only exist in one!') super(BidirectionalMap, self).__setitem__(key, val) if DEBUG: with Section('Map Abstract Data Type'): map_adt = MapADT(title='map_head') for n in range(6): key = 'map_item-{}'.format(''.join(randchars(8))) map_adt[key] = ''.join(randchars(4)) print(map_adt) with Section('Multi-Map Abstract Data Type'): faker = Factory.create() multimap = MultiMap(title='multi-map_head') print_h2('Multimap', desc='General abstract usage.') for n in range(4): key = 'map_item-{}'.format(n) multimap[key] = ''.join(randchars(4)) print(multimap)