Skip to content

Commit

Permalink
Added test for #6
Browse files Browse the repository at this point in the history
  • Loading branch information
thvitt committed Oct 10, 2020
1 parent e12a289 commit daaffc4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
39 changes: 38 additions & 1 deletion test/conftest.py
@@ -1,9 +1,46 @@
"""
A few fixtures usable for many tests.
To speed testing up, all of these fixtures are marked as 'session' fixtures.
Thus, they MUST NOT be modified by the tests.
"""

import os
from pathlib import Path

import pytest

import delta


@pytest.fixture(scope='session')
def testdir() -> str:
return os.fspath(Path(__file__).parent / 'corpus3')
"""
Test directory with 9 texts from 3 authors
"""
return os.fspath(Path(__file__).parent / 'corpus3')


@pytest.fixture(scope='session')
def corpus(testdir) -> delta.Corpus:
"""
Raw carpus built from the test directory.
"""
return delta.Corpus(testdir)


@pytest.fixture(scope='session')
def c50(corpus) -> delta.Corpus:
"""
Sample corpus limited to the 50 most frequent words.
"""
c50 = corpus.get_mfw_table(50)
return c50


@pytest.fixture(scope='session')
def distances(c50):
"""
A sample distance matrix.
"""
return delta.functions.cosine_delta(c50)
4 changes: 0 additions & 4 deletions test/corpus_test.py
Expand Up @@ -46,10 +46,6 @@ def test_call_fg(feature_generator, testdir):

## Corpus

@pytest.fixture(scope='module')
def corpus(testdir):
return d.Corpus(testdir)

def test_corpus_parse(corpus):
assert corpus.und.sum() == approx(25738.0)

Expand Down
6 changes: 2 additions & 4 deletions test/deltas_test.py
@@ -1,15 +1,13 @@
from pytest import approx

import delta as d
import os
from math import log10, pow
import pytest



@pytest.fixture(scope='module')
def c1000(testdir):
return d.Corpus(testdir).get_mfw_table(1000)
def c1000(corpus):
return corpus.get_mfw_table(1000)


def fn_id(fn):
Expand Down
18 changes: 18 additions & 0 deletions test/test_issue6.py
@@ -0,0 +1,18 @@
import delta


def test_issue_6(distances):
clustering = delta.Clustering(distances)
clusters = clustering.fclustering()
print("\nFLAT CLUSTERS\n", clusters.describe())
print("\nATTEMPTING distances.evaluate()\n")
assert distances.evaluate() is not None


def test_dm_zscore(distances):
z_scores = distances.z_scores()
assert z_scores is not None


def test_dm_operation(distances):
assert distances - 1 is not None

0 comments on commit daaffc4

Please sign in to comment.