Skip to content

Commit

Permalink
Add dump_as_two_item_tsv.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymoch committed Mar 4, 2016
1 parent 115178c commit ddadf0c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions test/test_dump_as_json.py
@@ -1,5 +1,5 @@
"""
Tests for apyori.print_record_as_json.
Tests for apyori.dump_as_json.
"""

import json
Expand All @@ -10,8 +10,8 @@
except ImportError:
from io import StringIO

from nose.tools import eq_
from nose.tools import raises
from nose.tools import eq_

from apyori import RelationRecord
from apyori import OrderedStatistic
Expand Down
34 changes: 34 additions & 0 deletions test/test_dump_as_two_item_tsv.py
@@ -0,0 +1,34 @@
"""
Tests for apyori.dump_as_two_item_tsv.
"""

# For Python 2 compatibility.
try:
from StringIO import StringIO
except ImportError:
from io import StringIO

from nose.tools import eq_

from apyori import RelationRecord
from apyori import OrderedStatistic
from apyori import dump_as_two_item_tsv


def test_normal():
"""
Test for normal data.
"""
test_data = RelationRecord(
frozenset(['A', 'B']), 0.5, [
OrderedStatistic(frozenset(['A']), frozenset(['B']), 0.8, 1.2),
OrderedStatistic(frozenset(), frozenset(['B']), 0.8, 1.2),
OrderedStatistic(frozenset(['A']), frozenset(), 0.8, 1.2),
]
)
output_file = StringIO()
dump_as_two_item_tsv(test_data, output_file)

output_file.seek(0)
result = output_file.read()
eq_(result, 'A\tB\t0.50000000\t0.80000000\t1.20000000\n')

0 comments on commit ddadf0c

Please sign in to comment.