Skip to content

Commit e96c438

Browse files
Merge pull request #69 from TheDragonCode/4.x
[4.x] Add snapshots for `RoundTest` with multiple data sets for improved test validation
2 parents b86388f + e684a0f commit e96c438

12 files changed

Lines changed: 82 additions & 40 deletions

src/Services/AssertService.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace DragonCode\Benchmark\Services;
66

7-
use function assert;
7+
use AssertionError;
88

99
class AssertService
1010
{
@@ -111,22 +111,34 @@ public function toBeTotalMemory(?float $from = null, ?float $till = null): stati
111111
return $this;
112112
}
113113

114-
protected function assertGreaterThan(?float $actual, ?float $expected, string $name): void
114+
protected function assertGreaterThan(float $actual, ?float $expected, string $name): void
115115
{
116116
if ($expected === null) {
117117
return;
118118
}
119119

120-
assert($actual >= $expected, "The $name value must be greater than or equal to $expected.");
120+
if ($actual >= $expected) {
121+
return;
122+
}
123+
124+
throw new AssertionError(
125+
"The $name value must be greater than or equal to $expected."
126+
);
121127
}
122128

123-
protected function assertLessThan(?float $actual, ?float $expected, string $name): void
129+
protected function assertLessThan(float $actual, ?float $expected, string $name): void
124130
{
125131
if ($expected === null) {
126132
return;
127133
}
128134

129-
assert($actual <= $expected, "The $name value must be less than or equal to $expected.");
135+
if ($actual <= $expected) {
136+
return;
137+
}
138+
139+
throw new AssertionError(
140+
"The $name value must be less than or equal to $expected."
141+
);
130142
}
131143

132144
protected function resolveFrom(?float $from, ?float $till): ?float
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
+-------+--------------------+-------------------+
2+
| # | 0 | 1 |
3+
+-------+--------------------+-------------------+
4+
| min | 16 ms - 202 bytes | 2 ms - 102 bytes |
5+
| max | 113 ms - 209 bytes | 10 ms - 109 bytes |
6+
| avg | 53 ms - 205 bytes | 6 ms - 105 bytes |
7+
| total | 424 ms - 1.61 KB | 48 ms - 844 bytes |
8+
+-------+--------------------+-------------------+
9+
| order | 2 | 1 |
10+
+-------+--------------------+-------------------+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
+-------+-----------------------+----------------------+
2+
| # | 0 | 1 |
3+
+-------+-----------------------+----------------------+
4+
| min | 15.68 ms - 202 bytes | 2.35 ms - 102 bytes |
5+
| max | 112.79 ms - 209 bytes | 9.76 ms - 109 bytes |
6+
| avg | 53.03 ms - 205 bytes | 5.94 ms - 105 bytes |
7+
| total | 424.2 ms - 1.61 KB | 47.54 ms - 844 bytes |
8+
+-------+-----------------------+----------------------+
9+
| order | 2 | 1 |
10+
+-------+-----------------------+----------------------+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
+-------+--------------------------+------------------------+
2+
| # | 0 | 1 |
3+
+-------+--------------------------+------------------------+
4+
| min | 15.6789 ms - 202 bytes | 2.34568 ms - 102 bytes |
5+
| max | 112.78901 ms - 209 bytes | 9.75679 ms - 109 bytes |
6+
| avg | 53.02525 ms - 205 bytes | 5.9429 ms - 105 bytes |
7+
| total | 424.20199 ms - 1.61 KB | 47.5432 ms - 844 bytes |
8+
+-------+--------------------------+------------------------+
9+
| order | 2 | 1 |
10+
+-------+--------------------------+------------------------+

tests/Unit/Assertions/ToBeAvgMemoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
expect(true)->toBeTrue();
1919
});
2020

21-
test('failure less than', function () {
21+
test('failure greater than', function () {
2222
benchmark()
2323
->assert()
2424
->toBeAvgMemory(from: 10000);
2525
})->throws(AssertionError::class, 'The average memory value must be greater than or equal to 10000.');
2626

27-
test('failure greater than', function () {
27+
test('failure less than', function () {
2828
benchmark()
2929
->assert()
3030
->toBeAvgMemory(till: 1);

tests/Unit/Assertions/ToBeAvgTimeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
expect(true)->toBeTrue();
1919
});
2020

21-
test('failure less than', function () {
21+
test('failure greater than', function () {
2222
benchmark()
2323
->assert()
2424
->toBeAvgTime(from: 1000);
2525
})->throws(AssertionError::class, 'The average time value must be greater than or equal to 1000.');
2626

27-
test('failure greater than', function () {
27+
test('failure less than', function () {
2828
benchmark()
2929
->assert()
3030
->toBeAvgTime(till: 1);

tests/Unit/Assertions/ToBeMaxMemoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
expect(true)->toBeTrue();
1919
});
2020

21-
test('failure less than', function () {
21+
test('failure greater than', function () {
2222
benchmark()
2323
->assert()
2424
->toBeMaxMemory(from: 10000);
2525
})->throws(AssertionError::class, 'The maximum memory value must be greater than or equal to 10000.');
2626

27-
test('failure greater than', function () {
27+
test('failure less than', function () {
2828
benchmark()
2929
->assert()
3030
->toBeMaxMemory(till: 1);

tests/Unit/Assertions/ToBeMaxTimeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
expect(true)->toBeTrue();
1919
});
2020

21-
test('failure less than', function () {
21+
test('failure greater than', function () {
2222
benchmark()
2323
->assert()
2424
->toBeMaxTime(from: 1000);
2525
})->throws(AssertionError::class, 'The maximum time value must be greater than or equal to 1000.');
2626

27-
test('failure greater than', function () {
27+
test('failure less than', function () {
2828
benchmark()
2929
->assert()
3030
->toBeMaxTime(till: 1);

tests/Unit/Assertions/ToBeMinMemoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
expect(true)->toBeTrue();
1919
});
2020

21-
test('failure less than', function () {
21+
test('failure greater than', function () {
2222
benchmark()
2323
->assert()
2424
->toBeMinMemory(from: 10000);
2525
})->throws(AssertionError::class, 'The minimum memory value must be greater than or equal to 10000.');
2626

27-
test('failure greater than', function () {
27+
test('failure less than', function () {
2828
benchmark()
2929
->assert()
3030
->toBeMinMemory(till: 1);

tests/Unit/Assertions/ToBeMinTimeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
expect(true)->toBeTrue();
1919
});
2020

21-
test('failure less than', function () {
21+
test('failure greater than', function () {
2222
benchmark()
2323
->assert()
2424
->toBeMinTime(from: 1000);
2525
})->throws(AssertionError::class, 'The minimum time value must be greater than or equal to 1000.');
2626

27-
test('failure greater than', function () {
27+
test('failure less than', function () {
2828
benchmark()
2929
->assert()
3030
->toBeMinTime(till: 1);

0 commit comments

Comments
 (0)