-
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.
tests: add
head
, tail
, init
and last
tests
- Loading branch information
Showing
4 changed files
with
468 additions
and
0 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,115 @@ | ||
import pytest | ||
|
||
from magic_list import list | ||
|
||
|
||
def test_ml_empty(ml_empty): | ||
with pytest.raises(TypeError) as ctx: | ||
ml_empty.head | ||
|
||
assert str(ctx.value) == "empty list has no head" | ||
|
||
|
||
def test_ml_with_one_int_truthy(ml_with_one_int_truthy): | ||
assert ml_with_one_int_truthy.head == 42 | ||
|
||
|
||
def test_ml_with_one_int_falsy(ml_with_one_int_falsy): | ||
assert ml_with_one_int_falsy.head == 0 | ||
|
||
|
||
def test_ml_with_one_str(ml_with_one_str): | ||
assert ml_with_one_str.head == "hello" | ||
|
||
|
||
def test_ml_with_one_list_nonempty(ml_with_one_list_nonempty): | ||
assert ml_with_one_list_nonempty.head == [3.14159, 2.71828, 9.80665] | ||
|
||
|
||
def test_ml_with_one_magic_list_nonempty(ml_with_one_magic_list_nonempty): | ||
assert ml_with_one_magic_list_nonempty.head == list([14, 3, 1872]) | ||
|
||
|
||
def test_ml_with_one_tuple_nonempty(ml_with_one_tuple_nonempty): | ||
assert ml_with_one_tuple_nonempty.head == ("John", "Doe", 23, 2183.76) | ||
|
||
|
||
def test_ml_with_different_several_int(ml_with_different_several_int): | ||
assert ml_with_different_several_int.head == 76 | ||
|
||
|
||
def test_ml_with_different_several_int_truthy(ml_with_different_several_int_truthy): | ||
assert ml_with_different_several_int_truthy.head == 1 | ||
|
||
|
||
def test_ml_with_different_several_str(ml_with_different_several_str): | ||
assert ml_with_different_several_str.head == "hello" | ||
|
||
|
||
def test_ml_with_different_several_list_nonempty( | ||
ml_with_different_several_list_nonempty, | ||
): | ||
assert ml_with_different_several_list_nonempty.head == [1, 2, 3] | ||
|
||
|
||
def test_ml_with_different_several_magic_list_nonempty( | ||
ml_with_different_several_magic_list_nonempty, | ||
): | ||
assert ml_with_different_several_magic_list_nonempty.head == list([10, 11, 12]) | ||
|
||
|
||
def test_ml_with_different_several_tuple_nonempty( | ||
ml_with_different_several_tuple_nonempty, | ||
): | ||
assert ml_with_different_several_tuple_nonempty.head == (9, 8, 7) | ||
|
||
|
||
def test_ml_with_duplicate_several_int(ml_with_duplicate_several_int): | ||
assert ml_with_duplicate_several_int.head == 1 | ||
|
||
|
||
def test_ml_with_duplicate_several_magic_list_nonempty( | ||
ml_with_duplicate_several_magic_list_nonempty, | ||
): | ||
assert ml_with_duplicate_several_magic_list_nonempty.head == list( | ||
["hello", "world"], | ||
) | ||
|
||
|
||
def test_ml_with_equal_several_int_truthy(ml_with_equal_several_int_truthy): | ||
assert ml_with_equal_several_int_truthy.head == 23 | ||
|
||
|
||
def test_ml_with_equal_several_int_falsy(ml_with_equal_several_int_falsy): | ||
assert ml_with_equal_several_int_falsy.head == 0 | ||
|
||
|
||
def test_ml_with_equal_several_list_empty(ml_with_equal_several_list_empty): | ||
assert ml_with_equal_several_list_empty.head == [] | ||
|
||
|
||
def test_ml_with_equal_several_magic_list_nonempty( | ||
ml_with_equal_several_magic_list_nonempty, | ||
): | ||
assert ml_with_equal_several_magic_list_nonempty.head == list([3, 5, 2]) | ||
|
||
|
||
def test_ml_with_equal_several_magic_list_empty(ml_with_equal_several_magic_list_empty): | ||
assert ml_with_equal_several_magic_list_empty.head == list() | ||
|
||
|
||
def test_ml_recursive_with_itself(ml_recursive_with_itself): | ||
assert ml_recursive_with_itself.head == ml_recursive_with_itself | ||
assert ml_recursive_with_itself.head.head == ml_recursive_with_itself.head | ||
|
||
|
||
def test_ml_with_recursive_item(ml_with_recursive_item): | ||
assert ml_with_recursive_item.head == ml_with_recursive_item.head[0] | ||
|
||
|
||
def test_ml_with_mutually_recursive_item(ml_with_mutually_recursive_item): | ||
assert ml_with_mutually_recursive_item == ml_with_mutually_recursive_item.head[0] | ||
assert ( | ||
ml_with_mutually_recursive_item.head | ||
== ml_with_mutually_recursive_item.head[0].head | ||
) |
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,119 @@ | ||
import pytest | ||
|
||
from magic_list import list | ||
|
||
|
||
def test_ml_empty(ml_empty): | ||
with pytest.raises(TypeError) as ctx: | ||
ml_empty.init | ||
|
||
assert str(ctx.value) == "empty list has no init" | ||
|
||
|
||
def test_ml_with_one_int_truthy(ml_with_one_int_truthy): | ||
assert ml_with_one_int_truthy.init == list() | ||
|
||
|
||
def test_ml_with_one_int_falsy(ml_with_one_int_falsy): | ||
assert ml_with_one_int_falsy.init == list() | ||
|
||
|
||
def test_ml_with_one_str(ml_with_one_str): | ||
assert ml_with_one_str.init == list() | ||
|
||
|
||
def test_ml_with_one_list_nonempty(ml_with_one_list_nonempty): | ||
assert ml_with_one_list_nonempty.init == list() | ||
|
||
|
||
def test_ml_with_one_magic_list_nonempty(ml_with_one_magic_list_nonempty): | ||
assert ml_with_one_magic_list_nonempty.init == list() | ||
|
||
|
||
def test_ml_with_one_tuple_nonempty(ml_with_one_tuple_nonempty): | ||
assert ml_with_one_tuple_nonempty.init == list() | ||
|
||
|
||
def test_ml_with_different_several_int(ml_with_different_several_int): | ||
assert ml_with_different_several_int.init == list([76, 39, -7, 0]) | ||
|
||
|
||
def test_ml_with_different_several_int_truthy(ml_with_different_several_int_truthy): | ||
assert ml_with_different_several_int_truthy.init == list([1, 2, 4, 8, 16]) | ||
|
||
|
||
def test_ml_with_different_several_str(ml_with_different_several_str): | ||
assert ml_with_different_several_str.init == list( | ||
["hello", "", "world", "goodbye", " "], | ||
) | ||
|
||
|
||
def test_ml_with_different_several_list_nonempty( | ||
ml_with_different_several_list_nonempty, | ||
): | ||
assert ml_with_different_several_list_nonempty.init == list([[1, 2, 3], [4, 5, 6]]) | ||
|
||
|
||
def test_ml_with_different_several_magic_list_nonempty( | ||
ml_with_different_several_magic_list_nonempty, | ||
): | ||
assert ml_with_different_several_magic_list_nonempty.init == list( | ||
[list([10, 11, 12]), list([13, 14, 15])], | ||
) | ||
|
||
|
||
def test_ml_with_different_several_tuple_nonempty( | ||
ml_with_different_several_tuple_nonempty, | ||
): | ||
assert ml_with_different_several_tuple_nonempty.init == list([(9, 8, 7), (6, 5, 4)]) | ||
|
||
|
||
def test_ml_with_duplicate_several_int(ml_with_duplicate_several_int): | ||
assert ml_with_duplicate_several_int.init == list([1, 0, 0, 1, 0, 1, -1, 1]) | ||
|
||
|
||
def test_ml_with_duplicate_several_magic_list_nonempty( | ||
ml_with_duplicate_several_magic_list_nonempty, | ||
): | ||
assert ml_with_duplicate_several_magic_list_nonempty.init == list( | ||
[ | ||
list(["hello", "world"]), | ||
list(["goodbye", "mars"]), | ||
], | ||
) | ||
|
||
|
||
def test_ml_with_equal_several_int_truthy(ml_with_equal_several_int_truthy): | ||
assert ml_with_equal_several_int_truthy.init == list([23, 23, 23]) | ||
|
||
|
||
def test_ml_with_equal_several_int_falsy(ml_with_equal_several_int_falsy): | ||
assert ml_with_equal_several_int_falsy.init == list([0, 0, 0]) | ||
|
||
|
||
def test_ml_with_equal_several_list_empty(ml_with_equal_several_list_empty): | ||
assert ml_with_equal_several_list_empty.init == list([[], [], []]) | ||
|
||
|
||
def test_ml_with_equal_several_magic_list_nonempty( | ||
ml_with_equal_several_magic_list_nonempty, | ||
): | ||
assert ml_with_equal_several_magic_list_nonempty.init == list( | ||
[list([3, 5, 2]), list([3, 5, 2])], | ||
) | ||
|
||
|
||
def test_ml_with_equal_several_magic_list_empty(ml_with_equal_several_magic_list_empty): | ||
assert ml_with_equal_several_magic_list_empty.init == list([list(), list(), list()]) | ||
|
||
|
||
def test_ml_recursive_with_itself(ml_recursive_with_itself): | ||
assert ml_recursive_with_itself.init == list() | ||
|
||
|
||
def test_ml_with_recursive_item(ml_with_recursive_item): | ||
assert ml_with_recursive_item.init == list() | ||
|
||
|
||
def test_ml_with_mutually_recursive_item(ml_with_mutually_recursive_item): | ||
assert ml_with_mutually_recursive_item.init == list() |
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,115 @@ | ||
import pytest | ||
|
||
from magic_list import list | ||
|
||
|
||
def test_ml_empty(ml_empty): | ||
with pytest.raises(TypeError) as ctx: | ||
ml_empty.last | ||
|
||
assert str(ctx.value) == "empty list has no last" | ||
|
||
|
||
def test_ml_with_one_int_truthy(ml_with_one_int_truthy): | ||
assert ml_with_one_int_truthy.last == 42 | ||
|
||
|
||
def test_ml_with_one_int_falsy(ml_with_one_int_falsy): | ||
assert ml_with_one_int_falsy.last == 0 | ||
|
||
|
||
def test_ml_with_one_str(ml_with_one_str): | ||
assert ml_with_one_str.last == "hello" | ||
|
||
|
||
def test_ml_with_one_list_nonempty(ml_with_one_list_nonempty): | ||
assert ml_with_one_list_nonempty.last == [3.14159, 2.71828, 9.80665] | ||
|
||
|
||
def test_ml_with_one_magic_list_nonempty(ml_with_one_magic_list_nonempty): | ||
assert ml_with_one_magic_list_nonempty.last == list([14, 3, 1872]) | ||
|
||
|
||
def test_ml_with_one_tuple_nonempty(ml_with_one_tuple_nonempty): | ||
assert ml_with_one_tuple_nonempty.last == ("John", "Doe", 23, 2183.76) | ||
|
||
|
||
def test_ml_with_different_several_int(ml_with_different_several_int): | ||
assert ml_with_different_several_int.last == 15 | ||
|
||
|
||
def test_ml_with_different_several_int_truthy(ml_with_different_several_int_truthy): | ||
assert ml_with_different_several_int_truthy.last == 32 | ||
|
||
|
||
def test_ml_with_different_several_str(ml_with_different_several_str): | ||
assert ml_with_different_several_str.last == "mars" | ||
|
||
|
||
def test_ml_with_different_several_list_nonempty( | ||
ml_with_different_several_list_nonempty, | ||
): | ||
assert ml_with_different_several_list_nonempty.last == [7, 8, 9] | ||
|
||
|
||
def test_ml_with_different_several_magic_list_nonempty( | ||
ml_with_different_several_magic_list_nonempty, | ||
): | ||
assert ml_with_different_several_magic_list_nonempty.last == list([16, 17, 18]) | ||
|
||
|
||
def test_ml_with_different_several_tuple_nonempty( | ||
ml_with_different_several_tuple_nonempty, | ||
): | ||
assert ml_with_different_several_tuple_nonempty.last == (3, 2, 1) | ||
|
||
|
||
def test_ml_with_duplicate_several_int(ml_with_duplicate_several_int): | ||
assert ml_with_duplicate_several_int.last == 0 | ||
|
||
|
||
def test_ml_with_duplicate_several_magic_list_nonempty( | ||
ml_with_duplicate_several_magic_list_nonempty, | ||
): | ||
assert ml_with_duplicate_several_magic_list_nonempty.last == list( | ||
["hello", "world"], | ||
) | ||
|
||
|
||
def test_ml_with_equal_several_int_truthy(ml_with_equal_several_int_truthy): | ||
assert ml_with_equal_several_int_truthy.last == 23 | ||
|
||
|
||
def test_ml_with_equal_several_int_falsy(ml_with_equal_several_int_falsy): | ||
assert ml_with_equal_several_int_falsy.last == 0 | ||
|
||
|
||
def test_ml_with_equal_several_list_empty(ml_with_equal_several_list_empty): | ||
assert ml_with_equal_several_list_empty.last == [] | ||
|
||
|
||
def test_ml_with_equal_several_magic_list_nonempty( | ||
ml_with_equal_several_magic_list_nonempty, | ||
): | ||
assert ml_with_equal_several_magic_list_nonempty.last == list([3, 5, 2]) | ||
|
||
|
||
def test_ml_with_equal_several_magic_list_empty(ml_with_equal_several_magic_list_empty): | ||
assert ml_with_equal_several_magic_list_empty.last == list() | ||
|
||
|
||
def test_ml_recursive_with_itself(ml_recursive_with_itself): | ||
assert ml_recursive_with_itself.last == ml_recursive_with_itself | ||
assert ml_recursive_with_itself.last.last == ml_recursive_with_itself.last | ||
|
||
|
||
def test_ml_with_recursive_item(ml_with_recursive_item): | ||
assert ml_with_recursive_item.last == ml_with_recursive_item.last[0] | ||
|
||
|
||
def test_ml_with_mutually_recursive_item(ml_with_mutually_recursive_item): | ||
assert ml_with_mutually_recursive_item == ml_with_mutually_recursive_item.last[0] | ||
assert ( | ||
ml_with_mutually_recursive_item.last | ||
== ml_with_mutually_recursive_item.last[0].last | ||
) |
Oops, something went wrong.