-
Notifications
You must be signed in to change notification settings - Fork 443
Expand file tree
/
Copy pathCalculatorBehavior.php
More file actions
83 lines (66 loc) · 1.83 KB
/
CalculatorBehavior.php
File metadata and controls
83 lines (66 loc) · 1.83 KB
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
<?php
namespace spec\Money\Calculator;
use Money\Calculator;
/**
* Mocking with typehints usage won't work here as the trait is autoloaded.
*
* @see https://github.com/phpspec/phpspec/issues/825
*/
trait CalculatorBehavior
{
function it_is_a_calculator()
{
$this->shouldImplement(Calculator::class);
}
function it_compares_two_values()
{
$this->compare(2, 1)->shouldReturn(1);
$this->compare(1, 2)->shouldReturn(-1);
$this->compare(1, 1)->shouldReturn(0);
}
function it_adds_two_values()
{
$this->add(rand(-100, 100), rand(-100, 100))->shouldBeString();
}
function it_subtracts_a_value_from_another()
{
$this->subtract(rand(-100, 100), rand(-100, 100))->shouldBeString();
}
function it_multiplies_a_value_by_another()
{
$this->multiply(rand(-100, 100), rand(-100, 100))->shouldBeString();
}
function it_divides_a_value_by_another()
{
$this->divide(rand(-100, 100), rand(1, 100))->shouldBeString();
}
function it_ceils_a_value()
{
$this->ceil(rand(-100, 100) / 100)->shouldBeString();
}
function it_floors_a_value()
{
$this->floor(rand(-100, 100) / 100)->shouldBeString();
}
function it_calculates_the_absolute_value()
{
$result = $this->absolute(rand(1, 100));
$result->shouldBeGreaterThanZero();
$result->shouldBeString();
$result = $this->absolute(rand(-100, -1));
$result->shouldBeGreaterThanZero();
$result->shouldBeString();
}
function it_shares_a_value()
{
$this->share(10, 2, 4)->shouldBeString();
}
public function getMatchers()
{
return [
'beGreaterThanZero' => function ($subject) {
return $subject > 0;
},
];
}
}