Skip to content

Commit 861c7ab

Browse files
committed
Update PHPUnit to PHPUnit10
1 parent 073b33a commit 861c7ab

16 files changed

Lines changed: 168 additions & 224 deletions

.github/workflows/tag_meged_pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
tools: composer:v2
2424

2525
- name: Checkout code
26-
uses: actions/checkout@v3
26+
uses: actions/checkout@v4
2727
with:
2828
fetch-depth: 0
2929

.github/workflows/test_pull_request.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
tools: composer:v2
1616

1717
- name: Checkout code
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 0
2121

@@ -63,12 +63,12 @@ jobs:
6363
tools: composer:v2
6464

6565
- name: Set up Node
66-
uses: actions/setup-node@v3
66+
uses: actions/setup-node@v4
6767
with:
6868
node-version: '14.x'
6969

7070
- name: Checkout code
71-
uses: actions/checkout@v3
71+
uses: actions/checkout@v4
7272
with:
7373
fetch-depth: 0
7474

@@ -126,25 +126,25 @@ jobs:
126126
tools: composer:v2
127127

128128
- name: Set up Node
129-
uses: actions/setup-node@v3
129+
uses: actions/setup-node@v4
130130
with:
131131
node-version: '14.x'
132132

133133
- name: Checkout code
134-
uses: actions/checkout@v3
134+
uses: actions/checkout@v4
135135
with:
136136
fetch-depth: 0
137137

138138
- name: Run Composer
139139
run: composer install --no-interaction
140140

141141
- name: Update PHPUnit for Code Coverage
142-
run: composer require phpunit/phpunit:^9.6 phploc/phploc:* sebastian/version:* --with-all-dependencies
142+
run: composer require phpunit/phpunit:^10.5 sebastian/version:* --with-all-dependencies
143143

144144
- name: PHP Lint
145145
run: ./vendor/bin/parallel-lint src tests examples
146146

147147
- name: Unit tests
148148
run: |
149149
mkdir -p build/logs
150-
./vendor/bin/phpunit ./tests/ --coverage-clover build/logs/clover.xml
150+
./vendor/bin/phpunit ./tests/ --coverage-clover build/logs/clover.xml --coverage-filter=./src/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/vendor/
2+
composer.lock
3+
.php-version

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,40 +149,47 @@ This class treats basic matters of primes.
149149
// judge if all of $n are prime or not
150150
$n = [ 2, 3, 5, ];
151151
echo sprintf(
152-
"Are all of [%s] prime? - %s.\n",
152+
"Are all of [%s] prime? - %s.\n\n",
153153
implode(', ', $n),
154154
$p->isPrimeAll($n) ? 'Yes' : 'No'
155155
);
156156

157+
// a prime previous to $n
158+
$n = 5;
159+
echo sprintf("A prime previous to %d is %d.\n", $n, $p->previous($n));
160+
157161
// a prime next to $n
158162
$n = 5;
159-
echo sprintf("A prime next to %d is %d.\n", $n, $p->next($n));
163+
echo sprintf("A prime next to %d is %d.\n\n", $n, $p->next($n));
160164

161165
// primes between $a and $b
162166
$a = 6;
163167
$b = 14;
164168
echo sprintf(
165-
"Primes between %d and %d are [%s].\n",
169+
"Primes between %d and %d are [%s].\n\n",
166170
$a,
167171
$b,
168172
implode(', ', $p->between($a, $b))
169173
);
170174

171175
// factorize
172176
$n = 1234567890;
173-
echo sprintf("Factorize %d:\n", $n);
177+
echo sprintf("Factorize %d:\n\n", $n);
178+
174179
$r = $p->factorize($n);
175180
$l1 = $p->numberOfDigits(max(array_column($r, 0)));
176181
$l2 = $p->numberOfDigits(max(array_column($r, 1)));
177182
$s = str_repeat(' ', $l1 + 1);
178183
$b = $s . str_repeat('-', $l2);
184+
179185
foreach ($r as $f) {
180186
echo (
181187
$f[0]
182188
? sprintf("%" . $l1 . "d)%" . $l2 . "d\n%s\n", $f[0], $f[1], $b)
183189
: sprintf("%s%" . $l2 . "d\n", $s, $f[1])
184190
);
185191
}
192+
echo "\n";
186193

187194
// Factorized formula
188195
echo $n . " = " . $p->factorizedFormula($n)['formula'] . "\n";
@@ -193,9 +200,14 @@ This class treats basic matters of primes.
193200
```
194201
Is 3 prime? - Yes.
195202
Are all of [2, 3, 5] prime? - Yes.
203+
204+
A prime previous to 5 is 3.
196205
A prime next to 5 is 7.
206+
197207
Primes between 6 and 14 are [7, 11, 13].
208+
198209
Factorize 1234567890:
210+
199211
2)1234567890
200212
----------
201213
3) 617283945
@@ -207,6 +219,7 @@ This class treats basic matters of primes.
207219
3607) 13717421
208220
----------
209221
3803
222+
210223
1234567890 = 2 * 3 ^ 2 * 5 * 3607 * 3803
211224
```
212225

@@ -216,6 +229,7 @@ This class treats basic matters of primes.
216229
|:---|:---|
217230
|`isPrime(int $n)`|judges if the param is prime or not|
218231
|`isPrimeAll(array $elements)`|judges if all of the param are prime or not|
232+
|`previous(int $n)`|returns a prime previous to the param|
219233
|`next(int $n)`|returns a prime next to the param|
220234
|`between(int $a, int $b)`|returns array of primes between the params|
221235
|`factorize(int $n)`|factorize the param and returns the process as an array|
@@ -593,6 +607,6 @@ This class treats basic matters of Bezout's Identity.
593607

594608
*Document Created: 2023/10/19*
595609

596-
*Document Updated: 2024/03/16*
610+
*Document Updated: 2024/04/17*
597611

598612
Copyright 2023 - 2024 macocci7

bin/TestAndLint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test_and_lint() {
5555
echo "-----------------------------------------------------------"
5656
echo "[PHP $1][phpunit]"
5757
./vendor/bin/phpunit ./tests/ \
58-
--color auto
58+
--color=auto
5959
echo "-----------------------------------------------------------"
6060
}
6161

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "macocci7/php-math-integer",
3-
"version": "1.1.1",
3+
"version": "1.1.2",
44
"description": "PHP Math Library of the subjects of number theory(only natural number).",
55
"type": "library",
66
"license": "MIT",
@@ -18,10 +18,9 @@
1818
"minimum-stability": "stable",
1919
"require-dev": {
2020
"squizlabs/php_codesniffer": "^3.7",
21-
"phpunit/phpunit": "^9.6",
21+
"phpunit/phpunit": "^10.5",
2222
"phpmd/phpmd": "^2.15",
2323
"phpstan/phpstan": "^1.10",
24-
"phploc/phploc": "^7.0",
2524
"php-parallel-lint/php-parallel-lint": "^1.3"
2625
}
2726
}

examples/UsePrime.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,47 @@
1313
// judge if all of $n are prime or not
1414
$n = [ 2, 3, 5, ];
1515
echo sprintf(
16-
"Are all of [%s] prime? - %s.\n",
16+
"Are all of [%s] prime? - %s.\n\n",
1717
implode(', ', $n),
1818
$p->isPrimeAll($n) ? 'Yes' : 'No'
1919
);
2020

21+
// a prime previous to $n
22+
$n = 5;
23+
echo sprintf("A prime previous to %d is %d.\n", $n, $p->previous($n));
24+
2125
// a prime next to $n
2226
$n = 5;
23-
echo sprintf("A prime next to %d is %d.\n", $n, $p->next($n));
27+
echo sprintf("A prime next to %d is %d.\n\n", $n, $p->next($n));
2428

2529
// primes between $a and $b
2630
$a = 6;
2731
$b = 14;
2832
echo sprintf(
29-
"Primes between %d and %d are [%s].\n",
33+
"Primes between %d and %d are [%s].\n\n",
3034
$a,
3135
$b,
3236
implode(', ', $p->between($a, $b))
3337
);
3438

3539
// factorize
3640
$n = 1234567890;
37-
echo sprintf("Factorize %d:\n", $n);
41+
echo sprintf("Factorize %d:\n\n", $n);
42+
3843
$r = $p->factorize($n);
3944
$l1 = $p->numberOfDigits(max(array_column($r, 0)));
4045
$l2 = $p->numberOfDigits(max(array_column($r, 1)));
4146
$s = str_repeat(' ', $l1 + 1);
4247
$b = $s . str_repeat('-', $l2);
48+
4349
foreach ($r as $f) {
4450
echo (
4551
$f[0]
4652
? sprintf("%" . $l1 . "d)%" . $l2 . "d\n%s\n", $f[0], $f[1], $b)
4753
: sprintf("%s%" . $l2 . "d\n", $s, $f[1])
4854
);
4955
}
56+
echo "\n";
5057

5158
// Factorized formula
5259
echo $n . " = " . $p->factorizedFormula($n)['formula'] . "\n";

examples/UsePrime.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
Is 3 prime? - Yes.
22
Are all of [2, 3, 5] prime? - Yes.
3+
4+
A prime previous to 5 is 3.
35
A prime next to 5 is 7.
6+
47
Primes between 6 and 14 are [7, 11, 13].
8+
59
Factorize 1234567890:
10+
611
2)1234567890
712
----------
813
3) 617283945
@@ -14,4 +19,5 @@ Factorize 1234567890:
1419
3607) 13717421
1520
----------
1621
3803
22+
1723
1234567890 = 2 * 3 ^ 2 * 5 * 3607 * 3803

