-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "add-only-dictionary" | ||
version = "0.1.3" | ||
version = "0.1.4" | ||
description = "Add Only Dictionary" | ||
authors = ["Matt Koski <[email protected]>"] | ||
license = "MIT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""Add Only Dictionary.""" | ||
|
||
from add_only_dictionary.aodict import AODict as AODict | ||
from add_only_dictionary.aolist import AOList as AOList |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""class AODict.""" | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
from typing import List | ||
|
||
|
||
try: | ||
from typing_extensions import SupportsIndex | ||
except ImportError: | ||
from typing import SupportsIndex | ||
|
||
|
||
class AOList(List[Any]): | ||
"""AOList class.""" | ||
|
||
def __init__(self, initial_list: list[Any] | None = None): | ||
"""Create new AOList. If list is given, convert it.""" | ||
if initial_list is not None: | ||
super().extend(initial_list) | ||
|
||
def __delitem__(self, key: Any) -> None: | ||
"""No op on AOList.""" | ||
pass | ||
|
||
def remove(self, item: Any) -> None: | ||
"""No op on AOList.""" | ||
pass | ||
|
||
def pop(self, idx: SupportsIndex = ...) -> Any: | ||
"""No op on AOList.""" | ||
pass | ||
|
||
def clear(self) -> None: | ||
"""No op on AOList.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Tests for AOList.""" | ||
from add_only_dictionary import AOList | ||
|
||
|
||
def check_invariants(ao: AOList) -> None: | ||
"""Common checks that shoujld continue being true.""" | ||
assert ao[0] == 1 | ||
assert ao[-1] == 3 | ||
assert len(ao) == 3 | ||
|
||
|
||
def test_methods() -> None: | ||
"""Test the four methods that would normally remove elements.""" | ||
ao: AOList = AOList([1, 2, 3]) | ||
check_invariants(ao) | ||
|
||
del ao[0] | ||
check_invariants(ao) | ||
|
||
ao.remove(2) | ||
check_invariants(ao) | ||
|
||
ao.pop() | ||
check_invariants(ao) | ||
|
||
ao.clear() | ||
check_invariants(ao) |