1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Behat\Behat\Tester\Exception\PendingException; |
4
|
|
|
use Behat\Behat\Context\Context; |
5
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
6
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
7
|
|
|
use Behat\Gherkin\Node\TableNode; |
8
|
|
|
use maxwilms\BloomFilter\BloomFilter; |
9
|
|
|
use maxwilms\BloomFilter\BloomFilterGenerator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Defines application features from the specific context. |
13
|
|
|
*/ |
14
|
|
|
class FeatureContext implements Context, SnippetAcceptingContext |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var BloomFilter |
19
|
|
|
*/ |
20
|
|
|
protected $bloomFilter; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Initializes context. |
24
|
|
|
* |
25
|
|
|
* Every scenario gets its own context instance. |
26
|
|
|
* You can also pass arbitrary arguments to the |
27
|
|
|
* context constructor through behat.yml. |
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @Given a BloomFilter for :elements elements with probability :probability for a false-positive |
36
|
|
|
*/ |
37
|
|
|
public function aBloomfilterForElementsWithProbabilityForAFalsePositive($elements, $probability) |
38
|
|
|
{ |
39
|
|
|
$this->bloomFilter = BloomFilterGenerator::generate($elements, $probability); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @When I insert :item |
44
|
|
|
*/ |
45
|
|
|
public function iInsert($item) |
46
|
|
|
{ |
47
|
|
|
$this->bloomFilter->add($item); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @Then it should confirm :item is in set |
52
|
|
|
*/ |
53
|
|
|
public function itShouldConfirmIsInSet($item) |
54
|
|
|
{ |
55
|
|
|
if (!$this->bloomFilter->contains($item)) { |
56
|
|
|
throw new Exception("$item is not in set!"); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @Then it should confirm :item is not in set |
62
|
|
|
*/ |
63
|
|
|
public function itShouldConfirmIsNotInSet($item) |
64
|
|
|
{ |
65
|
|
|
if ($this->bloomFilter->contains($item)) { |
66
|
|
|
throw new Exception("$item is in set"); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Given /^I serialize and unserialize$/ |
72
|
|
|
*/ |
73
|
|
|
public function iSerializeAndUnserialize() |
74
|
|
|
{ |
75
|
|
|
$serialized = serialize($this->bloomFilter); |
76
|
|
|
$this->bloomFilter = unserialize($serialized); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.