|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace spec\drupol\phpngrams; |
|
4
|
|
|
|
|
5
|
|
|
use drupol\phpngrams\NGrams; |
|
6
|
|
|
use PhpSpec\ObjectBehavior; |
|
7
|
|
|
|
|
8
|
|
|
class NGramsSpec extends ObjectBehavior |
|
9
|
|
|
{ |
|
10
|
|
|
public function it_is_initializable() |
|
11
|
|
|
{ |
|
12
|
|
|
$this->shouldHaveType(NGrams::class); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function it_can_get_ngram_from_a_string() |
|
16
|
|
|
{ |
|
17
|
|
|
$result = [ |
|
18
|
|
|
'he', 'el', 'll', 'lo', 'oh' |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
$this->ngramsString('hello', 2)->shouldIterateAs(new \ArrayIterator($result)); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function it_can_get_ngram_from_a_string_with_big_n() |
|
25
|
|
|
{ |
|
26
|
|
|
$result = [ |
|
27
|
|
|
'hello', 'elloh', 'llohe', 'lohel', 'ohell' |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
$this->ngramsString('hello', 10)->shouldIterateAs(new \ArrayIterator($result)); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function it_can_get_ngram_from_a_string_without_cycling() |
|
34
|
|
|
{ |
|
35
|
|
|
$result = [ |
|
36
|
|
|
'hel', 'ell', 'llo', 'lo ', 'o w', ' wo', 'wor', 'orl', 'rld' |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
$this->ngramsString('hello world', 3, false)->shouldIterateAs(new \ArrayIterator($result)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function it_can_get_ngram_from_an_array() |
|
43
|
|
|
{ |
|
44
|
|
|
$result = [ |
|
45
|
|
|
['h', 'e'], ['e','l'], ['l','l'], ['l','o'], ['o','h'] |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$this->ngramsArray(['h', 'e', 'l', 'l', 'o'], 2)->shouldIterateAs(new \ArrayIterator($result)); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function it_can_get_ngram_from_an_array_with_big_n() |
|
52
|
|
|
{ |
|
53
|
|
|
$result = [ |
|
54
|
|
|
['h','e','l','l','o'], |
|
55
|
|
|
['e','l','l','o','h'], |
|
56
|
|
|
['l','l','o','h','e'], |
|
57
|
|
|
['l','o','h','e','l'], |
|
58
|
|
|
['o','h','e','l','l'], |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
$this->ngramsArray(['h', 'e', 'l', 'l', 'o'], 10)->shouldIterateAs(new \ArrayIterator($result)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function it_can_get_ngram_from_an_array_without_cycling() |
|
65
|
|
|
{ |
|
66
|
|
|
$result = [ |
|
67
|
|
|
['h','e','l'], |
|
68
|
|
|
['e','l','l'], |
|
69
|
|
|
['l','l','o'], |
|
70
|
|
|
['l','o',' '], |
|
71
|
|
|
['o',' ','w'], |
|
72
|
|
|
[' ','w','o'], |
|
73
|
|
|
['w','o','r'], |
|
74
|
|
|
['o','r','l'], |
|
75
|
|
|
['r','l','d'], |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
$this->ngramsArray(['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'], 3, false)->shouldIterateAs(new \ArrayIterator($result)); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|