2023-04-24 23:44:30 +00:00
|
|
|
# $NetBSD: varmod-order-shuffle.mk,v 1.8 2023/02/26 06:08:06 rillig Exp $
|
2020-09-05 16:11:04 +00:00
|
|
|
#
|
|
|
|
# Tests for the :Ox variable modifier, which returns the words of the
|
|
|
|
# variable, shuffled.
|
|
|
|
#
|
2020-11-20 03:54:37 +00:00
|
|
|
# The variable modifier :Ox is available since 2005-06-01.
|
|
|
|
#
|
2020-09-05 16:11:04 +00:00
|
|
|
# As of 2020-08-16, make uses random(3) seeded by the current time in seconds.
|
2023-04-24 23:44:30 +00:00
|
|
|
# This makes the random numbers completely predictable since the only other
|
|
|
|
# part of make that uses random numbers is the 'randomize-targets' mode, which
|
|
|
|
# is off by default.
|
2020-11-07 19:39:21 +00:00
|
|
|
#
|
|
|
|
# Tags: probabilistic
|
2020-09-05 16:11:04 +00:00
|
|
|
|
2021-12-18 07:27:22 +00:00
|
|
|
WORDS= one two three four five six seven eight nine ten
|
2020-09-05 16:11:04 +00:00
|
|
|
|
|
|
|
# Note that 1 in every 10! trials two independently generated
|
|
|
|
# randomized orderings will be the same. The test framework doesn't
|
|
|
|
# support checking probabilistic output, so we accept that each of the
|
|
|
|
# 3 :Ox tests will incorrectly fail with probability 2.756E-7, which
|
|
|
|
# lets the whole test fail once in 1.209.600 runs, on average.
|
|
|
|
|
|
|
|
# Create two shuffles using the := assignment operator.
|
2021-12-18 07:27:22 +00:00
|
|
|
shuffled1:= ${WORDS:Ox}
|
|
|
|
shuffled2:= ${WORDS:Ox}
|
2020-09-05 16:11:04 +00:00
|
|
|
.if ${shuffled1} == ${shuffled2}
|
2020-11-07 19:39:21 +00:00
|
|
|
. error ${shuffled1} == ${shuffled2}
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# Sorting the list before shuffling it has no effect.
|
2021-12-18 07:27:22 +00:00
|
|
|
shuffled1:= ${WORDS:O:Ox}
|
|
|
|
shuffled2:= ${WORDS:O:Ox}
|
2020-09-05 16:11:04 +00:00
|
|
|
.if ${shuffled1} == ${shuffled2}
|
2020-11-07 19:39:21 +00:00
|
|
|
. error ${shuffled1} == ${shuffled2}
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
# Sorting after shuffling must produce the original numbers.
|
2021-12-18 07:27:22 +00:00
|
|
|
sorted:= ${WORDS:Ox:O}
|
|
|
|
.if ${sorted} != ${WORDS:O}
|
|
|
|
. error ${sorted} != ${WORDS:O}
|
2020-09-05 16:11:04 +00:00
|
|
|
.endif
|
|
|
|
|
|
|
|
all:
|