From daaffc44eaa5ada8bcdc5d865b07cf70a80687e8 Mon Sep 17 00:00:00 2001 From: Thorsten Vitt Date: Sat, 10 Oct 2020 17:27:49 +0200 Subject: [PATCH] Added test for #6 --- test/conftest.py | 39 ++++++++++++++++++++++++++++++++++++++- test/corpus_test.py | 4 ---- test/deltas_test.py | 6 ++---- test/test_issue6.py | 18 ++++++++++++++++++ 4 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 test/test_issue6.py diff --git a/test/conftest.py b/test/conftest.py index a251c02..a10ba14 100644 --- a/test/conftest.py +++ b/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') \ No newline at end of file + """ + 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) diff --git a/test/corpus_test.py b/test/corpus_test.py index 7abc492..d28ec2b 100644 --- a/test/corpus_test.py +++ b/test/corpus_test.py @@ -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) diff --git a/test/deltas_test.py b/test/deltas_test.py index 7f1b365..6923da6 100644 --- a/test/deltas_test.py +++ b/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): diff --git a/test/test_issue6.py b/test/test_issue6.py new file mode 100644 index 0000000..ce3ba82 --- /dev/null +++ b/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 \ No newline at end of file