Skip to content

Commit

Permalink
Feature/additional tests (#578)
Browse files Browse the repository at this point in the history
* add test for FunctionFormatter

* add more predicates tests

* add tests for is_non_string_iterable

* rm unnecessary imoprt

* add is_non_string_iterable test for sequence
  • Loading branch information
FlynnOwen committed Feb 14, 2023
1 parent 2ecc6d8 commit 28b0841
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,11 @@ def test_distribution_formatter():
30.00%
38.33%
""")


def test_function_formatter():
def _mult_ten(v):
return v * 10

func_formatter = formats.FunctionFormatter(_mult_ten)
assert func_formatter.format_value(5) == '50'
10 changes: 10 additions & 0 deletions tests/test_predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ def test_both():
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)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from datascience import util
import numpy as np
import pytest
from collections.abc import Sequence

def test_doctests():
results = doctest.testmod(util, optionflags=doctest.NORMALIZE_WHITESPACE)
Expand Down Expand Up @@ -96,3 +97,26 @@ def test_proportions_from_distribution():
uniform = u.column(1)
assert len(uniform) == 50 and _round_eq(1, sum(uniform))
assert [x in (0, 0.5, 1) for x in ds.sample_proportions(2, ds.make_array(.2, .3, .5))]


def test_is_non_string_iterable():
is_string = 'hello'
assert ds.is_non_string_iterable(is_string) == False

is_list = [1, 2, 3]
assert ds.is_non_string_iterable(is_list) == True

is_int = 1
assert ds.is_non_string_iterable(is_int) == False

class IsSequence(Sequence):
"""
Implementation of Sequence abc without __iter__
"""
def __getitem__(self, index):
pass

def __len__(self):
pass
is_sequence = IsSequence()
assert ds.is_non_string_iterable(is_sequence) == True

0 comments on commit 28b0841

Please sign in to comment.