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