-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for predicates functions
- Loading branch information
Burak Cakan
committed
Aug 18, 2023
1 parent
ec3ebcd
commit 317b20d
Showing
22 changed files
with
2,536 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,101 @@ | ||
import doctest | ||
import pytest | ||
from datascience import predicates | ||
from datascience import * | ||
|
||
def test_both(): | ||
"""Both f and g.""" | ||
p = are.above(2) & are.below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_tautology(): | ||
p = are.above(3) | are.below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, True, True, True, True] | ||
|
||
def test_contradiction(): | ||
p = are.above(3) & are.below(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, False, False] | ||
|
||
def test_either(): | ||
"""Either f or g.""" | ||
p = are.above(3) | are.below(2) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, True, True] | ||
|
||
def test_equal_to(): | ||
"""Equal to y.""" | ||
p = are.equal_to(1) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, False, False] | ||
|
||
def test_above(): | ||
"""Greater than y.""" | ||
p = are.above(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_below(): | ||
"""Less than y.""" | ||
p = are.not_below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_above_or_equal_to(): | ||
"""Greater than or equal to y.""" | ||
p = are.above_or_equal_to(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_below_or_equal_to(): | ||
"""Less than or equal to y.""" | ||
p = are.not_below_or_equal_to(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_strictly_between(): | ||
"""Greater than y and less than z.""" | ||
p = are.strictly_between(2, 4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_between(): | ||
"""Greater than or equal to y and less than z.""" | ||
p = are.between(3, 4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_between_or_equal_to(): | ||
"""Greater than or equal to y and less than or equal to z.""" | ||
p = are.between_or_equal_to(3, 3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_not_equal_to(): | ||
"""Greater than or equal to y and less than or equal to z.""" | ||
p = are.not_equal_to(5) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, True, True, True, False] | ||
|
||
def test_not(): | ||
"""Not f.""" | ||
not_f = predicates._not(lambda x: 2*x) | ||
assert not_f(5) == -10 | ||
|
||
def test_xor(): | ||
"""XOR f and g.""" | ||
p = are.above(3) ^ are.below(2) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, True, True] | ||
|
||
############ | ||
# Doctests # | ||
############ | ||
|
||
|
||
def test_doctests(): | ||
results = doctest.testmod(predicates, | ||
optionflags=doctest.NORMALIZE_WHITESPACE) | ||
assert results.failed == 0 |
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,108 @@ | ||
import doctest | ||
import pytest | ||
from datascience import predicates | ||
from datascience import * | ||
|
||
def test_both(): | ||
"""Both f and g.""" | ||
p = are.above(2) & are.below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_tautology(): | ||
p = are.above(3) | are.below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, True, True, True, True] | ||
|
||
def test_contradiction(): | ||
p = are.above(3) & are.below(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, False, False] | ||
|
||
def test_either(): | ||
"""Either f or g.""" | ||
p = are.above(3) | are.below(2) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, True, True] | ||
|
||
def test_equal_to(): | ||
"""Equal to y.""" | ||
p = are.equal_to(1) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, False, False] | ||
|
||
def test_above(): | ||
"""Greater than y.""" | ||
p = are.above(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_below(): | ||
"""Less than y.""" | ||
p = are.not_below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_above_or_equal_to(): | ||
"""Greater than or equal to y.""" | ||
p = are.above_or_equal_to(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_below_or_equal_to(): | ||
"""Less than or equal to y.""" | ||
p = are.not_below_or_equal_to(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_strictly_between(): | ||
"""Greater than y and less than z.""" | ||
p = are.strictly_between(2, 4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_between(): | ||
"""Greater than or equal to y and less than z.""" | ||
p = are.between(3, 4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_between_or_equal_to(): | ||
"""Greater than or equal to y and less than or equal to z.""" | ||
p = are.between_or_equal_to(3, 3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_not_equal_to(): | ||
"""Greater than or equal to y and less than or equal to z.""" | ||
p = are.not_equal_to(5) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, True, True, True, False] | ||
|
||
def test_not(): | ||
"""Not f.""" | ||
not_f = predicates._not(lambda x: 2*x) | ||
assert not_f(5) == -10 | ||
|
||
def test_xor(): | ||
"""XOR f and g.""" | ||
p = are.above(3) ^ are.below(2) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, True, True] | ||
|
||
def test_containing(): | ||
|
||
p = are.containing("L") | ||
string_list = ["Lemon","LidL","like","Amsterdam","buLk"] | ||
ps = [p(x) for x in string_list] | ||
assert ps == [True, True, False, False, True] | ||
|
||
############ | ||
# Doctests # | ||
############ | ||
|
||
|
||
def test_doctests(): | ||
results = doctest.testmod(predicates, | ||
optionflags=doctest.NORMALIZE_WHITESPACE) | ||
assert results.failed == 0 |
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,108 @@ | ||
import doctest | ||
import pytest | ||
from datascience import predicates | ||
from datascience import * | ||
|
||
def test_both(): | ||
"""Both f and g.""" | ||
p = are.above(2) & are.below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_tautology(): | ||
p = are.above(3) | are.below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, True, True, True, True] | ||
|
||
def test_contradiction(): | ||
p = are.above(3) & are.below(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, False, False] | ||
|
||
def test_either(): | ||
"""Either f or g.""" | ||
p = are.above(3) | are.below(2) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, True, True] | ||
|
||
def test_equal_to(): | ||
"""Equal to y.""" | ||
p = are.equal_to(1) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, False, False] | ||
|
||
def test_above(): | ||
"""Greater than y.""" | ||
p = are.above(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_below(): | ||
"""Less than y.""" | ||
p = are.not_below(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_above_or_equal_to(): | ||
"""Greater than or equal to y.""" | ||
p = are.above_or_equal_to(4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_below_or_equal_to(): | ||
"""Less than or equal to y.""" | ||
p = are.not_below_or_equal_to(3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, False, True, True] | ||
|
||
def test_strictly_between(): | ||
"""Greater than y and less than z.""" | ||
p = are.strictly_between(2, 4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_between(): | ||
"""Greater than or equal to y and less than z.""" | ||
p = are.between(3, 4) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_between_or_equal_to(): | ||
"""Greater than or equal to y and less than or equal to z.""" | ||
p = are.between_or_equal_to(3, 3) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [False, False, True, False, False] | ||
|
||
def test_not_equal_to(): | ||
"""Greater than or equal to y and less than or equal to z.""" | ||
p = are.not_equal_to(5) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, True, True, True, False] | ||
|
||
def test_not(): | ||
"""Not f.""" | ||
not_f = predicates._not(lambda x: 2*x) | ||
assert not_f(5) == -10 | ||
|
||
def test_xor(): | ||
"""XOR f and g.""" | ||
p = are.above(3) ^ are.below(2) | ||
ps = [p(x) for x in range(1, 6)] | ||
assert ps == [True, False, False, True, True] | ||
|
||
def test_containing(): | ||
|
||
p = are.containing("L") | ||
string_list = ["Lemon","LidL","like","Amsterdam","buLk"] | ||
ps = [p(x) for x in string_list] | ||
assert ps == [True, True, False, False, True] | ||
|
||
############ | ||
# Doctests # | ||
############ | ||
|
||
|
||
def test_doctests(): | ||
results = doctest.testmod(predicates, | ||
optionflags=doctest.NORMALIZE_WHITESPACE) | ||
assert results.failed == 0 |
Oops, something went wrong.