3 # an unfinished idea for how to manage identifiers that are randomly
4 # generated but are also uniquely identified for later use.
6 # Author: Chris Koeritz
10 # given a name for a randomly assigned number, this will generate a
11 # new random value and add it to the RANDOM_IDS list. it is an error
12 # to try to change an existing random id, because the id may already have
13 # been used in file generation and so forth.
14 function setup_random_id()
17 if [ ! -z "${RANDOM_IDS[$name]}" ]; then
18 echo "FAILURE: trying to reassign already generated random id for '$name'"
21 new_id=$RANDOM-$RANDOM-$RANDOM
22 RANDOM_IDS[$name]=$new_id
26 # returns the random value assigned under the name. it is an error
27 # to request one that does not exist yet; this implies the test has
28 # not properly configured the random ids it will use.
29 function get_random_id()
32 if [ -z "${RANDOM_IDS[$name]}" ]; then
33 echo "FAILURE-to-find-$name"
36 echo "${RANDOM_IDS[$name]}"
42 ## setup_random_id "george"
43 ## if [ $? -ne 0 ]; then echo TEST failed to set george; fi
44 ## setup_random_id "lucy"
45 ## if [ $? -ne 0 ]; then echo TEST failed to set lucy; fi
46 ## echo "lucy's id is: $(get_random_id lucy)"
47 ## lucy_id=$(get_random_id lucy)=
48 ## if [ $? -ne 0 ]; then echo TEST failed to get lucy; fi
49 ## echo "george's id is: $(get_random_id george)"
50 ## george_id=$(get_random_id george)
51 ## if [ $? -ne 0 ]; then echo TEST failed to get george; fi
53 ## setup_random_id "george" &>/dev/null
54 ## if [ $? -eq 0 ]; then echo TEST failed to trap george being reset; fi
55 ## setup_random_id "lucy" &>/dev/null
56 ## if [ $? -eq 0 ]; then echo TEST failed to trap lucy being reset; fi
58 ## if [ $? -eq 0 ]; then echo TEST failed to trap non-existent id request; fi