Skip to content

How do you create an arbitray for a Map() object? #4992

Answered by gruhn
dpnova asked this question in Q&A
Discussion options

You must be logged in to vote

If your keys are strings, you can use fc.dictionary. For example

const arbitraryMap = fc.dictionary(fc.string(), fc.nat())
    .map(dict => new Map(Object.entries(dict)))

console.log( fc.sample(arbitraryMap, 5) )
Map(1) { 'CxbD!_' => 1135090401 },
Map(3) { 'q`' => 2113644272, ' x&~' => 27, '~}!t|z~y' => 25 },
Map(1) { '_#3' => 1738777444 },
Map(4) {
  '|call}&b #' => 9,
  '\\^!+L(' => 28,
  '' => 1752156948,
  'c' => 163999411
},
Map(7) {
  'I>U){' => 1984610647,
  'KEeeK' => 1524839195,
  'sAZ' => 937344058,
  '' => 529998270,
  'Gd2#<=ZHr}' => 1135358149,
  'a;kS4rzo' => 1594872950,
  ':(' => 641853712
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dpnova
Comment options

@dpnova
Comment options

@dpnova
Comment options

Answer selected by dpnova
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants