-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The .relation_map() method is like .relations(), but the keys are relation objects and map 1-to-1 to targets. This commit also removes the .source() and .target() methods as they didn't work in common situations, as well as the .incoming_relation() method as it was not favored. This commit also adds a new utility function and associated unit tests.
- Loading branch information
Showing
5 changed files
with
117 additions
and
121 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
from wn._util import flatten, unique_list | ||
|
||
|
||
def test_flatten(): | ||
assert flatten([]) == [] | ||
assert flatten([[]]) == [] | ||
assert flatten([[], []]) == [] | ||
assert flatten([[[], []], [[], []]]) == [[], [], [], []] | ||
assert flatten([[1]]) == [1] | ||
assert flatten([[1, 2], [3, 4]]) == [1, 2, 3, 4] | ||
assert flatten(["AB", "CD"]) == ["A", "B", "C", "D"] | ||
|
||
|
||
def test_unique_list(): | ||
assert unique_list([]) == [] | ||
assert unique_list([1]) == [1] | ||
assert unique_list([1, 1, 1, 1, 1]) == [1] | ||
assert unique_list([1, 1, 2, 2, 1]) == [1, 2] | ||
assert unique_list([2, 1, 2, 2, 1]) == [2, 1] | ||
assert unique_list("A") == ["A"] | ||
assert unique_list("AAA") == ["A"] | ||
assert unique_list("ABABA") == ["A", "B"] | ||
assert unique_list([(1, 2), (1, 2), (2, 3)]) == [(1, 2), (2, 3)] |
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
Oops, something went wrong.