Skip to content

Commit 0304b4a

Browse files
committed
Made regression tests deterministic
Some output was uninitialized (to show an error) or timing-dependent (for the benefit of live demos) but that caused non-reproducible execution output, so I tweaked the tests to make the execution output deterministic
1 parent c83f288 commit 0304b4a

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

regression-tests/mixed-bounds-check.cpp2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <vector>
33

44
main: () -> int = {
5-
v : std::vector = (1, 2, 3, 4, 5);
5+
v : std::vector = (1, 2, 3, 4, 5, -999);
6+
v.pop_back();
67
std::cout << v[5] << "\n";
78
}

regression-tests/mixed-initialization-safety-3.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ fill: (
1717
out x: std::string,
1818
value: std::string,
1919
count: int
20-
)
20+
)
2121
[[pre: value.size() >= count, "fill: value must contain at least count elements"]]
2222
= {
2323
x = value.substr(0, count);
2424
}
2525

2626
print_decorated: (x:_) = std::cout << ">> [" << x << "]\n";
2727

28-
flip_a_coin: () -> bool = std::time(nullptr) % 2 == 0;
28+
flip_a_coin: () -> bool = std::rand() % 2 == 0;

regression-tests/test-results/mixed-bounds-check.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#line 3 "mixed-bounds-check.cpp2"
1313

1414
[[nodiscard]] auto main() -> int{
15-
std::vector v { 1, 2, 3, 4, 5 };
15+
std::vector v { 1, 2, 3, 4, 5, -999 };
16+
CPP2_UFCS_0(pop_back, v);
1617
std::cout << v[5] << "\n";
1718
}

regression-tests/test-results/mixed-initialization-safety-3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ auto fill(
4747

4848
auto print_decorated(auto const& x) -> void { std::cout << ">> [" << x << "]\n"; }
4949

50-
[[nodiscard]] auto flip_a_coin() -> bool { return std::time(nullptr) % 2 == 0; }
50+
[[nodiscard]] auto flip_a_coin() -> bool { return std::rand() % 2 == 0; }
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4456566
1+
-999

0 commit comments

Comments
 (0)