From f3a171bacf09547d8fb89e1372db5a42b4d6e640 Mon Sep 17 00:00:00 2001 From: David Wu Date: Mon, 27 Nov 2023 23:36:28 -0500 Subject: [PATCH] Make date rand test independent of evaluation order --- cpp/core/datetime.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cpp/core/datetime.cpp b/cpp/core/datetime.cpp index f7fff00b6..9f46618bf 100644 --- a/cpp/core/datetime.cpp +++ b/cpp/core/datetime.cpp @@ -364,8 +364,11 @@ void DateTime::runTests() { SimpleDate date1; SimpleDate date2; int d1 = rand.nextInt(-10000000,10000000); - int d2 = rand.nextInt(-20,20) * (rand.nextBool(0.1) ? 100 : 1); - int d3 = rand.nextInt(-20,20); d3 = d3 * d3 * (rand.nextBool(0.5) ? -1 : 1) * (rand.nextBool(0.1) ? 37 : 1); + int d2 = rand.nextInt(-20,20); + d2 *= (rand.nextBool(0.1) ? 100 : 1); + int d3 = rand.nextInt(-20,20); + d3 = d3 * d3 * (rand.nextBool(0.5) ? -1 : 1); + d3 *= (rand.nextBool(0.1) ? 37 : 1); date1 += d1; testAssert(SimpleDate() + d1 == date1);