aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_cluster.py
blob: f6732064099046b3b0a09d075f43aae15cbc3b8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import pytest
import collections
import tempfile
from fuzzycat.cluster import release_key_title, release_key_title_normalized, release_key_title_nysiis
import os

Case = collections.namedtuple("Case", 'input output')


def test_release_key_title():
    with pytest.raises(KeyError):
        release_key_title({})
    with pytest.raises(KeyError, match='title'):
        release_key_title({'ident': '123'})
    with pytest.raises(KeyError, match='ident'):
        release_key_title({'title': 'deep learning backdoor'})
    with pytest.raises(ValueError, match='title.*missing'):
        release_key_title({'ident': '', 'title': ''})
    cases = (
        Case(input={
            'ident': '',
            'title': 'simhash'
        }, output=('', 'simhash')),
        Case(input={
            'ident': '',
            'title': 'Simhash'
        }, output=('', 'Simhash')),
        Case(input={
            'ident': '',
            'title': 'Sim  hash'
        }, output=('', 'Sim  hash')),
    )
    for case in cases:
        assert case.output == release_key_title(case.input)


def test_release_key_title_normalized():
    cases = (
        Case(input={
            'ident': '',
            'title': 'simhash'
        }, output=('', 'simhash')),
        Case(input={
            'ident': '',
            'title': 'Simhash'
        }, output=('', 'simhash')),
        Case(input={
            'ident': '',
            'title': 'Sim  hash'
        }, output=('', 'simhash')),
        Case(input={
            'ident': '',
            'title': 'THE year 1929'
        }, output=('', 'theyear1929')),
        Case(input={
            'ident': '',
            'title': '2019?'
        }, output=('', '2019')),
        Case(input={
            'ident': '123',
            'title': 'H~~2019?'
        }, output=('123', 'h2019')),
    )
    for case in cases:
        assert case.output == release_key_title_normalized(case.input), 'failed case {}'.format(
            case.input)


def test_release_key_title_nysiis():
    cases = (
        Case(input={
            'ident': '',
            'title': 'simhash'
        }, output=('', 'SANAS')),
        Case(input={
            'ident': '',
            'title': 'Simhash'
        }, output=('', 'SANAS')),
        Case(input={
            'ident': '',
            'title': 'Sim  hash'
        }, output=('', 'SANAS')),
        Case(input={
            'ident': '',
            'title': 'THE year 1929'
        }, output=('', 'TAR')),
        Case(input={
            'ident': '',
            'title': '2019?'
        }, output=('', '')),
        Case(input={
            'ident': '123',
            'title': 'H~~2019?'
        }, output=('123', 'H')),
        Case(input={
            'ident': '123',
            'title': '世界'
        }, output=('123', '')),
    )
    for case in cases:
        assert case.output == release_key_title_nysiis(case.input), 'failed case {}'.format(
            case.input)