Skip to content

Commit 33d2de7

Browse files
committed
test: add test for to be sum of
1 parent 6cbbb8b commit 33d2de7

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ This plugin affords math related expectations.
6161
expect(4)->not->toBeFactorialOf(2);
6262
```
6363

64+
#### `toBeSumOf()`
65+
```php
66+
expect(6)->toBeSumOf([1, 2, 3]);
67+
expect(4)->not->toBeSumOf([2, 3]);
68+
```
69+
6470
#### `toBeSummationOf()`
6571
$$\sum\limits_n^k x * 2$$
6672
```php

tests/toBeSumOf.php

+18-16
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22

33
use PHPUnit\Framework\ExpectationFailedException;
44

5-
it('passes', function (int $sum, int $n, int $k, callable $step): void {
6-
expect($sum)->toBeSumOf($n, $k, $step);
5+
it('passes', function (int $sum, array $numbers): void {
6+
expect($sum)->toBeSumOf($numbers);
77
})->with([
8-
[110, 0, 10, static fn (int $i): int => $i * 2],
9-
[418, 2, 20, static fn (int $i): int => $i * 2],
10-
[1628, 4, 40, static fn (int $i): int => $i * 2],
11-
[3630, 6, 60, static fn (int $i): int => $i * 2],
12-
[6424, 8, 80, static fn (int $i): int => $i * 2],
8+
[10, [3, 3, 4]],
9+
[20, [4, 4, 4, 4, 4]],
10+
[30, [5, 5, 5, 5, 5, 5]],
11+
[40, [6, 6, 6, 6, 6, 6, 4]],
12+
[50, [7, 7, 7, 7, 7, 7, 7, 1]],
13+
[72, [8, 8, 8, 8, 8, 8, 8, 8, 8]],
14+
[88, [9, 9, 9, 9, 9, 9, 9, 9, 9, 7]],
15+
[110, [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]],
1316
]);
1417

15-
it('passes not', function (int $n, int $k, callable $step): void {
16-
expect(1)->not->toBeSumOf($n, $k, $step);
18+
it('passes not', function (array $numbers): void {
19+
expect(1)->not->toBeSumOf($numbers);
1720
})->with([
18-
[0, 10, static fn (int $i): int => $i * 2],
19-
[2, 20, static fn (int $i): int => $i * 2],
20-
[4, 40, static fn (int $i): int => $i * 2],
21-
[6, 60, static fn (int $i): int => $i * 2],
22-
[8, 80, static fn (int $i): int => $i * 2],
21+
[[2, 3]],
22+
[[1, 2, 3]],
23+
[[1, 2, 3, 4]],
24+
[[1, 2, 3, 4, 5]],
2325
]);
2426

2527
test('failures', function (): void {
26-
expect(1)->toBeSumOf(0, 1, static fn (int $i): int => $i * 2);
28+
expect(1)->toBeSumOf([]);
2729
})->throws(ExpectationFailedException::class);
2830

2931
test('failures not', function (): void {
30-
expect(2)->not->toBeSumOf(0, 1, static fn (int $i): int => $i * 2);
32+
expect(2)->not->toBeSumOf([2]);
3133
})->throws(ExpectationFailedException::class);

0 commit comments

Comments
 (0)