src/Prime.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ public function isPrimeAll(array $elements)
5656
return true;
5757
}
5858

59+
/**
60+
* returns the previous prime
61+
* @param int $n
62+
* @return int|null
63+
*/
64+
public function previous(int $n)
65+
{
66+
if ($n <= 2) {
67+
return null;
68+
}
69+
$i = $n - 1;
70+
while (!$this->isPrime($i)) {
71+
--$i;
72+
}
73+
return $i;
74+
}
75+
5976
/**
6077
* returns the next prime
6178
* @param int $n
@@ -65,7 +82,7 @@ public function next(int $n)
6582
{
6683
$i = $n > 1 ? $n + 1 : 2;
6784
while (!$this->isPrime($i)) {
68-
$i++;
85+
++$i;
6986
}
7087
return $i;
7188
}
@@ -122,7 +139,7 @@ public function factorize(int $n)
122139
break;
123140
}
124141
}
125-
$i++;
142+
++$i;
126143
}
127144
return $factors;
128145
}

tests/BezoutTest.php

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
require_once('vendor/autoload.php');
88

9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011
use Macocci7\PhpMathInteger\Bezout;
1112

@@ -34,9 +35,7 @@ public static function provide_set_can_throw_exception_with_invalid_param(): arr
3435
];
3536
}
3637

37-
/**
38-
* @dataProvider provide_set_can_throw_exception_with_invalid_param
39-
*/
38+
#[DataProvider('provide_set_can_throw_exception_with_invalid_param')]
4039
public function test_set_can_throw_exception_with_invalid_param(array $param, string $message): void
4140
{
4241
$b = new Bezout();
@@ -53,9 +52,7 @@ public static function provide_set_can_set_coefficients_correctly(): array
5352
];
5453
}
5554

56-
/**
57-
* @dataProvider provide_set_can_set_coefficients_correctly
58-
*/
55+
#[DataProvider('provide_set_can_set_coefficients_correctly')]
5956
public function test_set_can_set_coefficients_correctly(array $param, array $expect): void
6057
{
6158
$b = new Bezout();
@@ -74,9 +71,7 @@ public static function provide_clear_can_clear_coefficients_correctly(): array
7471
];
7572
}
7673

77-
/**
78-
* @dataProvider provide_clear_can_clear_coefficients_correctly
79-
*/
74+
#[DataProvider('provide_clear_can_clear_coefficients_correctly')]
8075
public function test_clear_can_clear_coeffecients_correctly(array $preset, array $expect): void
8176
{
8277
$b = new Bezout($preset);
@@ -99,9 +94,7 @@ public static function provide_identity_can_return_identity_correctly(): array
9994
];
10095
}
10196

102-
/**
103-
* @dataProvider provide_identity_can_return_identity_correctly
104-
*/
97+
#[DataProvider('provide_identity_can_return_identity_correctly')]
10598
public function test_identity_can_return_identity_correctly(array $preset, string|null $expect): void
10699
{
107100
$b = new Bezout($preset);
@@ -130,9 +123,7 @@ public static function provide_isSolvable_can_judge_correctly(): array
130123
];
131124
}
132125

133-
/**
134-
* @dataProvider provide_isSolvable_can_judge_correctly
135-
*/
126+
#[DataProvider('provide_isSolvable_can_judge_correctly')]
136127
public function test_isSolvable_can_judge_correctly(int|null $a, int|null $b, int|null $c, bool $expect): void
137128
{
138129
$bz = new Bezout();
@@ -153,9 +144,7 @@ public static function provide_solution_can_return_a_solution_set_correctly(): a
153144
];
154145
}
155146

156-
/**
157-
* @dataProvider provide_solution_can_return_a_solution_set_correctly
158-
*/
147+
#[DataProvider('provide_solution_can_return_a_solution_set_correctly')]
159148
public function test_solution_can_return_a_solution_set_correctly(array $preset, array $expect): void
160149
{
161150
$b = new Bezout();
@@ -203,9 +192,7 @@ public static function provide_generalSolution_can_return_general_solution_corre
203192
];
204193
}
205194

206-
/**
207-
* @dataProvider provide_generalSolution_can_return_general_solution_correctly
208-
*/
195+
#[DataProvider('provide_generalSolution_can_return_general_solution_correctly')]
209196
public function test_generalSolution_can_return_general_solution_correctly(array $preset, array $expect): void
210197
{
211198
$b = new Bezout();

0 commit comments

Comments
 (0)