1 1.3 rillig # $NetBSD: varmod-order-shuffle.mk,v 1.3 2020/08/16 20:43:01 rillig Exp $ 2 1.1 rillig # 3 1.2 rillig # Tests for the :Ox variable modifier, which returns the words of the 4 1.2 rillig # variable, shuffled. 5 1.3 rillig # 6 1.3 rillig # As of 2020-08-16, make uses random(3) seeded by the current time in seconds. 7 1.3 rillig # This makes the random numbers completely predictable since there is no other 8 1.3 rillig # part of make that uses random numbers. 9 1.3 rillig 10 1.3 rillig NUMBERS= one two three four five six seven eight nine ten 11 1.3 rillig 12 1.3 rillig # Note that 1 in every 10! trials two independently generated 13 1.3 rillig # randomized orderings will be the same. The test framework doesn't 14 1.3 rillig # support checking probabilistic output, so we accept that each of the 15 1.3 rillig # 3 :Ox tests will incorrectly fail with probability 2.756E-7, which 16 1.3 rillig # lets the whole test fail once in 1.209.600 runs, on average. 17 1.3 rillig 18 1.3 rillig # Create two shuffles using the := assignment operator. 19 1.3 rillig shuffled1:= ${NUMBERS:Ox} 20 1.3 rillig shuffled2:= ${NUMBERS:Ox} 21 1.3 rillig .if ${shuffled1} == ${shuffled2} 22 1.3 rillig .error ${shuffled1} == ${shuffled2} 23 1.3 rillig .endif 24 1.3 rillig 25 1.3 rillig # Sorting the list before shuffling it has no effect. 26 1.3 rillig shuffled1:= ${NUMBERS:O:Ox} 27 1.3 rillig shuffled2:= ${NUMBERS:O:Ox} 28 1.3 rillig .if ${shuffled1} == ${shuffled2} 29 1.3 rillig .error ${shuffled1} == ${shuffled2} 30 1.3 rillig .endif 31 1.1 rillig 32 1.3 rillig # Sorting after shuffling must produce the original numbers. 33 1.3 rillig sorted:= ${NUMBERS:Ox:O} 34 1.3 rillig .if ${sorted} != ${NUMBERS:O} 35 1.3 rillig .error ${sorted} != ${NUMBERS:O} 36 1.3 rillig .endif 37 1.1 rillig 38 1.1 rillig all: 39 1.1 rillig @:; 40